GroupA / Mbed 2 deprecated Lab_6_WaG

Dependencies:   mbed

Fork of WaG by GroupA

Revision:
11:6751b9406142
Parent:
10:ae0a262ba48d
Child:
12:a947a6609a23
--- a/display.cpp	Thu Feb 22 16:22:19 2018 +0000
+++ b/display.cpp	Fri Feb 23 23:05:58 2018 +0000
@@ -18,8 +18,8 @@
 #include <stdio.h>
 #include <string.h>
 
-#define VERSION1
-//#define VERSION2
+//#define VERSION1
+#define VERSION2
 
 
 /*
@@ -153,32 +153,40 @@
 */
 void bin2bcd_array(int num, char bcd[]) {
     char tmp_array[4];
-    sprintf(tmp_array, "%d", num);
-    
+    char reverse_bcd[4];
+    int last_index = 0;
     int i = 0;
-    while (tmp_array[i] != '\0') {
-        bcd[3 - i] = tmp_array[i];
-        i++;    
+    
+    sprintf(tmp_array, "%d", num);
+    for (i = 0; i < 4; i++) {
+        bcd[i] = 0;
+        reverse_bcd[i] = 0;
+    }
+    
+    while (last_index < 4 and tmp_array[last_index] != '\0') {
+        reverse_bcd[last_index] = tmp_array[last_index] - '0';   
+        last_index++;    
+    }
+    
+    // reverse the order to fit binary coded decimal
+    for (i = 0; i < last_index; i++) {
+        bcd[i] = reverse_bcd[last_index - 1 - i];
     }
 }
 #endif
 
-
-/*
- * char to_command(char input, int place);
- * Description: 
- *
- * Inputs: 
- *      Parameters:
- *          char input:
- *          int place: 
- *      Globals:
- *      
- * Outputs:
- *      Parameters:
- *      Globals:
- *      Returns: char
-*/
-char to_command(char input, int place) {
-    return 'a';
+void send_command_to_display(char bcd[]) {
+    int command;
+    
+    
+    for (int i = 1; i <= 4; i++) {
+        command = 0;
+        // command has following form: 0x0[place]0[value]
+        // the value converted to int is 16 * 16 * place + value
+        command = 16 * 16 * i + bcd[i - 1]; 
+        
+        SS = 0;
+        spi.write(command);
+        SS = 1;
+    }
 }
\ No newline at end of file