Dependencies:   mbed

Committer:
Sim
Date:
Tue Dec 01 08:04:17 2009 +0000
Revision:
0:898fb821307d

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Sim 0:898fb821307d 1 // AD-12864-SPI test program
Sim 0:898fb821307d 2 // About AD-12864-SPI, see http://www.aitendo.co.jp/product/1622.
Sim 0:898fb821307d 3
Sim 0:898fb821307d 4 // Pin allocation
Sim 0:898fb821307d 5 // 1 p21 #CS1 with 10k ohm pull-up
Sim 0:898fb821307d 6 // 2 p22 #RESET with 10k ohm pull-up
Sim 0:898fb821307d 7 // 3 p23 A0 ... 0:command 1:data
Sim 0:898fb821307d 8 // 4 p13 SCK
Sim 0:898fb821307d 9 // 5 p11 MOSI
Sim 0:898fb821307d 10 // 6 Vdd
Sim 0:898fb821307d 11 // 7 Vss
Sim 0:898fb821307d 12 // 8 NC LED_A
Sim 0:898fb821307d 13
Sim 0:898fb821307d 14 #include "mbed.h"
Sim 0:898fb821307d 15
Sim 0:898fb821307d 16 DigitalOut cs(p21);
Sim 0:898fb821307d 17 DigitalOut rst(p22);
Sim 0:898fb821307d 18 DigitalOut a0(p23);
Sim 0:898fb821307d 19 SPI spi(p11, p12, p13); // mosi, miso, sclk
Sim 0:898fb821307d 20
Sim 0:898fb821307d 21 void regwrite(unsigned char c){
Sim 0:898fb821307d 22 cs = a0 = 0;
Sim 0:898fb821307d 23 spi.write(c);
Sim 0:898fb821307d 24 cs = 1;
Sim 0:898fb821307d 25 }
Sim 0:898fb821307d 26
Sim 0:898fb821307d 27 void datawrite(unsigned char c){
Sim 0:898fb821307d 28 cs = 0;
Sim 0:898fb821307d 29 a0 = 1;
Sim 0:898fb821307d 30 spi.write(c);
Sim 0:898fb821307d 31 cs = 1;
Sim 0:898fb821307d 32 }
Sim 0:898fb821307d 33
Sim 0:898fb821307d 34 // set position (x, 8*y)
Sim 0:898fb821307d 35 void locate(int x, int y){
Sim 0:898fb821307d 36 regwrite(0xb0 | (y & 0x0f)); // Page Address Set (see 2.4.3)
Sim 0:898fb821307d 37 regwrite(0x10 | (x >> 4 & 0x0f)); // Column Address Set (see 2.4.4)
Sim 0:898fb821307d 38 regwrite(x & 0x0f);
Sim 0:898fb821307d 39 }
Sim 0:898fb821307d 40
Sim 0:898fb821307d 41 void cls(void){
Sim 0:898fb821307d 42 int x, y;
Sim 0:898fb821307d 43 for(y = 0; y < 8; y++){
Sim 0:898fb821307d 44 locate(0, y);
Sim 0:898fb821307d 45 for(x = 0; x < 128; x++) datawrite(0x00);
Sim 0:898fb821307d 46 }
Sim 0:898fb821307d 47 }
Sim 0:898fb821307d 48
Sim 0:898fb821307d 49 void plot(int x, int y){
Sim 0:898fb821307d 50 locate(x, y >> 3);
Sim 0:898fb821307d 51 datawrite(1 << (y & 7));
Sim 0:898fb821307d 52 }
Sim 0:898fb821307d 53
Sim 0:898fb821307d 54 void init(){
Sim 0:898fb821307d 55 spi.format(8,0); // nazo
Sim 0:898fb821307d 56 spi.frequency(20000000); // modify later
Sim 0:898fb821307d 57
Sim 0:898fb821307d 58 // reset
Sim 0:898fb821307d 59 wait_ms(200);
Sim 0:898fb821307d 60 rst = 0;
Sim 0:898fb821307d 61 wait_ms(200);
Sim 0:898fb821307d 62 rst = 1;
Sim 0:898fb821307d 63
Sim 0:898fb821307d 64 // initialize sequence
Sim 0:898fb821307d 65 regwrite(0xaf); // display on (see 2.4.1)
Sim 0:898fb821307d 66 regwrite(0x2f); // power control set (see 2.4.16)
Sim 0:898fb821307d 67 regwrite(0x81); // set electronic volume mode (see 2.4.18)
Sim 0:898fb821307d 68 // regwrite(0x1f); // electronic volume data 00-3f
Sim 0:898fb821307d 69 regwrite(0x00); // electronic volume data 00-3f
Sim 0:898fb821307d 70 regwrite(0x27); // V5 Volatge Regulator Internal Resister Ratio Set (see 2.4.17)
Sim 0:898fb821307d 71 regwrite(0xa2); // LCD Bias Set ... 1/9 bias (see 2.4.11)
Sim 0:898fb821307d 72 regwrite(0xc8); // Common Output Mode Select ... Reverse (see 2.4.15)
Sim 0:898fb821307d 73 regwrite(0xa0); // ADC Select ... Normal (see 2.4.8)
Sim 0:898fb821307d 74 regwrite(0xa4); // Display All Points ON/OFF ... normal (see 2.4.10)
Sim 0:898fb821307d 75 regwrite(0xa6); // Display Normal/Reverse ... normal (see 2.4.9)
Sim 0:898fb821307d 76 regwrite(0xac); // Static Indicator ... off (see 2.4.19)
Sim 0:898fb821307d 77 regwrite(0x00); // off
Sim 0:898fb821307d 78 regwrite(0x40); // Display Strat Line Set ... 0 (see 2.4.2)
Sim 0:898fb821307d 79 regwrite(0xe0); // Write Mode Set
Sim 0:898fb821307d 80 }
Sim 0:898fb821307d 81
Sim 0:898fb821307d 82 DigitalOut myled(LED1);
Sim 0:898fb821307d 83
Sim 0:898fb821307d 84 int main() {
Sim 0:898fb821307d 85 int i;
Sim 0:898fb821307d 86
Sim 0:898fb821307d 87 init();
Sim 0:898fb821307d 88
Sim 0:898fb821307d 89 cls();
Sim 0:898fb821307d 90 locate(0, 0);
Sim 0:898fb821307d 91 for(i = 0; i < 256; i++) datawrite(i);
Sim 0:898fb821307d 92
Sim 0:898fb821307d 93 for(i = 0; i < 64; i++){
Sim 0:898fb821307d 94 plot(64 + i, 0);
Sim 0:898fb821307d 95 plot(64 + i, 63);
Sim 0:898fb821307d 96 }
Sim 0:898fb821307d 97
Sim 0:898fb821307d 98 for(i = 0; i < 8; i++){
Sim 0:898fb821307d 99 locate(64, i);
Sim 0:898fb821307d 100 datawrite(0xff);
Sim 0:898fb821307d 101 locate(127,i);
Sim 0:898fb821307d 102 datawrite(0xff);
Sim 0:898fb821307d 103 }
Sim 0:898fb821307d 104
Sim 0:898fb821307d 105 for(i = 0; i < 64; i++) plot(i, i);
Sim 0:898fb821307d 106
Sim 0:898fb821307d 107 while(1) {
Sim 0:898fb821307d 108 myled = 1;
Sim 0:898fb821307d 109 wait_ms(200);
Sim 0:898fb821307d 110 myled = 0;
Sim 0:898fb821307d 111 wait_ms(200);
Sim 0:898fb821307d 112 }
Sim 0:898fb821307d 113 }