Paul Evans
/
Newhaven_LCD
Newhaven 320x240 LCD
newhaven.cpp
- Committer:
- pbevans89
- Date:
- 2011-02-27
- Revision:
- 0:c8893901ef8a
- Child:
- 2:2058e2f79157
File content as of revision 0:c8893901ef8a:
#include "mbed.h" #include "newhaven.h" NHLCD::NHLCD(PinName PIN_E,PinName PIN_RW,PinName PIN_A0,PinName PIN_CS,PinName PIN_RST, BusInOut *BUSLCD) : E(PIN_E),RW(PIN_RW),A0(PIN_A0),CS(PIN_CS),RST(PIN_RST){ LCD_PORT = BUSLCD; } void delay(unsigned int n) { unsigned int i,j; for (i=0;i<n;i++) for (j=0;j<350;j++) {;} } void delay1(unsigned int i) { while(i--); } void NHLCD::comm_out(unsigned char j){ LCD_PORT->output(); A0 = 1; LCD_PORT->write(j); CS = 0; RW = 0; E = 1; delay(1); E = 0; RW = 1; CS = 1; } void NHLCD::data_out(unsigned char j){ LCD_PORT->output(); A0 = 0; LCD_PORT->write(j); CS = 0; RW = 0; E = 1; delay(1); E = 0; RW = 1; CS = 1; } void NHLCD::clearScreen(){ int n; comm_out(0x46); data_out(0x00); data_out(0x00); comm_out(0x42); for(n=0;n<1200;n++){ data_out(0x20); } comm_out(0x46); data_out(0xB0); data_out(0x04); comm_out(0x42); for(n=0;n<9600;n++){ data_out(0x00); } } void NHLCD::text(char *text, char row, char col){ int c = row*40+col; comm_out(0x46); data_out((unsigned char)(c&0xFF)); data_out((unsigned char)((c&0xFF00)>>8)); comm_out(0x42); while(*text != 0) { data_out(*text); text++; } } void NHLCD::Init(void){ RST = 0; delay(5); RST = 1; delay(10); comm_out(0x40); delay(5); data_out(0x30); //parameters data_out(0x87); //horizontal character size (0x80 = 1) MUST BE MULTIPLE OF 320 data_out(0x07); //vertical character size (0x00 = 1) MUST BE MULTIPLE OF 240 data_out(40); //addresses per line data_out(80); data_out(0xEF); data_out(0x28); data_out(0x00); comm_out(0x44); data_out(0x00); data_out(0x00); data_out(0xEF); data_out(0xB0); data_out(0x04); data_out(0xEF); data_out(0x00); data_out(0x00); data_out(0x00); data_out(0x00); comm_out(0x5A); data_out(0x00); comm_out(0x5B); data_out(0x00); comm_out(0x58); data_out(0x56); comm_out(0x5D); data_out(0x04); data_out(0x86); comm_out(0x4C); comm_out(0x59); data_out(0x16); wait_ms(5); } void NHLCD::setPixel(int row, int col){ int loc = (0x04<<8)|(0xB0); int c = loc+row*40+(col/8); comm_out(0x46); data_out((unsigned char)(c&0xFF)); data_out((unsigned char)((c&0xFF00)>>8)); comm_out(0x43); LCD_PORT->input(); unsigned char buffer = LCD_PORT->read(); buffer = buffer|(1<<(7-((row*320+col)%8))); LCD_PORT->output(); comm_out(0x46); data_out((unsigned char)(c&0xFF)); data_out((unsigned char)((c&0xFF00)>>8)); comm_out(0x42); data_out(buffer); }