# max bit variable in AVR

#### tariq70

##### New Member
hi I'm using AVR codevision after defining 16 bit variable codevision shows 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?

Last edited:

#### Pommie

##### Well-Known Member
My guess would be codevision as the avr doesn't care if you access all the available ram as bits. How many do you have?
Is codevision similar to C and can you have a Union?

Mike.

#### Ian Rogers

##### User Extraordinaire
Forum Supporter
All I know is... Pic assembly only allows bit access to a few ram locations... AVR may be the same... If your compiler is the GNU derivative ( I think it is )

You can do this ( as Mike suggested )
C:
struct BITACCESS{
unsigned A : 1;
unsigned B : 1;
unsigned C : 1;
unsigned D : 1;
unsigned E : 1;
} flags;

flags.A = x;
Otherwise the compiler WILL use the hardware version.. On the pic's there is only 16 or so locations...

**NOTE** I may be talking about older ( smaller) pics..... I know 8051 does this.. I'm sure I read somewhere that pics do this aswell
BUT!! I cannot substantiate .. Take with pinch of salt!

Last edited:

#### Nigel Goodwin

##### Super Moderator
All I know is... Pic assembly only allows bit access to a few ram locations... AVR may be the same... If your compiler is the GNU derivative ( I think it is )
Are you sure about that Ian?.

The 14 bit assembler bit based routines use 7 bit addressing, so will address 128 bytes per memory bank - with (often) the lower 32 as SFR, and the top 16 RAM locations common across all banks. So about a maximum of 80 bytes per bank, plus the 16 common ones.

Are you perhaps thinking of the common 16 bytes?, and if so is that perhaps a limitation of the C compiler?.

#### Ian Rogers

##### User Extraordinaire
Forum Supporter
Are you sure about that Ian?.

The 14 bit assembler bit based routines use 7 bit addressing, so will address 128 bytes per memory bank - with (often) the lower 32 as SFR, and the top 16 RAM locations common across all banks. So about a maximum of 80 bytes per bank, plus the 16 common ones.

Are you perhaps thinking of the common 16 bytes?, and if so is that perhaps a limitation of the C compiler?.
Yeah! scrambling to find where I read it... I definitely know the 8051 does, I thought I read somewhere that because of banking the bit access was restricted to lower bank... But that probably ony happened way back.. I did used to use the old 12f508..

#### Nigel Goodwin

##### Super Moderator
Yeah! scrambling to find where I read it... I definitely know the 8051 does, I thought I read somewhere that because of banking the bit access was restricted to lower bank... But that probably ony happened way back.. I did used to use the old 12f508..
The 12F508 isn't an old chip - it was the 'modern' replacement for the 12C508

As far as I know there's no such restriction?, and nothing I could see in the datasheet on the 16F1827 on a quick look.

#### Pommie

##### Well-Known Member
I used the 12F208 for a number of projects way back and can confirm there were no restrictions on using the 25 ( ) bytes of memory - however, I was in assembly then.

Mike.

#### Nigel Goodwin

##### Super Moderator
I used the 12F208 for a number of projects way back and can confirm there were no restrictions on using the 25 ( ) bytes of memory - however, I was in assembly then.
Jesus! - was it only 25 bytes

Yup.

Scary isn't it.

Mike.