Library for Nuelectronics Nokia 3310/5110 LCD Display and joystick.
Dependents: N3310LCD_Demo FRDM_N3110LCD
Diff: N3310LCD.cpp
- Revision:
- 4:90dce6032a37
- Parent:
- 3:9808f63fd2fe
- Child:
- 5:1fd7af32e521
--- a/N3310LCD.cpp Sun Mar 24 15:15:08 2013 +0000 +++ b/N3310LCD.cpp Sun Mar 24 19:21:51 2013 +0000 @@ -33,19 +33,20 @@ unsigned char *fontStart; // Start of font data int8_t fontWidth; // Font width int8_t fontHeight; // Font height +int16_t fontStartChar; // Start, usually 32 +int16_t fontEndChar; // End character, usually 127 or 128 N3310LCD::N3310LCD (PinName mosi, PinName miso, PinName sck, PinName ce, PinName dat_cmd, PinName lcd_rst, PinName bl_on) : lcdPort(mosi, miso, sck), - ceWire(ce), dcWire(dat_cmd), rstWire(lcd_rst), blWire(bl_on) -{ + ceWire(ce), dcWire(dat_cmd), rstWire(lcd_rst), blWire(bl_on) { } void N3310LCD::init() { // use default SPI format lcdPort.format(8,0); - lcdPort.frequency(2000000); + lcdPort.frequency(8000000); // Lets try 8MHz // lcd reset wait_ms(1); @@ -72,15 +73,27 @@ case FONT_6x8: fontWidth = 6; fontHeight = 8; + fontStartChar = 32; + fontEndChar = 128; fontStart = font6_8; break; + + /* case FONT_ALPHA_17x17: + fontWidth = 17; + fontHeight = 17; + fontStartChar = 65; + fontEndChar = 91; + fontStart = Liberation_Sans17x17_Alpha; + break; +*/ default: fontWidth = 5; fontHeight = 7; + fontStartChar = 32; + fontEndChar = 128; fontStart = font5_7; break; } - } void N3310LCD::cls() @@ -200,22 +213,13 @@ void N3310LCD::writeChar(BYTE ch, eDisplayMode mode) { -// BYTE sendByte; - - // unsigned char* pFont = (unsigned char*)font6_8; -// ch -= 32; - /* - for (BYTE line = 0; line < 6; line++) { - sendByte = *(pFont + ch*6 + line); - writeData((mode == NORMAL)? sendByte: (sendByte ^ 0xff)); - } - */ + ch -= fontStartChar; if (cursor_col > LCDCOLMAX - (fontWidth+1)) cursor_col = LCDCOLMAX - (fontWidth+1); // ensure space is available for the character if (cursor_row > LCDROWMAX - 1) cursor_row = LCDROWMAX - 1; // ensure space is available for the character lcd_buffer[cursor_row][cursor_col] = 0x00; for(int8_t j=0; j< fontHeight; j++) { - lcd_buffer[cursor_row][cursor_col + j] = fontStart[(ch-32)*fontWidth + j]; + lcd_buffer[cursor_row][cursor_col + j] = fontStart[(ch)*fontWidth + j]; } lcd_buffer[cursor_row][cursor_col + fontWidth] = 0x00; @@ -274,16 +278,10 @@ for(int8_t j=0; j<colsUsed; j++) { sendByte = *(pFont + ch*48 + i*16 + j); -// ch_dat = pFont[ch*48 + i*16 +j]; // 16 cols in data for char even if we use fewer. - //ch_dat = pgm_read_byte(pFont+ch*48 + i*12 +j); // 12 cols in data for char even if we use fewer. lcd_buffer[cursor_row][cursor_col + j] = (mode == NORMAL)? sendByte : (sendByte^0xff); - - writeData( (mode == NORMAL)? sendByte : (sendByte^0xff)); + writeData( lcd_buffer[cursor_row][cursor_col + j] ); } } - - - } /* @@ -313,7 +311,6 @@ } lcd_buffer[row][x] = value; - locate (x,row); writeData(value); }