Passing Bitsets as parameters in functions

Mr Crusty
 
Avatar
 
Subject:

Passing Bitsets as parameters in functions

 · 
Posted: 29.10.2009 - 20:17  ·  #1
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 :P
Selected quotes for multi-quoting:   0

Registered users in this topic

Currently no registered users in this section

The statistic shows who was online during the last 5 minutes. Updated every 90 seconds.
MySQL Queries: 15 · Cache Hits: 13   32   45 · Page-Gen-Time: 0.022611s · Memory Usage: 2 MB · GZIP: on · Viewport: SMXL-HiDPI