VFD command test program

Dependencies:   mbed

Revision:
0:b2dddd322c12
Child:
1:05518314979e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Oct 02 12:01:29 2011 +0000
@@ -0,0 +1,254 @@
+/*
+
+mbed VFD Control for GP1059A01
+
+===============
+Status LED
+-----------
+LED1: 
+LED2: 
+LED3: 
+LED4: 
+
+===============
+GP1059A01 INTERFACE CONNECTION
+---------------
+1  D0   2  D1
+3  D2   4  D3
+5  D4   6  D5
+7  D6   8  D7
+9  GND  10 INT
+11 WR   12 RD
+13 CS   14 C/D
+15 5V   16 5V
+17 5V   18 GND
+19 GND  20 ebb(+70V)
+
+
+
+=====================
+mbed CONNECTION
+---------------------
+mbed   GP1059A01(I/O)
+---------------------
+p5     1 (D0)  I/O
+p6     2 (D1)  I/O
+p7     3 (D2)  I/O
+p8     4 (D3)  I/O
+p9     5 (D4)  I/O
+p10    6 (D5)  I/O
+p11    7 (D6)  I/O
+p12    8 (D7)  I/O
+p13    10 (INT) O
+p14    11 (WR)  I
+p15    12 (RD)  I
+p16    13 (CS)  I
+p17    14 (C/D) I
+GND    9,18,19 (GND)
+=====================
+
+*/
+
+#include "mbed.h"
+
+Serial pc(USBTX, USBRX);
+
+// VFD DATA PORT
+BusInOut DATA(p5, p6, p7, p8, p9, p10, p11, p12);
+//               __
+// Write Signal (WR)
+DigitalOut WR(p14);
+//              __
+// Read Signal (RD)
+DigitalOut RD(p15);
+//                     __
+// Chip Select Signal (CS)
+DigitalOut CS(p16);
+//                                 _
+// Command / Data Select Signal (C/D)
+DigitalOut CD(p17);
+//
+// Frame Signal
+DigitalIn INT(p13);
+
+// LED Status
+DigitalOut led1(LED2);
+DigitalOut led2(LED3);
+DigitalOut led3(LED4);
+
+const uint8_t HIGH = 1;
+const uint8_t LOW = 0;
+
+const uint16_t MAX_ADDRESS = 0x01fff;
+
+
+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;
+
+    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);
+    
+    // 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;
+}
+
+// Luminance Adjustment (06H)
+void luminance_adjustment(uint8_t data)
+{
+    send_cmd(6);
+    send_data(data);
+
+    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 
+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_cmd(5);    // 05H: Setting upper address of Write-Read
+    send_data((uint8_t)(address >> 8));        // 8bit shift
+    
+    return;
+}
+
+// 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_cmd(8);    // 08H: Setting upper address display started
+    send_data((uint8_t)(address >> 8));
+    
+    return;
+}
+
+// TEST PATTERN
+void test_pattern(){
+    uint8_t d = 0;
+    
+    //cmd_00H();      // Write/Read address is automatically incremented
+
+    luminance_adjustment(8);    // 51.9%
+    
+    set_write_read_address(0);  // Start address: 000000H
+    
+    set_disp_start_address(0);  // Display address: 000000H
+    
+    for (uint16_t i = 0; i < MAX_ADDRESS; i++){
+        write_display_data(d++);
+        if (d > 255) { d = 0; }
+    }
+    
+    return;        
+}
+
+void blink_LED() {
+    for (int i = 0 ; i < 10 ; i++) {
+        led3 = 1;
+        wait(0.2);
+        led3 = 0;
+        wait(0.2);
+    }
+    return;
+}
+
+int main() {
+
+    led1 = LOW;
+    led2 = LOW;
+    led3 = LOW;
+    
+    CS = HIGH;
+    WR = HIGH;
+    RD = HIGH;
+    CD = HIGH;
+    
+    // Start Sign
+    blink_LED();
+    
+    // TEST
+    test_pattern();
+    
+    // END Sign
+    blink_LED();    
+}
\ No newline at end of file