Connect a push button switch to P3.4 and an 8 Ohm speaker to P1.0 as shown below
ID: 2085790 • Letter: C
Question
Connect a push button switch to P3.4 and an 8 Ohm speaker to P1.0 as shown below. The 2N5307 is a Darlington transistor pair which has a current gain of beta > 2000 and its collector current can be up to 1.2 amps. If you output a square wave on P1.0 at frequency f_o you will hear a tone on the speaker with a base frequency f_o, plus odd harmonic overtones. For this assignment write the assembly-code to output an A-note (about 440Hz) in response to the push button on P3.4. Your assembly code must contain a subroutine which does the software time delay and a macro which output a bit to P3.4.Explanation / Answer
lets consider frequency of external oscillator be 12MHz
so the timers will run at 1MHz ,time period = 1/1MHz= 1microsecond (timer clock frequency = XTAL/12)
A-note frequeny =440Hz , timeperiod = 1/440=2272.7microseconds
duty ratio will be 50% so timer count=(2272.7micros/1micros)*1/2=1136.35 approx=11136 =470H
value to be loaded in Timer register=FFFFH-470H+1 =FB8FH
Therefore TH=FBH ,TL=8FH
Since P3.4 is configured to be Active low (Gives 0 as Input to P3.4 When button is Pushed )
code:
MOV P1,#00000000B //Initializing P1.0 as Output
MOV P3,#00010000B //Initializing P3.4 as Input
MOV TMOD,#00000001B // Sets Timer 0 to MODE1 (16 bit timer)
MOV TH0,#0FBH // Loads TH0 register with FBH
MOV TL0,#08FH // LOads TL0 register with 8FH
MAIN: MOV C,P3.4 //Load C with P3.4 value (1 if off and 0 if on)
JB C,MAIN // If C=1, goes to main,else goes forward
ACALL DELAY //Calling Delay Subroutine and waits for half time period
SETB P1.0 //Makes P1.0 high
ACALL DELAY // waits for half time period
CLR P1.0 //Makes P1.0 low
SJMP MAIN
DELAY:
SETB TR0 // Starts the Timer 0
HERE: JNB TF0,HERE // Loops here until TF0 is set (ie;until roll over)
CLR TR0 // Stops Timer 0
CLR TF0 // Clears TF0 flag
RET
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.