Write code to generate a square wave with a 75 duty cycle an
Write code to generate a square wave with a 75% duty cycle and a frequency of 5 kHz on P0.0.
assume we have a standard 8051 with a frequency of 11.0592 MHz , All code should be written in Assembly.
Solution
Firstly we will write whatever is given to us:
i) Duty Cycle: 75%
ii) Frequency: 5 kHz
iii) Standard 8051 with Freq. 11.0592 MHz
We need to generate a SQUARE WAVE
So,
- 5 kHz means time period is 0.05ms
- Duty cycle 75% means 75% of 0.05 ms
STEPS:
1) Make a delay of 0.005ms and then call it 7 and half (7.5) times and make sure that during that time keep the port high.
2) Then again make a delay of 0.005ms for the remaining 2 and a half (2.5) times and keep the value zero for the port logic that is chosen.
3) Repeat Steps 1 & 2 again and again.
org 00h
begin : setb p1.05
acall delay
acall delay
acall delay
clr p1.05
acall delay
acall delay
acall delay
acall delay
acall delay
acall delay
acall delay
sjmp begin
org 75h
delay:
mov tmod,#10h ;timer 1,mode1
back: mov tl1,#0f7h
mov th1,#0ffh
setb tr1
again: jnb tf1,again
clr tr1
clr tf1
ret
end
