Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Accessing bits of variable, XC8

Status
Not open for further replies.
All that volatile does, is to let the optimiser skip over the declaration.. This way the compiler lets it stay where you put it... If, for example, you are testing but not actually using the variable, the optimiser will just leave it out!! Very annoying whilst trying to debug!!

If you are using the free version, then forget the volatile bit as there is no / little optimisation done..
 
I tried your suggestion to assign it to an address and the compiler did that but in the main code it still doesn't call the function when the bit is changed. I looked @ the program memory for the "if" statement and it shows MOVF tstatus, W, ACCESS. If I understand this it is looking @ the whole byte and not the bit. I have tried to mask i.e. if (tstatus.a &0x01 ==true)call function ,but it still will not execute that line.
 
I figured it out. When I declared the bits I was doing

bool a:0;
bool b:0;
ect.....

so apparently the 0 is not initializing the bit as I thought, as I have change them all to 1's and now it works.
 
Last edited:
The whole point of creating a union is to tell the compiler what is where, you can have groups of bits 1 ~ 7
C:
union{
   struct{
   unsigned flags:3;
   unsigned over:1;
   unsigned startup:1;
   unsigned mode:2;
   };
} mystuf;
So any thing that has 7 states can fit into the flags.... mystuf.flags = 6;
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top