ehsanelahimirza
Full Member level 6
serial communication with 89c51
hi all
i m doing serial communication with pc and 89c51 but it is not working
i think my code is not correct.
plz correct me or guuide me
thanks
hi all
i m doing serial communication with pc and 89c51 but it is not working
i think my code is not correct.
plz correct me or guuide me
thanks
Code:
org 0h
main:
Serial_Init:
;Set timer 1 mode to 8-bit Auto-Reload
mov TMOD,#20H
;Enable reception
;Set Serial port mode to 8-bit UART
mov SCON,#50H
;Set baudrate to 9600 at 11.0592MHz
mov TH1,#0FDH
mov TH2,#0FDH
mov TL1,#0FDH
mov TL2,#0FDH
;Start Timer
setb TR1
Serial_Send:
;wait for last data to be
;sent completely
jnb TI,Serial_Send
;clear the transmit interrupt flag
clr TI
;Then move the data to send in SBUF
mov SBUF,A
Serial_Read:
;Wait for Receive interrupt flag
jnb RI,Serial_Read
;If falg is set then clear it
clr RI
;Then read data from SBUF
mov A,SBUF
mov p1,a
acall delay
jmp main
DELAY:
MOV R6 ,#0FFH
wait1:
MOV R7 ,#0FFH
wait3:
DJNZ R7,wait3
DJNZ R6,wait1
RET
end