Fork of LCD-Window which works with Enhanced TextLCD from Wim
Fork of LcdWindow by
Diff: sed1335text.cpp
- Revision:
- 7:b472970bd8f6
- Parent:
- 6:7ba288afed38
- Child:
- 8:ba176eea3e40
--- a/sed1335text.cpp Tue Jan 04 22:10:41 2011 +0000 +++ b/sed1335text.cpp Tue Jan 04 22:58:59 2011 +0000 @@ -27,14 +27,21 @@ #include "DigitalOut.h" #include "wait_api.h" +#define FIRSTBANK_MEM 0 +#define SECONDBANK_MEM 0x1000 +#define THIRDBANK_MEM 0x800 + +#define HIGH(x) ((x&0xff00)>>8) +#define LOW(x) (x&0xff) + void SED1335TextLCD::writeText(const unsigned int column, const unsigned int row, const char text[]) { int i=0; int pos=row*getColumns()+column; sendCmd(0x46); // set cursor addr - sendData(pos&0xff); - sendData((pos&0xff00)>>8); + sendData(LOW(pos)); + sendData(HIGH(pos)); sendCmd(0x42); while (text[i]!=0) { @@ -43,48 +50,25 @@ } } -void SED1335TextLCD::clear() { - _guard->take(); - - ::printf("start clear\n"); - // first block +void SED1335TextLCD::clearBank(int start, int size, int data) { sendCmd(0x46); // set cursor addr - sendData(0x00); // start of RAM - sendData(0x00); + sendData(LOW(start)); // start of RAM + sendData(HIGH(start)); wait_ms(1); sendCmd(0x42); // write to memory - for (int i=0;i<40*30;i++) - sendData(0x20); // send space + for (int i=0;i<size;i++) + sendData(data); // send space wait_ms(1); - - // second block - sendCmd(0x46); // set cursor addr - sendData(0x00); // start of RAM - sendData(0x10); - wait_ms(1); - - sendCmd(0x42); // write to memory - for (int i=0;i<40*30*8;i++) - sendData(0x00); // send space - wait_ms(1); +} - // third block - sendCmd(0x46); // set cursor addr - sendData(0x00); // start of RAM - sendData(0x08); - wait_ms(1); +void SED1335TextLCD::clear() { + _guard->take(); + + clearBank(FIRSTBANK_MEM,getColumns()*getRows(),0x20); + clearBank(SECONDBANK_MEM,getColumns()*getRows()*8,0); + clearBank(THIRDBANK_MEM,getColumns()*getRows(),0); - sendCmd(0x42); // write to memory - for (int i=0;i<40*30;i++) - sendData(0x00); // send space - wait_ms(1); - - sendCmd(0x46); // set cursor addr - sendData(0x00); // start of RAM - sendData(0x00); - - ::printf("end clear\n"); _guard->release(); } @@ -107,33 +91,31 @@ } void SED1335TextLCD::init() { - ::printf("reset"); _reset->write(0); wait_ms(2); _reset->write(1); wait_ms(10); - ::printf(" finished\n"); sendCmd(0x40); // SYSTEM SET sendData(0x30); // p1 set cg rom sendData(0x87); // p2 sendData(0x7); // p3 - sendData(0x27); // p4 - sendData(0x2f); // p5 + sendData(getColumns()-1); // p4 + sendData(getColumns()+3); // p5 sendData(0xef); // p6 - sendData(0x28); // p7 + sendData(getColumns()); // p7 sendData(0x0); // p8 wait_ms(1); sendCmd(0x44); // SCROLL - sendData(0x00); // first block at 0 - sendData(0x00); - sendData(0xf0); // 240 lines - sendData(0x00); // second block at 0x1000 - sendData(0x10); - sendData(0xf0); // 240 lines - sendData(0x00); // third block at 0x800 - sendData(0x08); + sendData(LOW(FIRSTBANK_MEM)); // first block + sendData(HIGH(FIRSTBANK_MEM)); + sendData(getRows()*8); // lines + sendData(LOW(SECONDBANK_MEM)); // second block + sendData(HIGH(SECONDBANK_MEM)); + sendData(getRows()*8); // lines + sendData(LOW(THIRDBANK_MEM)); // third block at 0x800 + sendData(HIGH(THIRDBANK_MEM)); wait_ms(1); sendCmd(0x5a); // HDOT SCR @@ -162,7 +144,6 @@ } void SED1335TextLCD::sendCmd(const unsigned char cmd) { - ::printf("c->%x\n",cmd); _rd->write(1); _wr->write(1); _a0->write(1); @@ -173,7 +154,6 @@ } void SED1335TextLCD::sendData(const unsigned char cmd) { -// ::printf("d"); _rd->write(1); _wr->write(1); _a0->write(0); @@ -184,7 +164,6 @@ } void SED1335TextLCD::sendByte(const unsigned char byte) { -// ::printf("->%x\n",byte); // display reads with rising flank of /wr // first, set data, then set /wr low (no timing needed) _data->write(byte);