In: Electrical Engineering
Write the code in assembly language to generate two square waves of frequency 1KHZ with 50% duty cycle and 10KHZ with 50% duty cycle using P1.0 and P1.1 using timer0 and timer1 simultaneously. Don't use instruction overhead. use timer interrupts to implement the functionality use Xtal=12MHZ
I am assuming you are talking about 8051 microcontrollers.
Given Crystal Frequency = 12MHz., that means 1 clock pulse is of 1μsec.
1st frequency required = 1KHz
1 pulse = 1/1KHz = 1 msec, 500 μsec ON time and 500 μsec OFF time
Count = 500μsec/1μsec = 500
Counter initial value = 65536 - 500 = 65036 = FE0C
for 10Khz,
1 pulse = 1/10KHz = 0.1msec
Counter initial value = 50 usec/1 usec = 50
Counter intial Value = 65486 = FFCE
We can use the timer in MODE 1(counter mode - 01)
Finding TMOD bit:
TMOD = 0001 0001 -> (11)H (we are using both timers, one for 1KHz and other for 10Khz)
Now we need to produce 2 interupts for TIM 1 AND TIM2, so we need to ask IE register:
1000 1010 - (8A)H
PROGRAM :
org 0000H
LJMP main
org 000BH
CPL P1.0
CLR TR0
CPL P1.1
CLR TR1
MOV TL0 #0CH
MOV TL0 #0FEH
SETB TR0
SETB TR1
RETI
org 0100H
MOV 1E #8A
MOV TMOD #11H
MOV TL0 #0CH
MOV TH0 #0FEH
MOV TL1 #
SETB TR0
SETB TR1
SJMP TR0
SJMP TR1