- This topic has 2 replies, 3 voices, and was last updated 8 years, 5 months ago by .
Viewing 3 posts - 1 through 3 (of 3 total)
Viewing 3 posts - 1 through 3 (of 3 total)
- You must be logged in to reply to this topic.
|
Microcontroller › 8051 › the function of the code “SBUF = value”.in RS232 interfacing code by som9543
In RS232 interfacing code with 8051 the receive code is given as
void recieve() //Function to receive serial data
{
unsigned char value;
while(RI==0);
SBUF=value;
P1=SBUF;
RI=0;
}
please let me know the function of the code “SBUF = value”. why it is important to assign some unknown value to SBUF?
Hi there
I guess the above code is not correct, shouldn't it be:
void recieve() //Function to receive serial data
{
unsigned char value;
while(RI==0); //waits untill any reception occurs
value=SBUF; //stores 1 byte data in value
P1=vlaue; //that value is also copied to PORT1
RI=0; //makes RX part get ready for another reception
}
At the end of this function you could also add SBUF=0;(just after RI=0;) to ensure no garbage value stays inside SBUF register, which might have affected the upcoming reception.
receive function is just to receive value from serial port
so we can not assign any value to SBUF
actually it should be value = SBUF