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

8051 sbuf program

dear sir

I am writing  c code to write to rs232 port using aduc831 kit
SBUF=1+48;
SBUF=1+48;
SBUF=1+48;
SBUF=1+48;
initially sbuf didnt take SBUF=1 doing above it did but now want to send nibble continuously from io port P3 such that it should display 0 to 0f on hyperterm
now frm program 0f 1111 should be displayed on hyperterm.kindly help

regards
khn

Parents
  • If you have a byte that you want to emit as nibbles, you can get the values to print with:
    Low nibble:

    SBUF = (num & 0x0f) + '0';
    

    High nibble:

    SBUF = ((num >> 4) & 0x0f) + '0';
    

    If "num" is a 16-bit number, you just have to shift 8 and 12 steps to get the other two nibbles.

    By the way - do not format your text as code. It is _only_ source code that should use the "pre" tags - notice how your original post becomes very wide? Text within the pre tag doesn't get any automatic line breaks, so you can quickly create truly borked message threads. Too clever formatting is a good way to get people to ignore your posts.

Reply
  • If you have a byte that you want to emit as nibbles, you can get the values to print with:
    Low nibble:

    SBUF = (num & 0x0f) + '0';
    

    High nibble:

    SBUF = ((num >> 4) & 0x0f) + '0';
    

    If "num" is a 16-bit number, you just have to shift 8 and 12 steps to get the other two nibbles.

    By the way - do not format your text as code. It is _only_ source code that should use the "pre" tags - notice how your original post becomes very wide? Text within the pre tag doesn't get any automatic line breaks, so you can quickly create truly borked message threads. Too clever formatting is a good way to get people to ignore your posts.

Children