![](/media/cache/profiles/Headshot_Fall2023_Square.jpg.50x50_q85.jpg)
This program is intended for use exploring bitwise operator. It also demonstrates the use of the 8-bit unsigned char type and using printf to display integer values in various number bases.
main.cpp@108:61d009929518, 2021-10-01 (annotated)
- Committer:
- CSTritt
- Date:
- Fri Oct 01 18:18:49 2021 +0000
- Revision:
- 108:61d009929518
- Parent:
- 107:e7084caca83a
This program is intended for use exploring bitwise operator. It also demonstrates the use of the 8-bit unsigned char type and using printf to display integer values in various number bases.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
CSTritt | 107:e7084caca83a | 1 | /* |
CSTritt | 107:e7084caca83a | 2 | Project: 21_BitTests_v5 |
CSTritt | 107:e7084caca83a | 3 | File: main.cpp |
CSTritt | 107:e7084caca83a | 4 | |
CSTritt | 108:61d009929518 | 5 | This program is intended for use exploring bitwise operator. It also |
CSTritt | 108:61d009929518 | 6 | demonstrates the use of the 8-bit unsigned char type and using printf to |
CSTritt | 108:61d009929518 | 7 | display integer values in various number bases. |
CSTritt | 107:e7084caca83a | 8 | |
CSTritt | 107:e7084caca83a | 9 | Last modified 9/30/21 by C. S. Tritt (v. 1.0) |
CSTritt | 107:e7084caca83a | 10 | */ |
Jonathan Austin |
0:2757d7abb7d9 | 11 | #include "mbed.h" |
Jonathan Austin |
0:2757d7abb7d9 | 12 | |
CSTritt | 107:e7084caca83a | 13 | // Pulse durations. |
CSTritt | 107:e7084caca83a | 14 | const int SPULSE = 500; |
CSTritt | 107:e7084caca83a | 15 | const int LPULSE = 1000; |
Jonathan Austin |
0:2757d7abb7d9 | 16 | |
CSTritt | 107:e7084caca83a | 17 | // Construct a transmit only serial connection over our USB. |
CSTritt | 107:e7084caca83a | 18 | Serial pc(USBTX, NC, 9600); // Serial channel to PC. |
CSTritt | 107:e7084caca83a | 19 | // Construct a 8-bit BusOut bargraph display. |
CSTritt | 107:e7084caca83a | 20 | BusOut barGraph(D2, D3, D4, D5, D6, D7, D8, D9); // The display. |
CSTritt | 107:e7084caca83a | 21 | |
mbed_official | 82:abf1b1785bd7 | 22 | int main() |
mbed_official | 82:abf1b1785bd7 | 23 | { |
CSTritt | 107:e7084caca83a | 24 | while (true) { // Main loop. |
CSTritt | 107:e7084caca83a | 25 | // Set some values. |
CSTritt | 107:e7084caca83a | 26 | unsigned char myIntA = 0b10101010; // Binary. 170_10. |
CSTritt | 107:e7084caca83a | 27 | unsigned char myIntB = 0x3E; // Hex. 62_10. |
CSTritt | 107:e7084caca83a | 28 | unsigned char myIntC = 077; // Octal, 63_10. |
CSTritt | 107:e7084caca83a | 29 | |
CSTritt | 107:e7084caca83a | 30 | // Do a bitwise operation. |
CSTritt | 107:e7084caca83a | 31 | unsigned char myIntD = myIntA | myIntB; |
CSTritt | 107:e7084caca83a | 32 | |
CSTritt | 107:e7084caca83a | 33 | // Send output to PC and bargraph. |
CSTritt | 107:e7084caca83a | 34 | pc.printf("myIntA = %d (base 10).\n", myIntA); |
CSTritt | 107:e7084caca83a | 35 | barGraph = myIntA; |
CSTritt | 107:e7084caca83a | 36 | ThisThread::sleep_for(SPULSE); |
CSTritt | 107:e7084caca83a | 37 | |
CSTritt | 107:e7084caca83a | 38 | pc.printf("myIntB = %X (Hexadecimal).\n", myIntB); |
CSTritt | 107:e7084caca83a | 39 | barGraph = myIntB; |
CSTritt | 107:e7084caca83a | 40 | ThisThread::sleep_for(SPULSE); |
CSTritt | 107:e7084caca83a | 41 | |
CSTritt | 107:e7084caca83a | 42 | pc.printf("myIntC = %o (Octal).\n", myIntC); |
CSTritt | 107:e7084caca83a | 43 | barGraph = myIntC; |
CSTritt | 107:e7084caca83a | 44 | ThisThread::sleep_for(SPULSE); |
CSTritt | 107:e7084caca83a | 45 | |
CSTritt | 107:e7084caca83a | 46 | pc.printf("myIntD = %X (Hexadecimal).\n", myIntD); |
CSTritt | 107:e7084caca83a | 47 | barGraph = myIntD; |
CSTritt | 107:e7084caca83a | 48 | ThisThread::sleep_for(LPULSE); |
CSTritt | 107:e7084caca83a | 49 | pc.printf("Repeating...\n\n"); |
Jonathan Austin |
0:2757d7abb7d9 | 50 | } |
CSTritt | 107:e7084caca83a | 51 | } |