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

How can map some bit in a array

Dear all,

I want to access some continus bit,let me can modify the value,such as,
for(i = 0 ; i < 10 ; i++)
{
bit[i] = ?;
}

but you know,the bit var cann't build as a array in keil c51,but build some boolean var with byte will speed down the MCU and more code,Who can give me a good advice and a way,Thanks in advance.

Parents
  • Hi,

    1) Keil does support Bit-addressable Objects. Read all about bdata memory, bit type, sbit keyword.
    2) you always are free to use ASM/ENDASM subroutines;
    3) something like:

    unsigned long bitfield, i;   //32-bits array
    
    for(i = 0 ; i < 10 ; i++)
    {
    // set:
    bitfield |= 1<<i;
    // reset:
    bitfield &= ~(1<<i);
    // read state:
    (bitfield & 1<<i)
    }
    ...but I have not checked how Keil Compiler process it...
    Good days!

Reply
  • Hi,

    1) Keil does support Bit-addressable Objects. Read all about bdata memory, bit type, sbit keyword.
    2) you always are free to use ASM/ENDASM subroutines;
    3) something like:

    unsigned long bitfield, i;   //32-bits array
    
    for(i = 0 ; i < 10 ; i++)
    {
    // set:
    bitfield |= 1<<i;
    // reset:
    bitfield &= ~(1<<i);
    // read state:
    (bitfield & 1<<i)
    }
    ...but I have not checked how Keil Compiler process it...
    Good days!

Children
No data