Maker Pro
Maker Pro

Bit manipulation in pic controllers

electronicsLearner77

Jul 2, 2015
306
Joined
Jul 2, 2015
Messages
306
I need to check for a flag like TRUE or False. Can i use char data type or bit type? By creating bit type is it advantageous? I mean to say will it reduce execution time? Also i want the code to be portable. Please advise.
 

Minder

Apr 24, 2015
3,478
Joined
Apr 24, 2015
Messages
3,478
If a unique bit in a word or file, BTFSS, BTFSC.
If you want to change it or clear it etc, then one of the Math operations XORWF etc etc.
M.
 

Amar Dhore

Dec 2, 2015
129
Joined
Dec 2, 2015
Messages
129
Yes it is very useful and it is a very general logic and not specific to the controller. It saves space and execution time as the processor has to deal with a variable.
I do it like this:

#define bit_mask (err1 | err2 | err3 | .....|err8)
define or declare err1, ...err8 as a bit.
Now,
You can clear a bit with simply "AND" and set with "OR" logic.
lets say I have to set a flag for err8 then

uint8_t flagCeck;
flagCeck = bit_mask | err8;
clear with
flagCeck = bit_mask & err8;

Hope this helps.
 
Top