Toyomasa Watarai / Mbed 2 deprecated GT20L16J1Y_example

Dependencies:   C12832_lcd mbed

Fork of app-board-LCD by Chris Styles

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "C12832_lcd.h"
00003 
00004 unsigned char matrixdata[32];
00005 C12832_LCD lcd;
00006 
00007 void read_font(unsigned short code) {
00008     SPI spi(p11, p12, p13); // mosi, miso, sclk
00009     DigitalOut cs(p10);
00010     unsigned char  c1, c2, MSB,LSB;
00011     uint32_t Address, seq;
00012 
00013     // SJIS to kuten code conversion
00014     c1 = (code>>8);
00015     c2 = (code & 0xFF);
00016     seq = (c1<=159 ? c1-129 : c1-193)*188 + (c2<=126 ? c2-64 : c2-65);
00017     MSB = seq / 94 + 1;
00018     LSB = seq % 94 + 1;
00019     Address = 0;
00020         
00021     if(     MSB >=  1 && MSB <= 15 && LSB >= 1 && LSB <= 94)
00022         Address =( (MSB -  1) * 94 + (LSB - 1))*32;
00023     else if(MSB >= 16 && MSB <= 47 && LSB >= 1 && LSB <= 94)
00024         Address =( (MSB - 16) * 94 + (LSB - 1))*32 + 0x0AA40L;
00025     else if(MSB >= 48 && MSB <= 84 && LSB >= 1 && LSB <= 94)
00026         Address = ((MSB - 48) * 94 + (LSB - 1))*32 + 0x21CDFL;
00027     else if(MSB == 85 &&                LSB >= 1 && LSB <= 94)
00028         Address = ((MSB - 85) * 94 + (LSB - 1))*32 + 0x3C4A0L;
00029     else if(MSB >= 88 && MSB <= 89 && LSB >= 1 && LSB <= 94)
00030         Address = ((MSB - 88) * 94 + (LSB - 1))*32 + 0x3D060L;
00031     
00032     // Deselect the device
00033     cs = 1;
00034 
00035     // Setup the spi for 8 bit data, high steady state clock
00036     spi.format(8,3);
00037     spi.frequency(1000000); 
00038     
00039     // Select the device by seting chip select low
00040     cs = 0;
00041     spi.write(0x03);    // Read data byte
00042     spi.write(Address>>16 & 0xff);
00043     spi.write(Address>>8 & 0xff);
00044     spi.write(Address & 0xff);
00045     
00046     // Send a dummy byte to receive the contents of the WHOAMI register
00047     for(int i=0; i<32; i++)
00048     {
00049       matrixdata[i]=spi.write(0x00);
00050     }
00051 
00052     // Deselect the device
00053     cs = 1;
00054 }
00055 
00056 
00057 void draw_kanji(int offset_x, int offset_y)
00058 {
00059     int color;
00060     for(int x=0; x<32; x++)
00061     {
00062         for(int y=0; y<8; y++)
00063         {
00064         if (matrixdata[x] & (1<<y))
00065             color = 1;
00066         else
00067             color = 0;
00068         lcd.pixel(x%16 + offset_x, y+(8*(x>>4)) + offset_y, color);
00069         }
00070     }
00071     lcd.copy_to_lcd();
00072 }
00073 
00074 int main()
00075 {
00076     unsigned short kbuf[16] = {0x93fa, 0x967b, 0x8cea, 0x955c, 0x8ea6};
00077 
00078     lcd.cls();
00079 
00080     for(int i=0; i<5; i++) {
00081         read_font(kbuf[i]); 
00082         draw_kanji(16*i, 0);
00083     }
00084     
00085 }