I am trying to interface to an laser mouse sensor.I would like to be able to set individual bits by their names listed in the data sheet for easy identification.I have the following code.
//Multidimential bitset.cpp #include#include int main () { // Create a bitset that is 228 bits long called Regs "registers". // These 228 bits represent all the bits in the 28 registers being used "Reserved registers were excluded" std::bitset<228> Regs; // Create variables to represent the individual registers and all the bits them. //---------------------------------------------------- //MOTION register and it's individual bits. char MOTION = bitset[0] : 8 //8 bits for the MOTION register bool MOT = MOTION[7] : 1 //bit 7 of the MOTION register bool OVF = MOTION[3] : 1 //bit 4 of the MOTION register bool LP_VALID = MOTION[4] : 1 //bit 3 of the MOTION register bool FAULT = MOTION[5] : 1 //bit 2 of the MOTION register //bits 5,4,unused,bits 0,1 reserved //---------------------------------------------------- //Delta_X register and it's individual bits. char Delta_X = bitset[1] : 8 //8 bits for the MOTION register bool _X7 = Delta_X[7]: 1 //bit 7 of the MOTION register bool _X6 = Delta_X[6]: 1 //bit 4 of the MOTION register bool _X5 = Delta_X[5]: 1 //bit 3 of the MOTION register bool _X4 = Delta_X[4]: 1 //bit 2 of the MOTION register bool _X3 = Delta_X[3]: 1 //bit 2 of the MOTION register bool _X2 = Delta_X[2]: 1 //bit 2 of the MOTION register bool _X1 = Delta_X[1]: 1 //bit 2 of the MOTION register bool _X0 = Delta_X[0]: 1 //bit 2 of the MOTION register //---------------------------------------------------- }
Now I would set the 7th bit called MOT in the MOTION register to a 1 with the following.
Regs.MOTION.set(MOT,1)
opinions? any sugestions, maps instead maybe?