Generation of Square Waveform of 2 kHz frequency

To generate a square waveform of 2 kHz frequency using Timer 1 Mode 2 in assembly language.

Assembly Language:

MOV TMOD,#20H ; Move 20 H to TMOD, To select Timer 1 Mode 2
AGAIN: MOV TH1,#01BH ; Move 1B H to Timer 1 TH1
SETB TR1 ; Set TR1 = 1 to start Timer 1
HERE: JNB TF1, HERE ; Jump to label HERE if TF1 ≠ 1; when Timer 1 ; TL1 overflows from FF H to 00 H, TF1 = 1
CLR TR1 ; Clear TR1 = 0 to stop Timer 1
CPL P1.5 ; Complement P1.5 bit
CLR TF1 ; Clear TF1 = 0 to reset TF1 flag
SJMP AGAIN ; Short jump to label AGAIN
END ; End of asm file.

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

Advertisements