org 00h
serTx DATA 1H
serRx DATA 2H
byte1 DATA 3h
byte2 DATA 4h
byte3 DATA 5h
byte4 DATA 6h
org 30h
;##### UART Initialization ######
; MOV TMOD,#20H ;timer 1,mode 2(auto reload)
; MOV TH1,#-6 ;4800 baud rate X 2 =9600
; MOV SCON,#50H 8-bit, 1 stop, REN enabled
; SETB TR1 ;start timer 1
mov PCON,#0x80 ;x2 serial baud rate
mov TH1,#0xFA ;reload value 250 for 9600bps w/11.059MHz xtal
mov TL1,#0xFA
mov TMOD,#0x20 ;timer 1,mode 2(auto reload)
mov TCON,#0x40 ;start timer 1
mov SCON,#0x50 ;8-bit, 1 stop, REN enabled
;##### Main Code #####
start: acall Rx
MOV byte1,serRx
acall Rx
MOV byte2,serRx
acall Rx
MOV byte3,serRx
acall Rx
MOV byte4,serRx
MOV serTx,byte1
acall Tx
MOV serTx,byte2
acall Tx
MOV serTx,byte3
acall Tx
MOV serTx,byte4
acall Tx
ajmp start
;##### UART Transmit And Ricive #####
Rx: JNB RI,Rx ;wait for the last bit
CLR RI ;clear RI flag
MOV A,SBUF
MOV serRx,A
RET
Tx: MOV A,serTx
MOV SBUF,A ;saving incoming byte in A
TxH: JNB TI,TxH ;wait for the last bit
CLR TI ;get ready to receive next byte
;Tx: jnb TI,Tx ;wait here if transmit in progress
; clr TI ;byte sent, clear tx flag
; mov SBUF,serRx ;transfer received byte to UART buffer
RET
end