Question 11.8: Write a program in which the 8051 reads data from P1 and wri...
Write a program in which the 8051 reads data from P1 and writes it to P2 continuously while giving a copy of it to the serial COM port to be transferred serially. Assume that XTAL=11.0592. Set the baud rate at 9600.
Learn more on how we answer questions.
ORG 0000H MAIN: MOV P1,#0FFH ;make P1 an input port MOV TMOD,#20H ;timer 1, auto reload BACK: MOV A,P1 ;read data from port 1 MOV SBUF,A ;give a copy to SBUF . . . ORG 100H SERIAL: JB TI,TRANS ;jump if TI is high MOV A,SBUF ;otherwise due to receive TRANS: CLR TI ;clear TI since CPU doesn’t RETI ;return from ISR |
The moment a byte is written into SBUF it is framed and transferred
serially. As a result, when the last bit (stop bit) is transferred the TI is
raised, and that causes the serial interrupt to be invoked since the
corresponding bit in the IE register is high. In the serial ISR, we check
for both TI and RI since both could have invoked interrupt.