FontTest3
Published 06 Dec 2009, by
Sim mbed

No tags
« Back to documentation index
Show/hide line numbers
spilcd.h Source File
spilcd.h
00001
00002
00003
00004
00005
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
00018 void init(){
00019 spi.format(8,0);
00020 spi.frequency(20000000);
00021
00022
00023 wait_ms(10);
00024 rst = 0;
00025 wait_us(1);
00026 rst = 1;
00027 wait_us(1);
00028
00029
00030 cmd(0xa2);
00031 cmd(0xa0);
00032 cmd(0xc8);
00033 cmd(0x24);
00034 cmd(0x81);
00035 cmd(0x1e);
00036 cmd(0x2f);
00037 cmd(0x40);
00038 cmd(0xe0);
00039 cmd(0xaf);
00040 }
00041
00042 public:
00043
00044
00045 SPILCD(PinName cs_pin, PinName rst_pin, PinName a0_pin, PinName mosi_pin, PinName miso_pin, PinName sclk_pin)
00046 : cs(cs_pin), rst(rst_pin), a0(a0_pin), spi(mosi_pin, miso_pin, sclk_pin) {
00047
00048 init();
00049 cls();
00050 }
00051
00052
00053 void cls(void){
00054 int x, y;
00055 for(y = 0; y < 8; y++){
00056 moveto(0, y);
00057 for(x = 0; x < 128; x++) write(0x00);
00058 }
00059 moveto(0, 0);
00060 }
00061
00062
00063 void moveto(int x, int y){
00064 cmd(0xb0 | (y & 0x0f));
00065 cmd(0x10 | (x >> 4 & 0x0f));
00066 cmd(x & 0x0f);
00067 }
00068
00069
00070 void cmd(unsigned char c){
00071 cs = a0 = 0;
00072 spi.write(c);
00073 cs = 1;
00074 }
00075
00076
00077 void write(unsigned char c){
00078 cs = 0;
00079 a0 = 1;
00080 spi.write(c);
00081 cs = 1;
00082 }
00083 };
00084
00085 #endif