Modified, multi-file version of my orginal 7-segment test program.

Files at this revision

API Documentation at this revision

Comitter:
CSTritt
Date:
Wed Nov 10 14:51:10 2021 +0000
Parent:
111:47b0267b8dd4
Commit message:
Modified multi-file version of my original 7-segment test program.

Changed in this revision

display.cpp Show annotated file Show diff for this revision Revisions of this file
display.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 47b0267b8dd4 -r 2af5a1ac47d5 display.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/display.cpp	Wed Nov 10 14:51:10 2021 +0000
@@ -0,0 +1,29 @@
+#include "display.h"
+
+void display(int disVal, BusOut &disBus){
+    // 7-segment, active low look-up-table. Displays Hex 0 to F, dp, all off 
+    // and all on. 
+    const int lutAL[] = { 
+    0b00000011, // 0 = 0
+    0b10011111, // 1 = 1
+    0b00100101, // 2 = 2
+    0b00001101, // 3 = 3
+    0b10011001, // 4 = 4
+    0b01001001, // 5 = 5
+    0b01000001, // 6 = 6
+    0b00011111, // 7 = 7
+    0b00000001, // 8 = 8
+    0b00001001, // 9 = 9
+    0b00010001, // 10 = a
+    0b11000001, // 11 = b
+    0b11100101, // 12 = c
+    0b10000101, // 13 = d
+    0b01100001, // 14 = e
+    0b01110001, // 15 = f
+    0b11111110, // 16 = dp
+    0b11111111, // 17 = All off
+    0b00000000  // 18 = All on
+    //abcdefg_dp – 7-segement output codes 0 to 18.
+    };
+    disBus = lutAL[disVal];
+}
\ No newline at end of file
diff -r 47b0267b8dd4 -r 2af5a1ac47d5 display.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/display.h	Wed Nov 10 14:51:10 2021 +0000
@@ -0,0 +1,5 @@
+#ifndef MY_DSPLY
+#define MY_DSPLY
+#include "mbed.h"
+void display(int disVal, BusOut &disBus);
+#endif
\ No newline at end of file
diff -r 47b0267b8dd4 -r 2af5a1ac47d5 main.cpp
--- a/main.cpp	Tue Nov 09 20:33:18 2021 +0000
+++ b/main.cpp	Wed Nov 10 14:51:10 2021 +0000
@@ -1,6 +1,9 @@
 /*
-    Project: 21_7segmentTest_v5 (Lab Wk 10)
-    File: main.cpp
+    Project: 21_7segmentTest2_v5 (Lab Wk 10)
+    File: main.cpp (v. 1.0)
+    
+    This is a modified, multi-file version of my original 7-segment display 
+    test program.
     
     This test program confirms hardware operation and demonstrates use of the 
     7-segement display. It will also be used as the starting point for the 
@@ -17,61 +20,33 @@
     Created: 11/9/21 (v. 1.0)
 */
 #include "mbed.h"
-
-void display(int disVal, BusOut &disBus);
-
-Serial pc(USBTX, NC, 9600); // Use for debugging.
+#include "display.h"
 
 const int SLP_TIME = 1000; // Update once per second.
 
 int main(void)
 {
+    Serial pc(USBTX, NC, 9600); // Use for debugging.
     // Note that bit sequence is the oposite of what I initially thought they 
     // would be. That is, pins are listed in low order to high order sequence.
     BusOut disBus(D9, D8, D7, D6, D5, D4, D3, D2); // The display.
     int myCount = 0; // Loop count. Rolls over at 18.
     
     // Test the wiring.
+    
     display(18, disBus);  // All on (binary).
-    ThisThread::sleep_for(2000); // Test even bars for 0.4 seconds.
+    pc.printf("Wiring test. All segments on.\n"); // Status message.
+    ThisThread::sleep_for(2000); // Light all segments for 2 seconds.
     display(17, disBus);  // All off (binary).
-    ThisThread::sleep_for(2000); // Test even bars for 0.4 seconds.
+    pc.printf("Wiring test All segments off.\n"); // Status message.
+    ThisThread::sleep_for(2000); // Turn off all segments for 2 seconds.
     
     // Enter main loop.
     while(true) {
         display(myCount, disBus); // Display myCount (count).
-        pc.printf("In main myCount = %d.\n", myCount); // Send count to PC.
+        pc.printf("In main myCount = %x.\n", myCount); // Send count to PC.
         myCount++; // Increment the count.
         if (myCount > 18) myCount = 0; // Rollover!
         ThisThread::sleep_for(SLP_TIME);  // Display value for 1 second.
     }
-}
-
-void display(int disVal, BusOut &disBus){
-    // 7-segment, active low look-up-table. Displays Hex 0 to F, dp, all off 
-    // and all on. 
-    const int lutAL[] = { 
-    0b00000011, // 0 = 0
-    0b10011111, // 1 = 1
-    0b00100101, // 2 = 2
-    0b00001101, // 3 = 3
-    0b10011001, // 4 = 4
-    0b01001001, // 5 = 5
-    0b01000001, // 6 = 6
-    0b00011111, // 7 = 7
-    0b00000001, // 8 = 8
-    0b00001001, // 9 = 9
-    0b00010001, // 10 = a
-    0b11000001, // 11 = b
-    0b11100101, // 12 = c
-    0b10000101, // 13 = d
-    0b01100001, // 14 = e
-    0b01110001, // 15 = f
-    0b11111110, // 16 = dp
-    0b11111111, // 17 = All off
-    0b00000000  // 18 = All on
-    //abcdefg_dp – 7-segement output codes 0 to 18.
-    };
-    disBus = lutAL[disVal];
-    pc.printf("In display, disVal = %d\n", disVal);
 }
\ No newline at end of file