Hi,
Probably not much interest for people who have already understood the following concept, but may be useful for newbies.
Taken me a week of nights to realize it's so simple.
I have been working on an Accelerometer unit that uses TWI and has a lot of registers to load, without altering all existing bits in the registers.
There are all 8bit and have reg names and bit names given by the chip maker in their data sheet.
For legibility of code I have made each register a bit set with bits enumerated in line with the makers bit codes.
Getting each register loaded becomes easy when passed as a bitset parameter to the TWI set functions attached. One set bits the other clears bits
If you run this in the emulator and watch the bitsets you will see how the bit true and false states are passed into and processed in the procedure. I have not set the function to clear all vars on entry, so second time through shows how the + - in bitsets works.
If altering be aware that Bitset length must be the same or compile error
Regards
Crusty
Probably not much interest for people who have already understood the following concept, but may be useful for newbies.
Taken me a week of nights to realize it's so simple.
I have been working on an Accelerometer unit that uses TWI and has a lot of registers to load, without altering all existing bits in the registers.
There are all 8bit and have reg names and bit names given by the chip maker in their data sheet.
For legibility of code I have made each register a bit set with bits enumerated in line with the makers bit codes.
Getting each register loaded becomes easy when passed as a bitset parameter to the TWI set functions attached. One set bits the other clears bits
If you run this in the emulator and watch the bitsets you will see how the bit true and false states are passed into and processed in the procedure. I have not set the function to clear all vars on entry, so second time through shows how the + - in bitsets works.
If altering be aware that Bitset length must be the same or compile error
Regards
Crusty