; This program receives data on the 8051 ; serial port. Once the program's ; initialisation is complete, it waits for ; data arriving on the RXD line (data ; that was transmitted by the external ; UART). ; Any text typed in the external UART is ; sent once the Tx Send button is pressed. ; As each character is transmitted fully, ; it disappears from the Tx window. ; The data is appended with the return ; character (0D HEX). ; The default external UART baud rate is 19,200 - to ; generate this baud rate, timer 1 must overflow ; every 3 us with SMOD equal to 1 (this is as close as ; we can get to 19,200 baud at a system clock frequency ; of 12 Mz). ; See the notes on the serial port for more information. ; The program is written using busy-waiting. ; It continuously tests the RI flag. Once ; this flag is set by the 8051 hardware ; (a byte has been received) the program ; clears it and then moves the byte from ; SBUF to A. ; The received byte's value is checked to ; see if it is the terminating character (0D HEX). ; If it is the program jumps to the finish, ; otherwise it moves the byte to data memory ; and returns to waiting for the next byte. CLR SM0 ; | SETB SM1 ; | put serial port in 8-bit UART mode SETB REN ; enable serial port receiver MOV A, PCON ; | SETB ACC.7 ; | MOV PCON, A ; | set SMOD in PCON to double baud rate MOV TMOD, #20H ; put timer 1 in 8-bit auto-reload interval timing mode MOV TH1, #0FDH ; put -3 in timer 1 high byte (timer will overflow every 3 us) MOV TL1, #0FDH ; put same value in low byte so when timer is first started it will overflow after 1 us SETB TR1 ; start timer 1 MOV R1, #30H ; put data start address in R1 again: JNB RI, $ ; wait for byte to be received CLR RI ; clear the RI flag MOV A, SBUF ; move received byte to A CJNE A, #0DH, skip ; compare it with 0DH - it it's not, skip next instruction JMP finish ; if it is the terminating character, jump to the end of the program skip: MOV @R1, A ; move from A to location pointed to by R1 INC R1 ; increment R1 to point at next location where data will be stored JMP again ; jump back to waiting for next byte finish: jmp $ ; do nothing