Dependencies:   mbed

Revision:
0:f2ec16cdf989
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Dec 02 14:55:59 2009 +0000
@@ -0,0 +1,120 @@
+// AD-12864-SPI test program
+// About AD-12864-SPI, see http://www.aitendo.co.jp/product/1622.
+
+// Pin allocation
+// 1 p21 #CS1 with 10k ohm pull-up
+// 2 p22 #RESET with 10k ohm pull-up
+// 3 p23 A0 ... 0:command 1:data
+// 4 p13 SCK
+// 5 p11 MOSI
+// 6     Vdd
+// 7     Vss
+// 8 NC  LED_A 
+
+#include "mbed.h"
+#include "font8.h"
+
+DigitalOut cs(p21);
+DigitalOut rst(p22);
+DigitalOut a0(p23);
+SPI spi(p11, p12, p13); // mosi, miso, sclk
+
+void regwrite(unsigned char c){
+    cs = a0 = 0;
+    spi.write(c);
+    cs = 1;
+}
+
+void datawrite(unsigned char c){
+    cs = 0;
+    a0 = 1;
+    spi.write(c);
+    cs = 1;
+}
+
+// set position (x, 8*y)
+void locate(int x, int y){
+    regwrite(0xb0 | (y & 0x0f)); // Page Address Set (see 2.4.3)
+    regwrite(0x10 | (x >> 4 & 0x0f)); // Column Address Set (see 2.4.4)
+    regwrite(x & 0x0f);
+}
+
+void cls(void){
+    int x, y;
+    for(y = 0; y < 8; y++){
+        locate(0, y);
+        for(x = 0; x < 128; x++) datawrite(0x00);
+    }
+}
+
+void plot(int x, int y){
+    locate(x, y >> 3);
+    datawrite(1 << (y & 7));
+}
+
+void init(){
+    spi.format(8,0); // nazo
+    spi.frequency(10000000); // modify later
+    
+    // reset
+    wait_ms(200);
+    rst = 0;
+    wait_ms(200);
+    rst = 1;
+
+    // initialize sequence
+    regwrite(0xaf);    // display on (see 2.4.1)
+    regwrite(0x2f);    // power control set (see 2.4.16)
+    regwrite(0x81);    // set electronic volume mode (see 2.4.18)
+//    regwrite(0x1f);    // electronic volume data 00-3f
+    regwrite(0x00);    // electronic volume data 00-3f
+    regwrite(0x27);    // V5 Volatge Regulator Internal Resister Ratio Set (see 2.4.17)
+    regwrite(0xa2);    // LCD Bias Set ... 1/9 bias (see 2.4.11)
+    regwrite(0xc8);    // Common Output Mode Select ... Reverse (see 2.4.15)
+    regwrite(0xa0);    // ADC Select ... Normal (see 2.4.8)
+    regwrite(0xa4);    // Display All Points ON/OFF ... normal (see 2.4.10)
+    regwrite(0xa6);    // Display Normal/Reverse ... normal (see 2.4.9)
+    regwrite(0xac);    // Static Indicator ... off (see 2.4.19)
+    regwrite(0x00);    // off
+    regwrite(0x40);    // Display Strat Line Set ... 0 (see 2.4.2)
+    regwrite(0xe0);    // Write Mode Set
+}
+
+void drawchar(unsigned char c){
+    const unsigned char *p = &font8[c << 3];
+    datawrite(p[0]);
+    datawrite(p[1]);
+    datawrite(p[2]);
+    datawrite(p[3]);
+    datawrite(p[4]);
+    datawrite(p[5]);
+    datawrite(p[6]);
+    datawrite(p[7]);
+}
+
+void drawtext(const char *s){
+    unsigned char c;
+    while((c = *s++) != '\0') drawchar(c);
+}
+
+int main() {
+    int x, y, c;
+    char buf[16];
+    
+    init();
+    cls();
+
+    locate(0, 0);
+    sprintf(buf, "%08x", 0xdeadbeef);
+    drawtext(buf);
+    wait_ms(2000);
+
+    c = 0;
+    while(1) {
+        for(y = 0; y < 8; y++){
+            locate(0, y);
+            for(x = 0; x < 16; x++) drawchar(c++);
+        }
+        wait_ms(800);
+    }
+}