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

accessing bitwise data in a data buffer

hi all,
iam a new to embedded programming and keil software.
i am struck with a problem how to access a bit in a data buffer.

the algo i need to implement is

data_buf of 32 bits is stored in the micro controller. i need to send those bits bit by bit. ie. starting from bit 0 to bit 31.

can anybody pls suggest me how to write a program in keil.

thanks in advance
uday

Parents
  • i have declared a buffer holding a 32 bit value. i need to send that value on 3rd pin of port 0. my problem was how to access each bit of the buffer and send it. if i use a piece of code below..is it correct ?

    /**********
    unsigned int data_buf[40];
    unsigned int i;
    for (i=0;i<=39;i++)
    {
    P0^3 = data_buf[i];
    }
    *********/


    No. This code will not work and does not match the description you provided. Ignoring the fact that the code is commented-out, even still it will not work.

    i have declared a buffer holding a 32 bit value.

    No, you have declared an array of 80 bytes (40 ints). Since bytes have 8-bits, your buffer holds 640 bits (not 32).

    i need to send that value on 3rd pin of port 0.

    OK, then why do you send 40 bits when your first sentence says you have 32 bits.

    my problem was how to access each bit of the buffer and send it.

    This is what Mr. Neil suggested with his comment to "look at the shift and bitwise operators."

    Have you looked at any of the example programs provided or looked into the 8051 download files ( http://www.keil.com/download/c51.asp)? There are several examples there that do similar things to what you want.

    Jon

Reply
  • i have declared a buffer holding a 32 bit value. i need to send that value on 3rd pin of port 0. my problem was how to access each bit of the buffer and send it. if i use a piece of code below..is it correct ?

    /**********
    unsigned int data_buf[40];
    unsigned int i;
    for (i=0;i<=39;i++)
    {
    P0^3 = data_buf[i];
    }
    *********/


    No. This code will not work and does not match the description you provided. Ignoring the fact that the code is commented-out, even still it will not work.

    i have declared a buffer holding a 32 bit value.

    No, you have declared an array of 80 bytes (40 ints). Since bytes have 8-bits, your buffer holds 640 bits (not 32).

    i need to send that value on 3rd pin of port 0.

    OK, then why do you send 40 bits when your first sentence says you have 32 bits.

    my problem was how to access each bit of the buffer and send it.

    This is what Mr. Neil suggested with his comment to "look at the shift and bitwise operators."

    Have you looked at any of the example programs provided or looked into the 8051 download files ( http://www.keil.com/download/c51.asp)? There are several examples there that do similar things to what you want.

    Jon

Children
No data