Lib for the LCD display on mbed lab Board
Diff: C12832_lcd.cpp
- Revision:
- 7:0f5a3b0f3cab
- Parent:
- 3:468cdccff7af
- Child:
- 8:c9afe58d786a
--- a/C12832_lcd.cpp Wed Dec 05 21:43:17 2012 +0000 +++ b/C12832_lcd.cpp Fri Dec 21 20:43:59 2012 +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 @@ -106,7 +107,7 @@ #else _spi.write(cmd); #endif -_CS = 1; + _CS = 1; } // write data to lcd controller @@ -159,7 +160,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 @@ -173,7 +174,7 @@ auto_up = 1; // switch on auto update 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 @@ -198,7 +199,7 @@ void C12832_LCD::copy_to_lcd(void) { -#ifndef TARGET_LPC1768 +#ifndef TARGET_LPC1768 int i; #endif //page 0 @@ -206,7 +207,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 @@ -223,17 +224,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; @@ -248,17 +249,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; @@ -273,19 +274,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; @@ -299,10 +300,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) @@ -541,7 +542,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) @@ -638,8 +639,30 @@ if(up ) auto_up = 1; } -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); + } + } + } + +} + +