Electronics › Electronics › Read a character from serial port and send back › Hey Pavithra, I tried
Hey Pavithra,
I tried simulating your code and there are some points you should note.
1. Use ‘ ACALL r ‘ to make a recieve function and end it with ‘ RET ‘. In your code ‘SJMP r’ will loop forever in the ‘r’ subroutine and never execute the sending subroutine.
2. The data you are recieving is on ‘P1’ , but you are transmitting data from ‘P2’ .
3. If you are simulating, check that the clock is set to 11.0592MHz only.
This is your code which I made some changes to, hope it helps.
ORG 000H
MOV TMOD,#20H
MOV TH1,#0FDH
MOV SCON,#50H
SETB TR1
ACALL r
ACALL t
r:JNB RI,R
MOV A,SBUF
MOV P1,A
CLR RI
RET
t: MOV P1, A
MOV SBUF, A
w: JNB TI,w
CLR TI
RET
END
Regards.