Generation of different frequency Square Waveform based on Pin State of 2 Input Pins

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

1. When P2.1 = 1 and P2.0 = 1, generate a square waveform of 50 Hz frequency.
2. When P2.1 = 1 and P2.0 = 0, generate a square waveform of 100 Hz frequency.
3. When P2.1 = 0 and P2.0 = 1, generate a square waveform of 1 kHz frequency.
4. When P2.0 = 0 and P2.1 = 0, generate a square waveform of 2 kHz frequency.

Assembly Language:

MOV P2,#0FFH;
START:MOV A,P2;
ANL A,#03H;
CJNE A, #03H, NEXT1;
LCALL DELAY1;
NEXT1: CJNE A, #02H, NEXT2;
LCALL DELAY2;
NEXT2: CJNE A, #01H, NEXT3;
LCALL DELAY3;
NEXT3: CJNE A, #00H, REPEAT;
LCALL DELAY4;
REPEAT: SJMP START;

/* generation of square waveform of 50 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,#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
HERE1: JNB TF0, HERE1 ; 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.0 ; Complement P1.5 bit
CLR TF0 ; Clear TF0 = 0 to reset TF0 flag

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

DELAY2: MOV TMOD,#01H ; Move 01 H to TMOD, To select Timer 0 Mode 1
AGAIN2: MOV TL0,#0FFH ; Move FF H to Timer 0 TL0
MOV TH0,#0EDH ; Move ED H to Timer 0 TH0
SETB TR0 ; Set TR0 = 1 to start Timer 0
HERE2: JNB TF0, HERE2 ; 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.0 ; Complement P1.0 bit
CLR TF0 ; Clear TF0 = 0 to reset TF0 flag

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

DELAY3: MOV TMOD,#01H ; Move 01 H to TMOD, To select Timer 0 Mode 1
AGAIN3: MOV TL0,#033H ; Move 33 H to Timer 0 TL0
MOV TH0,#0FEH ; Move FE H to Timer 0 TH0
SETB TR0 ; Set TR0 = 1 to start Timer 0
HERE3: JNB TF0, HERE3 ; Jump to label HERE3 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.0 ; Complement P1.0 bit
CLR TF0 ; Clear TF0 = 0 to reset TF0 flag

/* generation of square waveform of 2 kHz frequency using Timer 0 Mode 1*/

DELAY4: MOV TMOD,#01H ; Move 01 H to TMOD, To select Timer 0 Mode 1
AGAIN4: MOV TL0,#019H ; Move 19 H to Timer 0 TL0
MOV TH0,#0FFH ; Move FF H to Timer 0 TH0
SETB TR0 ; Set TR0 = 1 to start Timer 0
HERE4: JNB TF0, HERE1 ; Jump to label HERE4 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.0 ; Complement P1.0 bit
CLR TF0 ; Clear TF0 = 0 to reset TF0 flag