Nicholas Herriot
/
MMA8452_test
A test utility for mma8452
helperFunctions.cpp@7:2fa57cf76768, 2013-10-17 (annotated)
- Committer:
- nherriot
- Date:
- Thu Oct 17 09:40:52 2013 +0000
- Revision:
- 7:2fa57cf76768
- Parent:
- 4:489573e65d47
commit bug fix for multiple start bit on IIC bus.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nherriot | 4:489573e65d47 | 1 | |
nherriot | 4:489573e65d47 | 2 | #include "helperFunctions.h" |
nherriot | 4:489573e65d47 | 3 | |
nherriot | 4:489573e65d47 | 4 | //Serial pc(USBTX, USBRX); |
nherriot | 4:489573e65d47 | 5 | |
nherriot | 4:489573e65d47 | 6 | // This function will print a 7 bit char as a binary number on the screen |
nherriot | 4:489573e65d47 | 7 | void printbincharpad(char c) |
nherriot | 4:489573e65d47 | 8 | { |
nherriot | 4:489573e65d47 | 9 | for (int i = 7; i >= 0; --i) |
nherriot | 4:489573e65d47 | 10 | { |
nherriot | 4:489573e65d47 | 11 | putchar( (c & (1 << i)) ? '1' : '0' ); |
nherriot | 4:489573e65d47 | 12 | if (i==4){putchar(':');} |
nherriot | 4:489573e65d47 | 13 | } |
nherriot | 4:489573e65d47 | 14 | |
nherriot | 4:489573e65d47 | 15 | } |
nherriot | 4:489573e65d47 | 16 | |
nherriot | 4:489573e65d47 | 17 | // This function will take two characters and print formatted as a binary number on the screen |
nherriot | 4:489573e65d47 | 18 | void print2bytebinchar(char *buffer) |
nherriot | 4:489573e65d47 | 19 | { |
nherriot | 4:489573e65d47 | 20 | printbincharpad(buffer[0]); |
nherriot | 4:489573e65d47 | 21 | printf(" -- "); |
nherriot | 4:489573e65d47 | 22 | printbincharpad(buffer[1]); |
nherriot | 4:489573e65d47 | 23 | printf("\n"); |
nherriot | 4:489573e65d47 | 24 | } |