Generation of Square Waveform of  750 Hz and 500 Hz based on Input Pin State

Write a program to continuously monitor P2.0 in assembly language.

  1. When P2.0 = 1, generate a square waveform of 750 Hz frequency.
  2. When P2.0 = 0, generate a square waveform of 500 Hz frequency.

Assembly Language:

SETB P2.0;
START: MOV C,P2.0;
JC DELAY1;

/* generation of square waveform of 500 Hz frequency using Timer 0 Mode 1*/

DELAY: MOV TMOD,#01H ; Move 01 H to TMOD, To select Timer 0 Mode 1
AGAIN: MOV TL0,#067H ; Move FF H to Timer 0 TL0
MOV TH0,#0FCH ; Move DB H to Timer 0 TH0
SETB TR0 ; Set TR0 = 1 to start Timer 0
HERE: JNB TF0, HERE ; Jump to label HERE1 if TF0 = 1; when Timer 0 ; overflows from FFFF H to 0000 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 START ; Jump to START label

/* generation of square waveform of 750 Hz frequency using Timer 0 Mode 1*/
DELAY1: MOV TMOD,#01H ; Move 01 H to TMOD, To select Timer 0 Mode 1
AGAIN1: MOV TL0,#09AH ; Move FF H to Timer 0 TL0
MOV TH0,#0FDH ; Move ED H to Timer 0 TH0
SETB TR0 ; Set TR0 = 1 to start Timer 0
HERE1: JNB TF0, HERE1 ; Jump to label HERE2 if TF0 = 1; when Timer 0 ; overflows from FFFF H to 0000 H, TF0 = 1
CLR TR0 ; Clear TR0 = 0 to stop Timer 0
CPL P1.5 ; Complement P1.0 bit
CLR TF0 ; Clear TF0 = 0 to reset TF0 flag
SJMP START ; Jump to START label

END ; End of asm file

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

Advertisements
%d bloggers like this: