Timers programming in Assembly level language for 8051 Microcontroller

Write ALP to generate square wave of 50% duty cycle on P2.3. Use Timer0 to generate time delay. Mode 1

Assembly Code:

ASM Code:
  ORG 0000H MOV TMOD,#01H HERE: MOV TL0,#0F2H MOV TH0,#0FFH CPL P2.3 ACALL DELAY SJMP HERE DELAY: SETB TR0 AGAIN: JNB TF0,AGAIN CLR TR0 CLR TF0 RET END  

Write ALP to generate square wave of 50% duty cycle on P2.3. Use Timer0 to generate time delay. Mode 2

Assembly Code:

ASM Code:
  ORG 0000H MOV TMOD,#02H // Timer 0, Mode 2 MOV TL0,#0F0H MOV TH0,#0FH HERE: CPL P2.3 ACALL DELAY SJMP HERE DELAY: SETB TR0 AGAIN: JNB TF0,AGAIN CLR TF0 RET END  

Write ALP to generate square wave of 2kHz frequency on pin P1.1 (Crystal frequency= 11.0592MHz)

Assembly Code:

ASM Code:
  ORG 0000H MOV TMOD,#01H HERE: MOV TL0,#1AH MOV TH0,#0FFH CPL P1.1 ACALL DELAY SJMP HERE DELAY: SETB TR0 AGAIN: JNB TF0,AGAIN CLR TR0 CLR TF0 RET END  

Write ALP for Counter 1 in mode 2 to count pulses fed into pin T1.

Assembly Code:

ASM Code:
  ORG 0000H MOV TMOD,#01100000B //Counter 1, Mode 2 //Count External Pulses MOV TH1, #00H //Clear TH1 SETB P3.5 //Make T1 pin Input AGAIN: SETB TR1 //Start the counter BACK: MOV A,TL1 //Get copy of Count TL1 MOV R7, A //Store value of count in R7 JNB TF1, BACK //Keep Counting until counter overflow CLR TR1 //Stop Counter 1 CLR TF1 //Make TF=0 SJMP AGAIN //Keep Doing It END