LCDPanel implementation for ITDB02-2.2SP LCD module using HX8340B controller
#include "mbed.h" DigitalOut myled(LED1); SPI spi(p5,NC,p7); DigitalOut cs(p8); DigitalOut rst(p9); void command(unsigned int i) { spi.write(i&0xff); } // clear 9th bit for command void data(unsigned int i) { spi.write(i|0x100); } // set 9th bit for data void lcd_window(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2) { command(0x2A); // column data(0x00); data(x1); data(0x00); data(x2); command(0x2B); // row data(0x00); data(y1); data(0x00); data(y2); command(0x2C); // start write to ram } void lcd_pixel(unsigned int c) { data(c>>8); data(c); } void lcd_fill(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, unsigned int color) { cs=0; lcd_window(x1,y1,x2,y2); unsigned int total=(x2-x1+1)*(y2-y1+1); for (unsigned int i=0;i<total;i++) { lcd_pixel(color); } cs=1; } void lcd_clear() { lcd_fill(0,0,176,220,0); } void lcd_init() { cs = 1; rst = 0; spi.format(9); spi.frequency(5000000); wait_ms(1); rst = 1; wait_ms(1); cs = 0; command(0xC1); data(0xff); data(0x83); data(0x40); command(0x11); wait_ms(150); command(0xca); data(0x70); data(0x00); data(0xD9); command(0xb0); data(0x01); data(0x11); command(0xc9); data(0x90); data(0x49); data(0x10); data(0x28); data(0x28); data(0x10); data(0x00); data(0x06); wait_ms(20); command(0xc2); data(0x60); data(0x71); data(0x01); data(0x0e); data(0x05); data(0x02); data(0x09); data(0x31); data(0x0A); command(0xc3); data(0x67); data(0x30); data(0x61); data(0x17); data(0x48); data(0x07); data(0x05); data(0x33); wait_ms(10); command(0xb5); data(0x35); data(0x20); data(0x45); command(0xb4); data(0x33); data(0x25); data(0x4c); wait_ms(10); command(0x3a); data(0x05); command(0x29); wait_ms(10); cs=1; lcd_clear(); } int main() { lcd_init(); lcd_fill(9,9,166,210,0xff); lcd_fill(19,19,156,200,0x0ff00); while(1) { myled = 1; wait(0.2); myled = 0; wait(0.2); } }
LCDPanel_HX8340B.cpp@0:6339553f69a4, 2012-03-09 (annotated)
- Committer:
- silviogissi
- Date:
- Fri Mar 09 01:50:15 2012 +0000
- Revision:
- 0:6339553f69a4
- Child:
- 1:5dbe0bb6f7e4
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
silviogissi | 0:6339553f69a4 | 1 | #include "LCDPanel_HX8340B.h" |
silviogissi | 0:6339553f69a4 | 2 | |
silviogissi | 0:6339553f69a4 | 3 | LCDPanel_HX8340B::LCDPanel_HX8340B(PinName spi_data, PinName spi_clock, PinName cs, PinName rst) |
silviogissi | 0:6339553f69a4 | 4 | : LCDPanel (LCDPANEL_HX8340B_WIDTH,LCDPANEL_HX8340B_HEIGHT,cs) |
silviogissi | 0:6339553f69a4 | 5 | , _rst(rst) |
silviogissi | 0:6339553f69a4 | 6 | #ifdef LCDPANEL_HX8340B_BITBANG |
silviogissi | 0:6339553f69a4 | 7 | , _scl(spi_clock) |
silviogissi | 0:6339553f69a4 | 8 | , _sda(spi_data) |
silviogissi | 0:6339553f69a4 | 9 | #else |
silviogissi | 0:6339553f69a4 | 10 | , _spi(spi_data,NC,spi_clock) |
silviogissi | 0:6339553f69a4 | 11 | #endif |
silviogissi | 0:6339553f69a4 | 12 | { |
silviogissi | 0:6339553f69a4 | 13 | init(); |
silviogissi | 0:6339553f69a4 | 14 | } |
silviogissi | 0:6339553f69a4 | 15 | |
silviogissi | 0:6339553f69a4 | 16 | void LCDPanel_HX8340B::init() { |
silviogissi | 0:6339553f69a4 | 17 | } |