Hello Everyone.
First timer here. I have not been able to find a way of setting bits for booleans the same way you can do so on Arduino. Commands like bitRead(), bitSet() and bitClear().
Are there similar commands for this processor?
Thanks
Solved! Go to Solution.
Hi,
If you are an assembler player then you have instructions:
( for more info please read the S12ZCPU_RM )
BSET Di,#opr5i
BSET.bwl oprmemreg,#opr5i
BSET.bwl oprmemreg,Dn
BCLR Di,#opr5i
BCLR.bwl oprmemreg,#opr5i
BCLR.bwl oprmemreg,Dn
(Note; all of them are read-modify-write instructions. It is necassary to think about it in the case of interupt flags clearing when you can acccidentaly clear all flags except required. x = mask; is not the same as x = x | mask; The first one is correct for flags learing. The second one clears all flags which are set even it uses bit instruction in the assembler code after compiling and building. )
If you use C then you can use following approaches to set or clear bit(s):
Let rm is register or memory
rm |= mask; // set bits defined by mask
rm &= ~mask; // clear bits defined by mask
rm ^= mask; // flip bits defined by mask
rm &= mask; // test bits defined by mask
or
#define bytesetmask(rm,mask) (rm |= mask) // set bits defined by mask
#define byteclearmask(rm,mask) (rm &= ~mask) // clear bits defined by mask
#define byteflipmask(rm,mask) (rm ^= mask) // flips bits defined by mask
#define bytetestmask(rm,mask) (rm &= mask) // flips bits defined by mask
or
#define bitset(rm,nbit) (rm |= (1<<(nbit))) // set just one bit
#define bitclear(rm,nbit) (rm &= ~(1<<(nbit))) // clear just one bit
#define bitflip(rm,nbit) (rm ^= (1<<(nbit))) // flip just one bit
#define bitcheck(rm,nbit) (rm & (1<<(nbit))) // test just one bit
I hope I have not made a mistake. I wrote it in one breath.
BTW; Processor Expert, if you use it…from the help:
Processor Expert defines a set of C macros providing an effective access to a specified register or its part. The definitions of all these macros are in the file PE_Types.h.
Only short example from the PE_types.h file:
/**************************************************/
/* PE register access macros */
/**************************************************/
#define setRegBit(reg, bit) (reg |= reg##_##bit##_##MASK)
#define clrRegBit(reg, bit) (reg &= ~reg##_##bit##_##MASK)
#define getRegBit(reg, bit) (reg & reg##_##bit##_##MASK)
#define setReg(reg, val) (reg = (word)(val))
#define getReg(reg) (reg)
#define setRegBits(reg, mask) (reg |= (word)(mask))
Best regards,
Ladislav
Hi,
If you are an assembler player then you have instructions:
( for more info please read the S12ZCPU_RM )
BSET Di,#opr5i
BSET.bwl oprmemreg,#opr5i
BSET.bwl oprmemreg,Dn
BCLR Di,#opr5i
BCLR.bwl oprmemreg,#opr5i
BCLR.bwl oprmemreg,Dn
(Note; all of them are read-modify-write instructions. It is necassary to think about it in the case of interupt flags clearing when you can acccidentaly clear all flags except required. x = mask; is not the same as x = x | mask; The first one is correct for flags learing. The second one clears all flags which are set even it uses bit instruction in the assembler code after compiling and building. )
If you use C then you can use following approaches to set or clear bit(s):
Let rm is register or memory
rm |= mask; // set bits defined by mask
rm &= ~mask; // clear bits defined by mask
rm ^= mask; // flip bits defined by mask
rm &= mask; // test bits defined by mask
or
#define bytesetmask(rm,mask) (rm |= mask) // set bits defined by mask
#define byteclearmask(rm,mask) (rm &= ~mask) // clear bits defined by mask
#define byteflipmask(rm,mask) (rm ^= mask) // flips bits defined by mask
#define bytetestmask(rm,mask) (rm &= mask) // flips bits defined by mask
or
#define bitset(rm,nbit) (rm |= (1<<(nbit))) // set just one bit
#define bitclear(rm,nbit) (rm &= ~(1<<(nbit))) // clear just one bit
#define bitflip(rm,nbit) (rm ^= (1<<(nbit))) // flip just one bit
#define bitcheck(rm,nbit) (rm & (1<<(nbit))) // test just one bit
I hope I have not made a mistake. I wrote it in one breath.
BTW; Processor Expert, if you use it…from the help:
Processor Expert defines a set of C macros providing an effective access to a specified register or its part. The definitions of all these macros are in the file PE_Types.h.
Only short example from the PE_types.h file:
/**************************************************/
/* PE register access macros */
/**************************************************/
#define setRegBit(reg, bit) (reg |= reg##_##bit##_##MASK)
#define clrRegBit(reg, bit) (reg &= ~reg##_##bit##_##MASK)
#define getRegBit(reg, bit) (reg & reg##_##bit##_##MASK)
#define setReg(reg, val) (reg = (word)(val))
#define getReg(reg) (reg)
#define setRegBits(reg, mask) (reg |= (word)(mask))
Best regards,
Ladislav