- This topic has 4 replies, 3 voices, and was last updated 11 years, 6 months ago by .
Viewing 5 posts - 1 through 5 (of 5 total)
Viewing 5 posts - 1 through 5 (of 5 total)
- You must be logged in to reply to this topic.
|
Electronics › Electronics › Read a character from serial port and send back
Hi Engineers Garage and all
I have a query regarding serial communication. I need to read a character from serial port and send them back. Ive written the code but not getting expected result. Please u experts help me.. I would be very happy :]
This is my assembly code
ORG 000H
MOV TMOD,#20H
MOV TH1,#0FDH
MOV SCON,#50H
SETB TR1
r:JNB RI,R
MOV A,SBUF
MOV P1,A
CLR RI
SJMP R
HERE:JNB TI,HERE
CLR TI
AGAIN:MOV P2,SBUF
SJMP AGAIN
END
PLease guys help me and suggest me wat m i doin wrong . waiting for ur reply
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.
thank you so much for ur suggestions.. Im gonna try this out and hope so it would work ..
with regards.
Sorry to say this, this code dint work.
try this code
SCON=0X50;
TMOD=0X20;
TL1=TH1=0XFD;
TR1=1;
inside main
while(RI==0);
{
RI=0;
msg=SBUF;
SBUF=msg;
while(TI==0);
TI=0;
}