Display_nums

Dependencies:   mbed

Fork of Microprocessors_Template by EECS397

Revision:
2:8412c8623314
Parent:
1:b46d63943c99
Child:
3:48be985187c6
--- a/main.cpp	Mon Feb 19 18:23:29 2018 +0000
+++ b/main.cpp	Thu Feb 22 01:50:12 2018 +0000
@@ -15,6 +15,7 @@
 #define DSP_TST_OFF 0x0f00
 
 //ASCII character values of decimal numbers
+#define ZERO 48
 #define ONE 49
 #define TWO 50
 #define THREE 51
@@ -36,67 +37,113 @@
 int main()
 {
 
+    // Setting the formal of display_ctr
     dsp_ncs = 1;
     display_ctr.format(16, 0);
+    
+    // Setting to Normal Mode
+    dsp_ncs = 0;
+    display_ctr.write(DSP_TST_OFF); //normal mode
+    dsp_ncs = 1;
+    wait(.5);
 
-    while(1) {
-        dsp_ncs = 0;
-        display_ctr.write(DSP_TST_OFF); //normal mode
-        dsp_ncs = 1;
-        wait(.5);
-        dsp_ncs = 0;
-        display_ctr.write(0x090F);  //decode mode
-        dsp_ncs = 1;
-        wait(.5);
-        dsp_ncs = 0;
-        display_ctr.write(0x0b04); //display 5 digits
-        dsp_ncs = 1;
-        wait(.5);
-        dsp_ncs = 0;
-        display_ctr.write(0x0c01); //shutdown mode
-        dsp_ncs = 1;
-        wait(.5);
-        dsp_ncs = 0;
-        display_ctr.write(0x0104);
-        dsp_ncs = 1;
-        wait(0.5);
-        dsp_ncs = 0;
+    
+    // Setting it to display 5 digits
+    dsp_ncs = 0;
+    display_ctr.write(0x0b04); //display 5 digits
+    dsp_ncs = 1;
+    wait(.5);
+
+    /* Setting decode mode */
+    // This means it only looks at the lower nibble of data, ignoring the 
+    // first portion of data
+    dsp_ncs = 0;
+    display_ctr.write(0x090F); //decode mode
+    dsp_ncs = 1;
+    wait(.5);
+    
+
+    // Setting it to shutdown mode
+    dsp_ncs = 0;
+    display_ctr.write(0x0c01); //shutdown mode
+    dsp_ncs = 1;
+    wait(.5);
+    
+    //dsp_ncs = 0;
+    //display_ctr.write(0x0104); // write a 4
+    //dsp_ncs = 1;
+    //wait(0.5);
+    
+    // Sets the display to full brightness
+    dsp_ncs = 0;
+    display_ctr.write(0x0A);
+    dsp_ncs = 1;
+    wait(.5);
+    dsp_ncs = 0;
+
+    while (1)
+    {
         promptUser();
-
     }
-
-}
+}// pcw
 
 //Prompt User for Numbers
 void promptUser()
 {
-    pc.printf("Please enter a number 1-9:\n");
+    pc.printf("Please enter a number 0-9:\n");
     input = pc.getc();
-    if (input < 49 || input > 57) {
+    if (input < 48 || input > 57)
+    {
         pc.printf("Invalid Number.\n");
         promptUser();
-    } else {
-        switch (input) {
-            case ONE:
-                display_ctr.write(0x0101);
-            case TWO:
-                display_ctr.write(0x0102);
-            case THREE:
-                display_ctr.write(0x0103);
-            case FOUR:
-                display_ctr.write(0x0104);
-            case FIVE:
-                display_ctr.write(0x0105);
-            case SIX:
-                display_ctr.write(0x0106);
-            case SEVEN:
-                display_ctr.write(0x0107);
-            case EIGHT:
-                display_ctr.write(0x0108);
-            case NINE:
-                display_ctr.write(0x0109);
+    }
+    else
+    {
+        switch (input)
+        {
+        case ZERO:
+            pc.printf("You typed 0\n");
+            display_ctr.write(0x0100);
+            break;
+        case ONE:
+            pc.printf("You typed 1\n");
+            display_ctr.write(0x0101);
+            break;
+        case TWO:
+            pc.printf("You typed 2\n");
+            display_ctr.write(0x0102);
+            break;
+        case THREE:
+            pc.printf("You typed 3\n");
+            display_ctr.write(0x0103);
+            break;
+        case FOUR:
+            pc.printf("You typed 4\n");
+            display_ctr.write(0x0104);
+            break;
+        case FIVE:
+            pc.printf("You typed 5\n");
+            display_ctr.write(0x0105);
+            break;
+        case SIX:
+            pc.printf("You typed 6\n");
+            display_ctr.write(0x0106);
+            break;
+        case SEVEN:
+            pc.printf("You typed 7\n");
+            display_ctr.write(0x0107);
+            break;
+        case EIGHT:
+            pc.printf("You typed 8\n");
+            display_ctr.write(0x0108);
+            break;
+        case NINE:
+            display_ctr.write(0x0109);
+            pc.printf("You typed 9\n");
+            break;
         }
         dsp_ncs = 1;
         wait(0.5);
+        dsp_ncs = 0;
     }
 }
\ No newline at end of file