Write a program in C in which every 2 seconds the LED connec
Write a program in C, in which every 2 seconds, the LED connected to P2.7 is turned on and off four times, while the 8051 is getting data from P1 and sending it to P0 continuously. Make sure the on and off states are 50 ms in duration.
Solution
ORG 0
LJMP MAIN
 ORG 23H
 LJMP SERIAL ;jump to serial int ISR
 ORG 30H
 MAIN: MOV P1,#0FFH ;make P1 an input port
 MOV TMOD,#20H ;timer 1, auto reload
 MOV TH1,#0FDH ;9600 baud rate
 MOV SCON,#50H ;8-bit,1 stop, ren enabled
 MOV IE,10010000B ;enable serial int.
 SETB TR1 ;start timer 1
 BACK: MOV A,P1 ;read data from port 1
 MOV P2,A ;send it to P2
 SJMP BACK ;stay in loop indefinitely
 LJMP MAIN
 ORG 000BH ;ISR for Timer 0
 CPL P2.7
 MOV TL0,#00
 MOV TH0,#0DCH
 RETI
 ORG 30H
 ;--------main program for initialization
 MAIN:MOV TM0D,#00000001B ;Timer 0, Mode 1
 MOV TL0,#00
 MOV TH0,#0DCH
 MOV IE,#82H ;enable Timer 0 interrupt
 SETB TR0
 HERE:SJMP HERE
 END

