A C12832 LCD with generic interface
Dependents: mbed_blinky HTTPClient_HelloWorld websocketandnode xbeerx ... more
Fork of C12832 by
Diff: C12832_lcd.cpp
- Revision:
- 12:4affce236743
- Parent:
- 11:1d68011a277c
- Parent:
- 10:8f86576007d6
- Child:
- 13:8a9cad03124b
--- a/C12832_lcd.cpp Sat Nov 09 01:00:59 2013 +0000 +++ b/C12832_lcd.cpp Sat Nov 09 01:02:48 2013 +0000 @@ -14,7 +14,8 @@ // 13.10.12 initial design // 25.10.12 add autorefresh of screen -// 25.10.12 add standart font +// 25.10.12 add standart font +// 20.12.12 add bitmap graphics // optional defines : // #define debug_lcd 1 @@ -107,7 +108,7 @@ #else _spi.write(cmd); #endif -_CS = 1; + _CS = 1; } // write data to lcd controller @@ -160,7 +161,7 @@ wr_cmd(0xA6); // display normal - + #if defined TARGET_LPC1768 //setup DMA channel 0 LPC_SC->PCONP |= (1UL << 29); // Power up the GPDMA LPC_GPDMA->DMACConfig = 1; // enable DMA controller @@ -172,9 +173,10 @@ memset(buffer,0x00,512); // clear display buffer copy_to_lcd(); auto_up = 1; // switch on auto update - claim(stdout); // redirekt printf to lcd + // dont do this by default. Make the user call + //claim(stdout); // redirekt printf to lcd locate(0,0); - set_font((unsigned char*)Small_7); // standart font + set_font((unsigned char*)Small_7); // standart font } // set one pixel in buffer @@ -199,7 +201,7 @@ void C12832_LCD::copy_to_lcd(void) { -#ifndef TARGET_LPC1768 +#ifndef TARGET_LPC1768 int i; #endif //page 0 @@ -207,7 +209,7 @@ wr_cmd(0x10); // set column hi nibble 0 wr_cmd(0xB0); // set page address 0 _A0 = 1; -#if defined TARGET_LPC1768 +#if defined TARGET_LPC1768 _CS = 0; // start 128 byte DMA transfer to SPI1 LPC_GPDMACH0->DMACCDestAddr = (uint32_t)&LPC_SSP1->DR; // we send to SSP1 @@ -224,17 +226,17 @@ } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI1 not idle _CS = 1; #else // no DMA - for(i=0;i<128;i++){ + for(i=0; i<128; i++) { wr_dat(buffer[i]); - } -#endif + } +#endif // page 1 wr_cmd(0x00); // set column low nibble 0 wr_cmd(0x10); // set column hi nibble 0 wr_cmd(0xB1); // set page address 1 _A0 = 1; -#if defined TARGET_LPC1768 +#if defined TARGET_LPC1768 _CS = 0; // start 128 byte DMA transfer to SPI1 LPC_GPDMA->DMACIntTCClear = 0x1; @@ -249,17 +251,17 @@ } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI1 not idle _CS = 1; #else // no DMA - for(i=128;i<256;i++){ + for(i=128; i<256; i++) { wr_dat(buffer[i]); - } -#endif + } +#endif //page 2 wr_cmd(0x00); // set column low nibble 0 wr_cmd(0x10); // set column hi nibble 0 wr_cmd(0xB2); // set page address 2 _A0 = 1; -#if defined TARGET_LPC1768 +#if defined TARGET_LPC1768 _CS = 0; // start 128 byte DMA transfer to SPI1 LPC_GPDMA->DMACIntTCClear = 0x1; @@ -274,19 +276,19 @@ } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI1 not idle _CS = 1; #else // no DMA - for(i=256;i<384;i++){ + for(i=256; i<384; i++) { wr_dat(buffer[i]); - } -#endif + } +#endif //page 3 wr_cmd(0x00); // set column low nibble 0 wr_cmd(0x10); // set column hi nibble 0 wr_cmd(0xB3); // set page address 3 _A0 = 1; - - _CS = 0; -#if defined TARGET_LPC1768 + + _CS = 0; +#if defined TARGET_LPC1768 // start 128 byte DMA transfer to SPI1 LPC_GPDMA->DMACIntTCClear = 0x1; LPC_GPDMA->DMACIntErrClr = 0x1; @@ -300,10 +302,10 @@ } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI1 not idle _CS = 1; #else // no DMA - for(i=384;i<512;i++){ + for(i=384; i<512; i++) { wr_dat(buffer[i]); - } -#endif + } +#endif } void C12832_LCD::cls(void) @@ -542,7 +544,7 @@ for (i = 0; i <= r; i++) circle(x,y,i,color); auto_up = up; - if(auto_up) copy_to_lcd(); + if(auto_up) copy_to_lcd(); } void C12832_LCD::setmode(int mode) @@ -637,10 +639,33 @@ void C12832_LCD::set_auto_up(unsigned int up) { if(up ) auto_up = 1; + else auto_up = 0; } -unsigned int C12832_LCD::get_auto_up(void){ +unsigned int C12832_LCD::get_auto_up(void) +{ return (auto_up); } +void C12832_LCD::print_bm(Bitmap bm, int x, int y) +{ + int h,v,b; + char d; + for(v=0; v < bm.ySize; v++) { // lines + for(h=0; h < bm.xSize; h++) { // pixel + if(h + x > 127) break; + if(v + y > 31) break; + d = bm.data[bm.Byte_in_Line * v + ((h & 0xF8) >> 3)]; + b = 0x80 >> (h & 0x07); + if((d & b) == 0) { + pixel(x+h,y+v,0); + } else { + pixel(x+h,y+v,1); + } + } + } + +} + +