Hi,
look into attached file to see solution.
You should think about compiler setup .... look into the help or manuals ... keyword=bitfield.
Your issue is order of bits in the bitfield.
Best regards,
Ladislav
My test code:
#include "derivative.h" /* derivative-specific definitions */
//******************************************************************************
typedef union
{
unsigned long w;
struct
{
unsigned char disp_comp_cal : 2;//0
unsigned char disp_home : 2;//2
unsigned char disp_trips : 2;//4
unsigned char disp_fuel : 2;//6
unsigned char disp_hours : 2;//8
unsigned char disp_service : 2;//10
unsigned char disp_diags : 2;//12
unsigned char disp_slftst : 2;//14
unsigned char disp_cust_set : 2;//16
unsigned int dummy : 14;
}b;
}attrib2;
//******************************************************************************
void main(void)
{
attrib2 attrib22;
attrib22.w = 0x00UL;
attrib22.b.disp_comp_cal =2;
attrib22.b.disp_home =1;
attrib22.b.disp_trips =3;
attrib22.b.disp_fuel =1;
attrib22.b.disp_hours =2;
attrib22.b.disp_service =1;
attrib22.b.disp_diags =3;
attrib22.b.disp_slftst =1;
attrib22.b.disp_cust_set =1;
attrib22.b.dummy =0x3FFFF;
// expected 0B1001 1101 1001 1101 0111 1111 1111 1111
// 0x9D9D 7FFF
DDRAB = 0xFFFF;
//------------------------
for(;;)
{
attrib22.b.disp_comp_cal +=1;
attrib22.b.disp_home +=1;
attrib22.b.disp_trips +=1;
attrib22.b.disp_fuel +=1;
attrib22.b.disp_hours +=1;
attrib22.b.disp_service +=1;
attrib22.b.disp_diags +=1;
attrib22.b.disp_slftst +=1;
attrib22.b.disp_cust_set +=1;
PORTAB = (unsigned int) (attrib22.w & 0xFFFFUL);
PORTAB = (unsigned int) ((attrib22.w >> 16) & 0xFFFFUL);
}
//------------------------
EnableInterrupts;
//------------------------
for(;;)
{
_FEED_COP(); /* feeds the dog */
}
//------------------------
}
//******************************************************************************