![](/media/cache/profiles/Headshot_Fall2023_Square.jpg.50x50_q85.jpg)
Modified, multi-file version of my orginal 7-segment test program.
main.cpp@112:2af5a1ac47d5, 2021-11-10 (annotated)
- Committer:
- CSTritt
- Date:
- Wed Nov 10 14:51:10 2021 +0000
- Revision:
- 112:2af5a1ac47d5
- Parent:
- 111:47b0267b8dd4
Modified multi-file version of my original 7-segment test program.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
CSTritt | 107:61b9c99a4e27 | 1 | /* |
CSTritt | 112:2af5a1ac47d5 | 2 | Project: 21_7segmentTest2_v5 (Lab Wk 10) |
CSTritt | 112:2af5a1ac47d5 | 3 | File: main.cpp (v. 1.0) |
CSTritt | 112:2af5a1ac47d5 | 4 | |
CSTritt | 112:2af5a1ac47d5 | 5 | This is a modified, multi-file version of my original 7-segment display |
CSTritt | 112:2af5a1ac47d5 | 6 | test program. |
CSTritt | 108:eee3167b25b4 | 7 | |
CSTritt | 111:47b0267b8dd4 | 8 | This test program confirms hardware operation and demonstrates use of the |
CSTritt | 111:47b0267b8dd4 | 9 | 7-segement display. It will also be used as the starting point for the |
CSTritt | 111:47b0267b8dd4 | 10 | Week 10 lab practical. |
CSTritt | 111:47b0267b8dd4 | 11 | |
CSTritt | 111:47b0267b8dd4 | 12 | Display "value" from 0 to F_16 to DP (16_10) to all off (17_10) to all on |
CSTritt | 111:47b0267b8dd4 | 13 | (17_10) on 7-segment display. |
CSTritt | 108:eee3167b25b4 | 14 | |
CSTritt | 111:47b0267b8dd4 | 15 | Note: This display function takes an integer argument to be display and a |
CSTritt | 111:47b0267b8dd4 | 16 | BusOut object (passed by reference) on which to display it as arguments. |
CSTritt | 111:47b0267b8dd4 | 17 | This differs from the Week 8 Lab display function. |
CSTritt | 111:47b0267b8dd4 | 18 | |
CSTritt | 108:eee3167b25b4 | 19 | Written by: Dr. C. S. Tritt |
CSTritt | 111:47b0267b8dd4 | 20 | Created: 11/9/21 (v. 1.0) |
CSTritt | 107:61b9c99a4e27 | 21 | */ |
Jonathan Austin |
0:2757d7abb7d9 | 22 | #include "mbed.h" |
CSTritt | 112:2af5a1ac47d5 | 23 | #include "display.h" |
CSTritt | 111:47b0267b8dd4 | 24 | |
CSTritt | 111:47b0267b8dd4 | 25 | const int SLP_TIME = 1000; // Update once per second. |
CSTritt | 108:eee3167b25b4 | 26 | |
CSTritt | 111:47b0267b8dd4 | 27 | int main(void) |
CSTritt | 111:47b0267b8dd4 | 28 | { |
CSTritt | 112:2af5a1ac47d5 | 29 | Serial pc(USBTX, NC, 9600); // Use for debugging. |
CSTritt | 111:47b0267b8dd4 | 30 | // Note that bit sequence is the oposite of what I initially thought they |
CSTritt | 111:47b0267b8dd4 | 31 | // would be. That is, pins are listed in low order to high order sequence. |
CSTritt | 111:47b0267b8dd4 | 32 | BusOut disBus(D9, D8, D7, D6, D5, D4, D3, D2); // The display. |
CSTritt | 111:47b0267b8dd4 | 33 | int myCount = 0; // Loop count. Rolls over at 18. |
CSTritt | 111:47b0267b8dd4 | 34 | |
CSTritt | 108:eee3167b25b4 | 35 | // Test the wiring. |
CSTritt | 112:2af5a1ac47d5 | 36 | |
CSTritt | 111:47b0267b8dd4 | 37 | display(18, disBus); // All on (binary). |
CSTritt | 112:2af5a1ac47d5 | 38 | pc.printf("Wiring test. All segments on.\n"); // Status message. |
CSTritt | 112:2af5a1ac47d5 | 39 | ThisThread::sleep_for(2000); // Light all segments for 2 seconds. |
CSTritt | 111:47b0267b8dd4 | 40 | display(17, disBus); // All off (binary). |
CSTritt | 112:2af5a1ac47d5 | 41 | pc.printf("Wiring test All segments off.\n"); // Status message. |
CSTritt | 112:2af5a1ac47d5 | 42 | ThisThread::sleep_for(2000); // Turn off all segments for 2 seconds. |
CSTritt | 111:47b0267b8dd4 | 43 | |
CSTritt | 111:47b0267b8dd4 | 44 | // Enter main loop. |
CSTritt | 111:47b0267b8dd4 | 45 | while(true) { |
CSTritt | 111:47b0267b8dd4 | 46 | display(myCount, disBus); // Display myCount (count). |
CSTritt | 112:2af5a1ac47d5 | 47 | pc.printf("In main myCount = %x.\n", myCount); // Send count to PC. |
CSTritt | 111:47b0267b8dd4 | 48 | myCount++; // Increment the count. |
CSTritt | 111:47b0267b8dd4 | 49 | if (myCount > 18) myCount = 0; // Rollover! |
CSTritt | 111:47b0267b8dd4 | 50 | ThisThread::sleep_for(SLP_TIME); // Display value for 1 second. |
CSTritt | 111:47b0267b8dd4 | 51 | } |
CSTritt | 108:eee3167b25b4 | 52 | } |