tr
Revision 53:62184d04f9b5, committed 2021-03-30
- Comitter:
- tangguangmin
- Date:
- Tue Mar 30 13:47:15 2021 +0000
- Parent:
- 52:1210e39a4748
- Commit message:
- 45
Changed in this revision
N5110.cpp | Show annotated file Show diff for this revision Revisions of this file |
N5110.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 1210e39a4748 -r 62184d04f9b5 N5110.cpp --- a/N5110.cpp Thu Mar 18 13:58:10 2021 +0000 +++ b/N5110.cpp Tue Mar 30 13:47:15 2021 +0000 @@ -461,6 +461,10 @@ int ncols, char *pic) { + if(ncols%8) + { + ncols = (ncols/8 + 1) * 8; + } if((nrows - x0) < 84) x0 = nrows - 84; if((ncols - y0) < 48) @@ -472,7 +476,7 @@ char pixels = 0; int divisor = ((x0 + m) * ncols + (y0 + n * 8))/8; int remainder = ((x0 + m) * ncols + (y0 + n * 8))%8; - pixels = ((pic[divisor] << remainder)) + ((pic[divisor+1] >> (8 - remainder))); + pixels = ((pic[divisor] >> remainder)) + ((pic[divisor+1] << (8 - remainder))); buffer[m][n] = pixels; } }
diff -r 1210e39a4748 -r 62184d04f9b5 N5110.h --- a/N5110.h Thu Mar 18 13:58:10 2021 +0000 +++ b/N5110.h Tue Mar 30 13:47:15 2021 +0000 @@ -39,169 +39,6 @@ FILL_WHITE, ///< Filled white (no outline) }; -/** N5110 Class -@brief Library for interfacing with Nokia 5110 LCD display (https://www.sparkfun.com/products/10168) using the hardware SPI on the mbed. -@brief The display is powered from a GPIO pin meaning it can be controlled via software. The LED backlight is also software-controllable (via PWM pin). -@brief Can print characters and strings to the display using the included 5x7 font. -@brief The library also implements a screen buffer so that individual pixels on the display (84 x 48) can be set, cleared and read. -@brief The library can print primitive shapes (lines, circles, rectangles) -@brief Acknowledgements to Chris Yan's Nokia_5110 Library. - -@brief Revision 1.3 - -@author Craig A. Evans -@date 7th February 2017 - -@code - -#include "mbed.h" -#include "N5110.h" - -// rows,cols -int sprite[8][5] = { - { 0,0,1,0,0 }, - { 0,1,1,1,0 }, - { 0,0,1,0,0 }, - { 0,1,1,1,0 }, - { 1,1,1,1,1 }, - { 1,1,1,1,1 }, - { 1,1,0,1,1 }, - { 1,1,0,1,1 }, -}; - -// VCC,SCE,RST,D/C,MOSI,SCLK,LED -//N5110 lcd(p7,p8,p9,p10,p11,p13,p21); // LPC1768 - pwr from GPIO -N5110 lcd(p8,p9,p10,p11,p13,p21); // LPC1768 - powered from +3V3 - JP1 in 2/3 position -//N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); // K64F - pwr from 3V3 - -int main() -{ - // first need to initialise display - lcd.init(); - - while(1) { - - // these are default settings so not strictly needed - lcd.normalMode(); // normal colour mode - lcd.setBrightness(0.5); // put LED backlight on 50% - - lcd.clear(); - // x origin, y origin, rows, cols, sprite - lcd.drawSprite(20,6,8,5,(int *)sprite); - lcd.refresh(); - wait(5.0); - - lcd.clear(); // clear buffer at start of every loop - // can directly print strings at specified co-ordinates (must be less than 84 pixels to fit on display) - lcd.printString("Hello, World!",0,0); - - char buffer[14]; // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14) - // so can display a string of a maximum 14 characters in length - // or create formatted strings - ensure they aren't more than 14 characters long - int temperature = 27; - int length = sprintf(buffer,"T = %2d C",temperature); // print formatted data to buffer - // it is important the format specifier ensures the length will fit in the buffer - if (length <= 14) // if string will fit on display (assuming printing at x=0) - lcd.printString(buffer,0,1); // display on screen - - float pressure = 1012.3; // same idea with floats - length = sprintf(buffer,"P = %.2f mb",pressure); - if (length <= 14) - lcd.printString(buffer,0,2); - - // can also print individual characters at specified place - lcd.printChar('X',5,3); - - // draw a line across the display at y = 40 pixels (origin top-left) - for (int i = 0; i < WIDTH; i++) { - lcd.setPixel(i,40); - } - // need to refresh display after setting pixels or writing strings - lcd.refresh(); - wait(5.0); - - for(int i = 0; i < 3; i++) { - for(int j = 0; j < 5; j++) { - printf("%d,%d = %d\n",i,j,glyph[i][j]); - } - } - - - - // can check status of pixel using getPixel(x,y); - lcd.clear(); // clear buffer - lcd.setPixel(2,2); // set random pixel in buffer - lcd.refresh(); - wait(1.0); - - int pixel_to_test = lcd.getPixel(2,2); - - if ( pixel_to_test ) { - lcd.printString("2,2 is set",0,4); - } - - // this one shouldn't be set - pixel_to_test = lcd.getPixel(3,3); - - if ( pixel_to_test == 0 ) { - lcd.printString("3,3 is clear",0,5); - } - - lcd.refresh(); - wait(4.0); - - lcd.clear(); // clear buffer - lcd.inverseMode(); // invert colours - lcd.setBrightness(1.0); // put LED backlight on full - - float array[84]; - - for (int i = 0; i < 84; i++) { - array[i] = 0.5 + 0.5*sin(i*2*3.14/84); - } - - // can also plot graphs - 84 elements only - // values must be in range 0.0 - 1.0 - lcd.plotArray(array); - lcd.refresh(); - wait(5.0); - - lcd.clear(); - lcd.normalMode(); // normal colour mode back - lcd.setBrightness(0.5); // put LED backlight on 50% - - // example of drawing lines - for (int x = 0; x < WIDTH ; x+=10) { - // x0,y0,x1,y1,type 0-white,1-black,2-dotted - lcd.drawLine(0,0,x,HEIGHT,2); - } - lcd.refresh(); // refresh after drawing shapes - wait(5.0); - - - lcd.clear(); - // example of how to draw circles - lcd.drawCircle(WIDTH/2,HEIGHT/2,20,FILL_BLACK); // x,y,radius,black fill - lcd.drawCircle(WIDTH/2,HEIGHT/2,10,FILL_WHITE); // x,y,radius,white fill - lcd.drawCircle(WIDTH/2,HEIGHT/2,30,FILL_TRANSPARENT); // x,y,radius,transparent with outline - lcd.refresh(); // refresh after drawing shapes - wait(5.0); - - lcd.clear(); - // example of how to draw rectangles - // origin x,y,width,height,type - lcd.drawRect(10,10,50,30,FILL_BLACK); // filled black rectangle - lcd.drawRect(15,15,20,10,FILL_WHITE); // filled white rectange (no outline) - lcd.drawRect(2,2,70,40,FILL_TRANSPARENT); // transparent, just outline - lcd.refresh(); // refresh after drawing shapes - wait(5.0); - - } -} - - -@endcode -*/ class N5110 { private: