S12ZVC functions like BitRead BitSet BitClear

cancel
Showing results for 
Search instead for 
Did you mean: 

S12ZVC functions like BitRead BitSet BitClear

Jump to solution
73 Views
highlander
Contributor I

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

0 Kudos
1 Solution
53 Views
lama
NXP TechSupport
NXP TechSupport

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

View solution in original post

Tags (1)
0 Kudos
1 Reply
54 Views
lama
NXP TechSupport
NXP TechSupport

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

View solution in original post

Tags (1)
0 Kudos