An example of GT20L16J1Y (15x16 Japanese Kanji ROM) and C12823 LCD
Fork of app-board-LCD by
main.cpp@3:c426b4b6d888, 2013-07-10 (annotated)
- Committer:
- MACRUM
- Date:
- Wed Jul 10 09:38:03 2013 +0000
- Revision:
- 3:c426b4b6d888
- Parent:
- 2:a87e255a8f3a
An example of GT20L16J1Y (15x16 Japanese Kanji ROM) and C12832 LCD.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dreschpe | 0:f6a57b843f79 | 1 | #include "mbed.h" |
dreschpe | 1:1c6a9eaf55b5 | 2 | #include "C12832_lcd.h" |
dreschpe | 0:f6a57b843f79 | 3 | |
MACRUM | 3:c426b4b6d888 | 4 | unsigned char matrixdata[32]; |
chris | 2:a87e255a8f3a | 5 | C12832_LCD lcd; |
dreschpe | 1:1c6a9eaf55b5 | 6 | |
MACRUM | 3:c426b4b6d888 | 7 | void read_font(unsigned short code) { |
MACRUM | 3:c426b4b6d888 | 8 | SPI spi(p11, p12, p13); // mosi, miso, sclk |
MACRUM | 3:c426b4b6d888 | 9 | DigitalOut cs(p10); |
MACRUM | 3:c426b4b6d888 | 10 | unsigned char c1, c2, MSB,LSB; |
MACRUM | 3:c426b4b6d888 | 11 | uint32_t Address, seq; |
MACRUM | 3:c426b4b6d888 | 12 | |
MACRUM | 3:c426b4b6d888 | 13 | // SJIS to kuten code conversion |
MACRUM | 3:c426b4b6d888 | 14 | c1 = (code>>8); |
MACRUM | 3:c426b4b6d888 | 15 | c2 = (code & 0xFF); |
MACRUM | 3:c426b4b6d888 | 16 | seq = (c1<=159 ? c1-129 : c1-193)*188 + (c2<=126 ? c2-64 : c2-65); |
MACRUM | 3:c426b4b6d888 | 17 | MSB = seq / 94 + 1; |
MACRUM | 3:c426b4b6d888 | 18 | LSB = seq % 94 + 1; |
MACRUM | 3:c426b4b6d888 | 19 | Address = 0; |
MACRUM | 3:c426b4b6d888 | 20 | |
MACRUM | 3:c426b4b6d888 | 21 | if( MSB >= 1 && MSB <= 15 && LSB >= 1 && LSB <= 94) |
MACRUM | 3:c426b4b6d888 | 22 | Address =( (MSB - 1) * 94 + (LSB - 1))*32; |
MACRUM | 3:c426b4b6d888 | 23 | else if(MSB >= 16 && MSB <= 47 && LSB >= 1 && LSB <= 94) |
MACRUM | 3:c426b4b6d888 | 24 | Address =( (MSB - 16) * 94 + (LSB - 1))*32 + 0x0AA40L; |
MACRUM | 3:c426b4b6d888 | 25 | else if(MSB >= 48 && MSB <= 84 && LSB >= 1 && LSB <= 94) |
MACRUM | 3:c426b4b6d888 | 26 | Address = ((MSB - 48) * 94 + (LSB - 1))*32 + 0x21CDFL; |
MACRUM | 3:c426b4b6d888 | 27 | else if(MSB == 85 && LSB >= 1 && LSB <= 94) |
MACRUM | 3:c426b4b6d888 | 28 | Address = ((MSB - 85) * 94 + (LSB - 1))*32 + 0x3C4A0L; |
MACRUM | 3:c426b4b6d888 | 29 | else if(MSB >= 88 && MSB <= 89 && LSB >= 1 && LSB <= 94) |
MACRUM | 3:c426b4b6d888 | 30 | Address = ((MSB - 88) * 94 + (LSB - 1))*32 + 0x3D060L; |
MACRUM | 3:c426b4b6d888 | 31 | |
MACRUM | 3:c426b4b6d888 | 32 | // Deselect the device |
MACRUM | 3:c426b4b6d888 | 33 | cs = 1; |
MACRUM | 3:c426b4b6d888 | 34 | |
MACRUM | 3:c426b4b6d888 | 35 | // Setup the spi for 8 bit data, high steady state clock |
MACRUM | 3:c426b4b6d888 | 36 | spi.format(8,3); |
MACRUM | 3:c426b4b6d888 | 37 | spi.frequency(1000000); |
MACRUM | 3:c426b4b6d888 | 38 | |
MACRUM | 3:c426b4b6d888 | 39 | // Select the device by seting chip select low |
MACRUM | 3:c426b4b6d888 | 40 | cs = 0; |
MACRUM | 3:c426b4b6d888 | 41 | spi.write(0x03); // Read data byte |
MACRUM | 3:c426b4b6d888 | 42 | spi.write(Address>>16 & 0xff); |
MACRUM | 3:c426b4b6d888 | 43 | spi.write(Address>>8 & 0xff); |
MACRUM | 3:c426b4b6d888 | 44 | spi.write(Address & 0xff); |
MACRUM | 3:c426b4b6d888 | 45 | |
MACRUM | 3:c426b4b6d888 | 46 | // Send a dummy byte to receive the contents of the WHOAMI register |
MACRUM | 3:c426b4b6d888 | 47 | for(int i=0; i<32; i++) |
MACRUM | 3:c426b4b6d888 | 48 | { |
MACRUM | 3:c426b4b6d888 | 49 | matrixdata[i]=spi.write(0x00); |
MACRUM | 3:c426b4b6d888 | 50 | } |
MACRUM | 3:c426b4b6d888 | 51 | |
MACRUM | 3:c426b4b6d888 | 52 | // Deselect the device |
MACRUM | 3:c426b4b6d888 | 53 | cs = 1; |
MACRUM | 3:c426b4b6d888 | 54 | } |
MACRUM | 3:c426b4b6d888 | 55 | |
MACRUM | 3:c426b4b6d888 | 56 | |
MACRUM | 3:c426b4b6d888 | 57 | void draw_kanji(int offset_x, int offset_y) |
MACRUM | 3:c426b4b6d888 | 58 | { |
MACRUM | 3:c426b4b6d888 | 59 | int color; |
MACRUM | 3:c426b4b6d888 | 60 | for(int x=0; x<32; x++) |
MACRUM | 3:c426b4b6d888 | 61 | { |
MACRUM | 3:c426b4b6d888 | 62 | for(int y=0; y<8; y++) |
MACRUM | 3:c426b4b6d888 | 63 | { |
MACRUM | 3:c426b4b6d888 | 64 | if (matrixdata[x] & (1<<y)) |
MACRUM | 3:c426b4b6d888 | 65 | color = 1; |
MACRUM | 3:c426b4b6d888 | 66 | else |
MACRUM | 3:c426b4b6d888 | 67 | color = 0; |
MACRUM | 3:c426b4b6d888 | 68 | lcd.pixel(x%16 + offset_x, y+(8*(x>>4)) + offset_y, color); |
MACRUM | 3:c426b4b6d888 | 69 | } |
MACRUM | 3:c426b4b6d888 | 70 | } |
MACRUM | 3:c426b4b6d888 | 71 | lcd.copy_to_lcd(); |
MACRUM | 3:c426b4b6d888 | 72 | } |
MACRUM | 3:c426b4b6d888 | 73 | |
dreschpe | 0:f6a57b843f79 | 74 | int main() |
dreschpe | 0:f6a57b843f79 | 75 | { |
MACRUM | 3:c426b4b6d888 | 76 | unsigned short kbuf[16] = {0x93fa, 0x967b, 0x8cea, 0x955c, 0x8ea6}; |
MACRUM | 3:c426b4b6d888 | 77 | |
chris | 2:a87e255a8f3a | 78 | lcd.cls(); |
dreschpe | 0:f6a57b843f79 | 79 | |
MACRUM | 3:c426b4b6d888 | 80 | for(int i=0; i<5; i++) { |
MACRUM | 3:c426b4b6d888 | 81 | read_font(kbuf[i]); |
MACRUM | 3:c426b4b6d888 | 82 | draw_kanji(16*i, 0); |
dreschpe | 0:f6a57b843f79 | 83 | } |
MACRUM | 3:c426b4b6d888 | 84 | |
dreschpe | 0:f6a57b843f79 | 85 | } |