Library for interfacing to Nokia 5110 LCD display (as found on the SparkFun website).
Fork of N5110 by
Diff: N5110.cpp
- Revision:
- 13:908644099648
- Parent:
- 10:6f3abb40202b
- Child:
- 15:ee645611ff94
--- a/N5110.cpp Wed Sep 17 11:35:50 2014 +0000 +++ b/N5110.cpp Tue Mar 10 19:18:20 2015 +0000 @@ -10,10 +10,10 @@ N5110::N5110(PinName pwrPin, PinName scePin, PinName rstPin, PinName dcPin, PinName mosiPin, PinName sclkPin, PinName ledPin) { - + spi = new SPI(mosiPin,NC,sclkPin); // create new SPI instance and initialise - initSPI(); - + initSPI(); + // set up pins as required led = new PwmOut(ledPin); pwr = new DigitalOut(pwrPin); @@ -47,16 +47,18 @@ clearRAM(); } - -// sets normal video mode (black on white) -void N5110::normalMode() { - sendCommand(CMD_DC_NORMAL_MODE); - + +// sets normal video mode (black on white) +void N5110::normalMode() +{ + sendCommand(CMD_DC_NORMAL_MODE); + } -// sets normal video mode (white on black) -void N5110::inverseMode() { - sendCommand(CMD_DC_INVERT_VIDEO); +// sets normal video mode (white on black) +void N5110::inverseMode() +{ + sendCommand(CMD_DC_INVERT_VIDEO); } // function to power up the LCD and backlight @@ -144,7 +146,7 @@ } -// function to set the XY address in RAM for subsequenct data write +// function to set the XY address in RAM for subsequenct data write void N5110::setXYAddress(int x, int y) { // check whether address is in range @@ -187,11 +189,11 @@ void N5110::refresh() { int i,j; - + setXYAddress(0,0); // important to set address back to 0,0 before refreshing display // address auto increments after printing string, so buffer[0][0] will not coincide // with top-left pixel after priting string - + sce->write(0); //set CE low to begin frame for(j = 0; j < 6; j++) { // be careful to use correct order (j,i) for horizontal addressing @@ -217,17 +219,14 @@ } // function to print 5x7 font -void N5110::printChar(char c) +void N5110::printChar(char c,int x,int y) { - int i; - // loop through 5 columns - for (i = 0; i < 5 ; i++ ) { - sendData(font5x7[(c - 32)*5 + i]); - // array is offset by 32 relative to ASCII, each character is 5 pixels wide - // the X address is automatically incremented after each data write + for (int i = 0; i < 5 ; i++ ) { + buffer[x+i][y] = font5x7[(c - 32)*5 + i]; + // array is offset by 32 relative to ASCII, each character is 5 pixels wide } - sendData(0); // send an empty byte to introduce space between characters - + + refresh(); // this sends the buffer to the display and sets address (cursor) back to 0,0 } // function to print string at specified position @@ -237,20 +236,16 @@ // loop through string and print character while(*str) { - // This is the old version - strings are printed using the printChar function - //setXYAddress(x+6*n,y); // leave 1 pixel (6 = 5 + 1) between each character - //printChar(*str); // print the char - can probably do *str++ and remove next line - - // the new version writes the character bitmap data to the buffer, so that + // writes the character bitmap data to the buffer, so that // text and pixels can be displayed at the same time for (int i = 0; i < 5 ; i++ ) { buffer[x+i+n*6][y] = font5x7[(*str - 32)*5 + i]; } - + str++; // go to next character in string n++; // increment index } - + refresh(); // this sends the buffer to the display and sets address (cursor) back to 0,0 } @@ -274,18 +269,19 @@ } // function to plot array on display -void N5110::plotArray(float array[]) { - +void N5110::plotArray(float array[]) +{ + int i; - + for (i=0; i<84; i++) { // loop through array // elements are normalised from 0.0 to 1.0, so multiply // by 47 to convert to pixel range, and subtract from 47 // since top-left is 0,0 in the display geometry setPixel(i,47 - int(array[i]*47.0)); - } - + } + refresh(); - - + + } \ No newline at end of file