VFD command test program

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
kanpapa
Date:
Mon May 02 13:57:58 2016 +0000
Parent:
0:b2dddd322c12
Commit message:
test version

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
mbed.lib Show diff for this revision Revisions of this file
diff -r b2dddd322c12 -r 05518314979e main.cpp
--- a/main.cpp	Sun Oct 02 12:01:29 2011 +0000
+++ b/main.cpp	Mon May 02 13:57:58 2016 +0000
@@ -52,9 +52,10 @@
 #include "mbed.h"
 
 Serial pc(USBTX, USBRX);
+LocalFileSystem local("local");
 
 // VFD DATA PORT
-BusInOut DATA(p5, p6, p7, p8, p9, p10, p11, p12);
+BusOut DATA(p5, p6, p7, p8, p9, p10, p11, p12);
 //               __
 // Write Signal (WR)
 DigitalOut WR(p14);
@@ -72,94 +73,44 @@
 DigitalIn INT(p13);
 
 // LED Status
-DigitalOut led1(LED2);
-DigitalOut led2(LED3);
-DigitalOut led3(LED4);
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+DigitalOut led4(LED4);
+
 
 const uint8_t HIGH = 1;
 const uint8_t LOW = 0;
-
 const uint16_t MAX_ADDRESS = 0x01fff;
 
+FILE *fp;
+char in_filename[] = "/local/rom1.bin";
 
 void send_cmd(uint8_t cmd)
 {
-    // LED ON
-    led1 = HIGH;
-
-    // C/D SET HIGH
-    CD = HIGH;
-    wait_us(1);
-      
-    // CS SET LOW
-    CS = LOW;
-    wait_us(1);
-    
-    // WR SET LOW
-    WR = LOW;
-    wait_us(1);
-    
-    // COMMAND SET
-    DATA = cmd;
-    wait_us(1);
-
-    // WR SET HIGH
-    WR = HIGH;
-    wait_us(1);
-    
-    // CS SET HIGH
-    CS = HIGH;
-    wait_us(1);
-    
-    // LED OFF
-    led1 = LOW;
+    CD = HIGH;    // C/D SET HIGH      
+    DATA = cmd;   // COMMAND SET
+    CS = LOW;     // CS SET LOW
+    WR = LOW;     // WR SET LOW
+    wait_us(2);   // wait 2us
+    WR = HIGH;    // WR SET HIGH
+    CS = HIGH;    // CS SET HIGH
+    wait_us(4);   // wait 4us
 
     return;
 }
 
 void send_data(uint8_t data)
 {
-    // LED ON
-    led2 = HIGH;
-
-    // C/D SET HIGH
-    CD = LOW;
-    wait_us(1);
-      
-    // CS SET LOW
-    CS = LOW;
-    wait_us(1);
-    
-    // WR SET LOW
-    WR = LOW;
-    wait_us(1);
+    CD = LOW;      // C/D SET HIGH
+    DATA = data;   // DATA SET
+    CS = LOW;      // CS SET LOW
+    WR = LOW;      // WR SET LOW
+    wait_us(2);    // wait 2us
+    WR = HIGH;     // WR SET HIGH
+    CS = HIGH;     // CS SET HIGH
+    wait_us(4);    // wait 4us
     
-    // DATA SET
-    DATA = data;
-    wait_us(1);
-
-    // WR SET HIGH
-    WR = HIGH;
-    wait_us(1);
-    
-    // CS SET HIGH
-    CS = HIGH;
-    wait_us(1);
-    
-    // LED OFF
-    led2 = LOW;
-
-    return;
-}
-
-// Write/Read address is automatically incremented (00H)
-void cmd_00H(){
-    send_cmd(0);
-    return;
-}
-
-void cmd_01H(){
-    send_cmd(1);
     return;
 }
 
@@ -172,21 +123,15 @@
     return;
 }    
 
-// Data Write/Read(02H,03H);
-void write_display_data(uint8_t data){
-    send_cmd(2);    // 04H
-    send_data(data);
-
-    return;
-}
-
-// 04H,05H: Setting address of Write-Read 
+// 04H,05H,02H: Setting address of Write
 void set_write_read_address(uint16_t address){
     send_cmd(4);    // 04H: Setting lower address of Write-Read
-    send_data((uint8_t)(address && 0x0ff));    // mask upper address 
+    send_data((uint8_t)(address & 0x0ff));    // mask upper address 
     
     send_cmd(5);    // 05H: Setting upper address of Write-Read
-    send_data((uint8_t)(address >> 8));        // 8bit shift
+    send_data((uint8_t)(address >> 8));       // 8bit shift
+
+    send_cmd(2);    // 02H: Data Write
     
     return;
 }
@@ -194,7 +139,7 @@
 // 07H,08H: Setting address display started
 void set_disp_start_address(uint16_t address){
     send_cmd(7);    // 07H: Setting lower address display started
-    send_data((uint8_t)(address && 0x0ff));
+    send_data((uint8_t)(address & 0x0ff));
     
     send_cmd(8);    // 08H: Setting upper address display started
     send_data((uint8_t)(address >> 8));
@@ -204,29 +149,84 @@
 
 // TEST PATTERN
 void test_pattern(){
-    uint8_t d = 0;
+    led1 = 1;
+    set_disp_start_address(0);  // Display address: 000000H
+    led1 = 0;
     
-    //cmd_00H();      // Write/Read address is automatically incremented
-
-    luminance_adjustment(8);    // 51.9%
+    led2 = 1;
+    luminance_adjustment(0x0f);    // 100%
+    led2 = 0;
     
-    set_write_read_address(0);  // Start address: 000000H
-    
-    set_disp_start_address(0);  // Display address: 000000H
+    for (uint16_t d = 0; d < 256 ; d++){
+        led3 = 1;
+        set_write_read_address(0);  // Start address: 000000H
+        led3 = 0;
     
-    for (uint16_t i = 0; i < MAX_ADDRESS; i++){
-        write_display_data(d++);
-        if (d > 255) { d = 0; }
+        for (uint16_t i = 0; i < MAX_ADDRESS; i++){
+            led4 = 1;
+            send_data(d);
+            led4 = 0;
+        }
     }
     
     return;        
 }
 
+void test_datafile(){
+    if ( NULL == (fp = fopen( in_filename, "r" )) ) {
+        pc.printf("File open error.\n");
+        led1 = HIGH;
+        return;
+    }
+
+    led1 = 1;
+    set_disp_start_address(0);  // Display address: 000000H
+    led1 = 0;
+    
+    led2 = 1;
+    luminance_adjustment(0x0f); // 100%
+    led2 = 0;
+    
+    led3 = 1;
+    set_write_read_address(0);  // Start address: 000000H
+    led3 = 0;
+    
+    char d[8];  // 1char 8byte buffer
+    int char_cnt = 0;
+    
+    // 8byte = 1CHAR
+    while(fgets(d, 8, fp) != NULL && char_cnt < 10) {
+        for (int byte_num = 0; byte_num < 8 ; byte_num++){ // byte
+            pc.printf("d[%d]:%02x ",byte_num,d[byte_num]);
+            uint8_t a = 0;
+            for (int bit_num = 7; bit_num >= 0; bit_num--){ // bit
+                if ((d[byte_num] & 0x80) != 0) {
+                    a = a + (2 ^ bit_num);
+                }
+                d[byte_num] = d[byte_num] << 1;
+                pc.printf("a:%02x d:%02x ",a,d[byte_num]);
+            }
+            if ((d[byte_num] & 0x80) != 0) a++;
+            
+            led4 = 1;
+            pc.printf("A:%02x ",a);
+            send_data(a);
+            led4 = 0;
+
+            for (int e = 0; e < 7 ; e++) send_data(0);
+        }
+        char_cnt++;
+    }
+    fclose(fp);
+
+    return;        
+}
+
 void blink_LED() {
-    for (int i = 0 ; i < 10 ; i++) {
-        led3 = 1;
+    for (int i = 0 ; i < 5 ; i++) {
+        led4 = 1;
         wait(0.2);
-        led3 = 0;
+        led4 = 0;
         wait(0.2);
     }
     return;
@@ -237,6 +237,7 @@
     led1 = LOW;
     led2 = LOW;
     led3 = LOW;
+    led4 = LOW;
     
     CS = HIGH;
     WR = HIGH;
@@ -247,7 +248,9 @@
     blink_LED();
     
     // TEST
-    test_pattern();
+    //test_pattern();
+    
+    test_datafile();
     
     // END Sign
     blink_LED();    
diff -r b2dddd322c12 -r 05518314979e mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon May 02 13:57:58 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912
\ No newline at end of file
diff -r b2dddd322c12 -r 05518314979e mbed.lib
--- a/mbed.lib	Sun Oct 02 12:01:29 2011 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/projects/libraries/svn/mbed/trunk@28
\ No newline at end of file