AD-12864-SPI class

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers spilcd.h Source File

spilcd.h

00001 // AD-12684-SPI control class
00002 // version 0.1
00003 // created by Sim (http://mbed.org/users/Sim/)
00004 //
00005 // About AD-12864-SPI, see http://www.aitendo.co.jp/product/1622 .
00006 
00007 #ifndef __SPILCD_H__
00008 #define __SPILCD_H__
00009 
00010 #include "mbed.h"
00011 
00012 class SPILCD {
00013 private:
00014     DigitalOut cs, rst, a0;
00015     SPI spi;
00016 
00017     // boot up sequence
00018     void init(){
00019         spi.format(8,0); // nazo
00020         spi.frequency(20000000); // modify later
00021         
00022         // reset
00023         wait_ms(200);
00024         rst = 0;
00025         wait_ms(200);
00026         rst = 1;
00027     
00028         // initialize sequence
00029         regwrite(0xaf);    // display on (see 2.4.1)
00030         regwrite(0x2f);    // power control set (see 2.4.16)
00031         regwrite(0x81);    // set electronic volume mode (see 2.4.18)
00032 //        regwrite(0x1f);    // electronic volume data 00-3f
00033         regwrite(0x00);    // electronic volume data 00-3f ... control your own value
00034         regwrite(0x27);    // V5 Volatge Regulator Internal Resister Ratio Set (see 2.4.17)
00035         regwrite(0xa2);    // LCD Bias Set ... 1/9 bias (see 2.4.11)
00036         regwrite(0xc8);    // Common Output Mode Select ... Reverse (see 2.4.15)
00037         regwrite(0xa0);    // ADC Select ... Normal (see 2.4.8)
00038         regwrite(0xa4);    // Display All Points ON/OFF ... normal (see 2.4.10)
00039         regwrite(0xa6);    // Display Normal/Reverse ... normal (see 2.4.9)
00040         regwrite(0xac);    // Static Indicator ... off (see 2.4.19)
00041         regwrite(0x00);    // off
00042         regwrite(0x40);    // Display Strat Line Set ... 0 (see 2.4.2)
00043         regwrite(0xe0);    // Write Mode Set
00044     }
00045 
00046     // write command
00047     void regwrite(unsigned char c){
00048         cs = a0 = 0;
00049         spi.write(c);
00050         cs = 1;
00051     }
00052     
00053 public:
00054 
00055     // constructor
00056     SPILCD(PinName cs_pin, PinName rst_pin, PinName a0_pin, PinName mosi_pin, PinName miso_pin, PinName sclk_pin)
00057         : cs(cs_pin), rst(rst_pin), a0(a0_pin), spi(mosi_pin, miso_pin, sclk_pin) {
00058         
00059         init();
00060         cls();
00061     }
00062 
00063     // wipe all screen
00064     void cls(void){
00065         int x, y;
00066         for(y = 0; y < 8; y++){
00067             locate(0, y);
00068             for(x = 0; x < 128; x++) write(0x00);
00069         }
00070     }
00071 
00072     // move position to (x, 8 * y)
00073     void locate(int x, int y){
00074         regwrite(0xb0 | (y & 0x0f)); // Page Address Set (see 2.4.3)
00075         regwrite(0x10 | (x >> 4 & 0x0f)); // Column Address Set (see 2.4.4)
00076         regwrite(x & 0x0f);
00077     }
00078 
00079     // write data
00080     void write(unsigned char c){
00081         cs = 0;
00082         a0 = 1;
00083         spi.write(c);
00084         cs = 1;
00085     }
00086 
00087 };
00088 
00089 #endif