Electronics > Microcontrollers

max bit variable in AVR

(1/2) > >>

tariq:
hi I'm using AVR codevision after defining 16 bit variable I get this error :
too many global/static 'bit' variables
Does bit variables are limited in AVR?or they are just limited in codevision?or it's something else?

mikerj:
Show us the part of the code causing problems.

tariq:
its on the last bit variable.

jenniferkim:
There is no support for bit type in AVR. You can use a struct like this:


--- Code: ---typedef struct {
    uint8_t bit0:1;
    uint8_t bit1:1;
    uint8_t bit2:1;
    uint8_t bit3:1;
    uint8_t bit4:1;
    uint8_t bit5:1;
    uint8_t bit6:1;
    uint8_t bit7:1;
} BitField;

typedef union {
    BitField asBits;
    uint8_t asByte;
} BitByte;

BitByte mBitField;
--- End code ---

And to access one bit at once you only have to


--- Code: ---mBitField.asBits.bit3 = 1
--- End code ---

That's why I prefer Arduino Micro or Raspberry Pi modules.

westfw:

--- Quote ---too many global/static 'bit' variables
Does bit variables are limited in AVR?
--- End quote ---
There is apparently a configuration parameter that allows you to set the max number of "bit" variables.:

--- Quote ---A number of maximum 104 bit variables can be declared. The size of the bit variables allocated to the program can be specified in the Project|Configure|C
Compiler|Code Generation|Bit Variables Size list box. This size should be as low as possible, in order to free registers for allocation to other global variables.
--- End quote ---
(https://www.thierry-lequeu.fr/data/CodeVisonAVR-doc.pdf (page 68)


--- Quote ---or they are just limited in codevision?
--- End quote ---
Bit variables are not standard C, and most compilers don't implement them at all.
The portable method is to use structure-based bitfields as described by jenniferkim...

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version