This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Why can't I read SBUF?

The code is like this:

#include <reg51.h>
void main()
{
unsigned char ch;
SBUF = 0xcc;
ch = SBUF ;
}

I found that the value in ch is always zero,however, when I substituated SBUF with other SFRs, the result in ch is 0xcc, which is correct. What is the problem here and how can I read the value in SBUF?

Thanks!

Parents
  • Alex;
    The reason you cannot read the SBUF in your code is that there are two entirely different SBUF registers. Both registers have the same SFR address but cannot be accessed in the same manner. The only way to get data into the Receive SBUF is through the Serial Port. The only way to read data out of the transmitt SBUF is out the Serial Port.
    I suggest that you read Eric and Andrews bible of 8051 operations as posted on this website. Just search Bible in the discussion forum and you will find the links to the Philips websites.
    Bradford

Reply
  • Alex;
    The reason you cannot read the SBUF in your code is that there are two entirely different SBUF registers. Both registers have the same SFR address but cannot be accessed in the same manner. The only way to get data into the Receive SBUF is through the Serial Port. The only way to read data out of the transmitt SBUF is out the Serial Port.
    I suggest that you read Eric and Andrews bible of 8051 operations as posted on this website. Just search Bible in the discussion forum and you will find the links to the Philips websites.
    Bradford

Children