Simple training demonstration to show the use of union and structure
Fork of OddExample2 by
Revision 11:085c63023906, committed 2013-11-26
- Comitter:
- jf1452
- Date:
- Tue Nov 26 15:03:49 2013 +0000
- Parent:
- 10:6c0cd51df4df
- Commit message:
- Bit definitions using struct and union
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 6c0cd51df4df -r 085c63023906 main.cpp --- a/main.cpp Tue Nov 26 14:53:06 2013 +0000 +++ b/main.cpp Tue Nov 26 15:03:49 2013 +0000 @@ -9,8 +9,14 @@ { char Byte; // Use this to map a byte struct { - char Odd: 1; // this is the same as Bit0 - char Others: 7; // Just pad the rest of the bits + char Bit0: 1; // map individual + char Bit1: 1; // bits onto the + char Bit2: 1; // mapped byte. + char Bit3: 1; + char Bit4: 1; + char Bit5: 1; + char Bit6: 1; + char Bit7: 1; }; }; @@ -22,7 +28,7 @@ wait (10); // Wait 10 seconds to connect port - if (cMyNumber.Odd == 1) + if (cMyNumber.Bit0 == 1) serial.printf("%i is odd\n\r", cMyNumber.Byte); else serial.printf("%i is even\n\r", cMyNumber.Byte);