[an error occurred while processing this directive]
|
Вот этот примерчик ясно показывает // See the main.lst after compilation typedef struct {
//IAR C/C++ Compiler for AVR
//4.11A/W32 [Evaluation] (4.11.1.3)
// The result of calling CreateByte() is always 128, independently on LSB of myvol variable.
// Looks like compiler ignores other assignments to fields in bitfield
// if there is a constant value assigned to another field.
// Probably, similar behavior appears when using SFRs because they are also represented as bitfields
// in header files.
union {
struct {
unsigned char b0:1;
unsigned char b1:1;
unsigned char b2:1;
unsigned char b3:1;
unsigned char b4:1;
unsigned char b5:1;
unsigned char b6:1;
unsigned char b7:1;
};
unsigned char by;
};
} DBYTE;
volatile unsigned char myvol; //Volatile. We can also use any SFR instead, i.e. PORTA.
#pragma optimize = s 9
unsigned char CreateByte (void)
{
DBYTE db;
db.by = 0;
db.b7 = 1;
db.b0 = ((myvol&1) != 0) ? 1 : 0;
return db.by; //Result must be (128 + LSB(myval)), but it is always 128.
}
__C_task void main( void )
{
myvol = CreateByte();
}
E-mail: info@telesys.ru