Dependencies:   mbed

Revision:
1:acc66d3a1a1c
Parent:
0:87903e5535bc
Child:
2:b615682e3e4f
diff -r 87903e5535bc -r acc66d3a1a1c main.cpp
--- a/main.cpp	Thu Mar 22 13:29:18 2018 +0000
+++ b/main.cpp	Sun Apr 01 15:43:02 2018 +0000
@@ -1,10 +1,69 @@
-#include "mbed.h"
-
+#include "SPI.h"
 
 int main (void)
 {
-    while(1)
+    cs = 1;                     // Chip must be deselected, Chip Select is active LOW
+    LCD_cs = 1;                 // Chip must be deselected, Chip Select is active LOW
+    ADC_cs = 1;                 // Chip must be deselected, Chip Select is active LOW
+    spi.format(16,0);           // Setup the DATA frame SPI for 16 bit wide word, Clock Polarity 0 and Clock Phase 0 (0)
+    spi_cmd.format(8,0);        // Setup the COMMAND SPI as 8 Bit wide word, Clock Polarity 0 and Clock Phase 0 (0)
+    spi.frequency(1000000);     // 1MHz clock rate
+    spi_cmd.frequency(1000000); // 1MHz clock rate
+    
+    int adval_d = 0;            //A to D value read back
+    float adval_f =0.0f;
+    int err = 0;                //error variable used for debugging, trapping etc.,
+
+    char adval[32];
+    
+// Preload some arrays
+//    char hello_world[]="Hello World";
+    char splash_screen1[]="Martin Simpson";
+    char splash_screen2[]="Plymouth UNI";
+    char DVM[]="Voltage=";
+// Start up sequences
+    lcd_cls();
+    lcd_locate(1,1);
+    lcd_display(splash_screen1);    //Credit line 1
+    lcd_locate(2,2);
+    lcd_display(splash_screen2);    //Credit line 2
+    wait(2);
+    lcd_cls();
+    pulse_bar_graph(); //Flashy bargraph clear screen  
+    lcd_locate(1,0);
+    lcd_display(DVM);   //Type Voltage display
+    lcd_locate(1,13);
+    lcd_display("V");   //Units display
+   
+    while(true)                 //Loop forever Knight Rider Display on FPGA
     {
+        adval_d = read_adc();
         
+        adval_f = 3.3f*((float)adval_d/4095);//Convert 12 bit to a float and scale
+        sprintf(adval,"%.3f",adval_f);       //Store in an array string
+        lcd_locate(1,8);                     //and display on LCD
+        lcd_display(adval);                  //
+        
+        err = bar_graph(adval_d/255);       // 16*256 =4096 12 bit ADC!
+        if (err < 0){printf("Display Overload\r\n");}
+        
+        read_switches();
+        //LED Chaser display KIT lives on!
+        for (uint32_t i=1;i<=128;i*=2)
+        {
+            cs = 0;             //Select the device by seting chip select LOW
+            spi_cmd.write(0);
+            spi.write(i);
+            cs = 1;             //De-Select the device by seting chip select HIGH
+            wait_ms(20);
+        }
+        for (uint32_t i=128;i>=1;i/=2)
+        {
+            cs = 0;             //Select the device by seting chip select LOW
+            spi_cmd.write(0);
+            spi.write(i);
+            cs = 1;             //De-Select the device by seting chip select HIGH
+            wait_ms(20);
+        }
     }
 }