Generation of Square Waveform of 50 Hz frequency

To generate a square waveform of 50 Hz frequency using Timer 0 Mode 1 in assembly language.

Assembly Language:

MOV TMOD,#01H ; Move 01 H to TMOD, To select Timer 0 Mode 1
AGAIN: MOV TL0,#0FFH ; Move FF H to Timer 0 TL0
MOV TH0,#0DBH ; Move DB H to Timer 0 TH0
SETB TR0 ; Set TR0 = 1 to start Timer 0
HERE: JNB TF0, HERE ; Jump to label HERE if TF0 ≠ 1; when Timer 0 ; overflows from FF H to 00 H, TF0 = 1
CLR TR0 ; Clear TR0 = 0 to stop Timer 0
CPL P1.5 ; Complement P1.5 bit
CLR TF0 ; Clear TF0 = 0 to reset TF0 flag
SJMP AGAIN ; Short jump to label AGAIN
END ; End of asm file.

Check waveform using Logic Analyzer window in Keil µVision C51.

Advertisements