Simple library for interfacing to Nokia 5110 LCD display (as found on the SparkFun website). - koristen softverski SPI umjesto hardverskog
Fork of N5110 by
N5110.h
00001 /** 00002 @file N5110.h 00003 00004 @brief Header file containing member functions and variables 00005 00006 */ 00007 00008 #ifndef N5110_H 00009 #define N5110_H 00010 00011 #include "SWSPI.h" 00012 00013 // Command Bytes - taken from Chris Yan's library 00014 // More information can be found in the display datasheet 00015 // H = 0 - Basic instructions 00016 #define CMD_DC_CLEAR_DISPLAY 0x08 00017 #define CMD_DC_NORMAL_MODE 0x0C 00018 #define CMD_DC_FILL_DISPLAY 0x09 00019 #define CMD_DC_INVERT_VIDEO 0x0D 00020 #define CMD_FS_HORIZONTAL_MODE 0x00 00021 #define CMD_FS_VERTICAL_MODE 0x02 00022 #define CMD_FS_BASIC_MODE 0x00 00023 #define CMD_FS_EXTENDED_MODE 0x01 00024 #define CMD_FS_ACTIVE_MODE 0x00 00025 #define CMD_FS_POWER_DOWN_MODE 0x04 00026 // H = 1 - Extended instructions 00027 #define CMD_TC_TEMP_0 0x04 00028 #define CMD_TC_TEMP_1 0x05 00029 #define CMD_TC_TEMP_2 0x06 00030 #define CMD_TC_TEMP_3 0x07 00031 #define CMD_BI_MUX_24 0x15 00032 #define CMD_BI_MUX_48 0x13 00033 #define CMD_BI_MUX_100 0x10 00034 #define CMD_VOP_6V06 0xB2 00035 #define CMD_VOP_7V38 0xC8 00036 00037 #include "mbed.h" 00038 00039 /** 00040 @brief Simple library for interfacing with Nokia 5110 LCD display (https://www.sparkfun.com/products/10168) using the hardware SPI on the mbed. 00041 @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). 00042 @brief Can print characters and strings to the display using the included 5x7 font. 00043 @brief The library also implements a screen buffer so that individual pixels on the display (84 x 48) can be set, cleared and read. 00044 00045 @brief Acknowledgements to Chris Yan's Nokia_5110 Library. 00046 00047 @brief Revision 1.0 00048 00049 @author Craig A. Evans 00050 @date January 2014 00051 * 00052 * Example: 00053 * @code 00054 00055 #include "mbed.h" 00056 #include "N5110.h" 00057 00058 // VCC,SCE,RST,D/C,MOSI,SCLK,LED 00059 N5110 lcd(p7,p8,p9,p10,p11,p13,p26); 00060 00061 int main() { 00062 00063 // initialise display 00064 lcd.init(); 00065 // print a string in top-left corner 00066 lcd.printString("Hello, World!",0,0); 00067 // move cursor to 4th row 00068 lcd.setXYAddress(0,3); 00069 // print character 00070 lcd.printChar('X'); 00071 00072 while(1); 00073 } 00074 00075 * @endcode 00076 */ 00077 class N5110 00078 { 00079 00080 public: 00081 /** Create a N5110 object connected to the specified pins 00082 * 00083 * @param pwr Pin connected to Vcc on the LCD display (pin 1) 00084 * @param sce Pin connected to chip enable (pin 3) 00085 * @param rst Pin connected to reset (pin 4) 00086 * @param dc Pin connected to data/command select (pin 5) 00087 * @param mosi Pin connected to data input (MOSI) (pin 6) 00088 * @param sclk Pin connected to serial clock (SCLK) (pin 7) 00089 * @param led Pin connected to LED backlight (must be PWM) (pin 8) 00090 * 00091 */ 00092 N5110(PinName pwrPin, PinName scePin, PinName rstPin, PinName dcPin, PinName mosiPin, PinName sclkPin, PinName ledPin); 00093 00094 /** Initialise display 00095 * 00096 * Powers up the display and turns on backlight (50% brightness default). 00097 * Sets the display up in horizontal addressing mode and with normal video mode. 00098 */ 00099 void init(); 00100 00101 /** Turn off 00102 * 00103 * Powers down the display and turns of the backlight. 00104 * Needs to be reinitialised before being re-used. 00105 */ 00106 void turnOff(); 00107 00108 /** Clears 00109 * 00110 * Clears the screen. 00111 */ 00112 void clear(); 00113 00114 /** Turn on normal video mode (default) 00115 * Black on white 00116 */ 00117 void normalMode(); 00118 00119 /** Turn on inverse video mode (default) 00120 * White on black 00121 */ 00122 void inverseMode(); 00123 00124 /** Set Brightness 00125 * 00126 * Sets brightness of LED backlight. 00127 * @param brightness - float in range 0.0 to 1.0 00128 */ 00129 void setBrightness(float brightness); 00130 00131 /** Set XY Address 00132 * 00133 * Sets the X and Y address of where the next data sent to the displa will be written in RAM. 00134 * @param x - the column number (0 to 83) - is automatically incremented after data is written 00135 * @param y - the row number (0 to 5) - the diplay is split into 6 banks - each bank can be considered a row 00136 */ 00137 void setXYAddress(int x, int y); 00138 00139 /** Print String 00140 * 00141 * Prints a string of characters to the display. 00142 * @param x - the column number (0 to 83) 00143 * @param y - the row number (0 to 5) - the display is split into 6 banks - each bank can be considered a row 00144 */ 00145 void printString(const char * str,int x,int y); 00146 00147 /** Print Character 00148 * 00149 * Sends a character to the display. Will be printed at the current address. 00150 * X address is autoincremented by 1 to leave a pixel between successive characters. 00151 * @param c - the character to print. Can print ASCII as so printChar('C'). 00152 */ 00153 void printChar(char c); 00154 00155 /** Set a Pixel 00156 * 00157 * This function sets a pixel in the display. A call to refresh() must be made 00158 * to update the display to reflect the change in pixels. 00159 * @param x - the x co-ordinate of the pixel (0 to 83) 00160 * @param y - the y co-ordinate of the pixel (0 to 47) 00161 */ 00162 void setPixel(int x, int y); 00163 00164 /** Clear a Pixel 00165 * 00166 * This function clears pixel in the display. A call to refresh() must be made 00167 * to update the display to reflect the change in pixels. 00168 * @param x - the x co-ordinate of the pixel (0 to 83) 00169 * @param y - the y co-ordinate of the pixel (0 to 47) 00170 */ 00171 void clearPixel(int x, int y); 00172 00173 /** Get a Pixel 00174 * 00175 * This function gets the status of a pixel in the display. 00176 * @param x - the x co-ordinate of the pixel (0 to 83) 00177 * @param y - the y co-ordinate of the pixel (0 to 47) 00178 * @returns 00179 * 0 - pixel is clear 00180 * non-zero - pixel is set 00181 */ 00182 unsigned char getPixel(int x, int y); 00183 00184 /** Refresh display 00185 * 00186 * This functions refreshes the display to reflect the current data in the buffer. 00187 */ 00188 void refresh(); 00189 00190 /** Randomise buffer 00191 * 00192 * This function fills the buffer with random data. Can be used to test the display. 00193 * A call to refresh() must be made to update the display to reflect the change in pixels. 00194 * The seed is not set and so the generated pattern will probably be the same each time. 00195 * TODO: Randomise the seed - maybe using the noise on the AnalogIn pins. 00196 */ 00197 void randomiseBuffer(); 00198 00199 private: 00200 void initSPI(); 00201 void turnOn(); 00202 void reset(); 00203 void clearRAM(); 00204 void clearBuffer(); 00205 void sendCommand(unsigned char command); 00206 void sendData(unsigned char data); 00207 00208 public: 00209 unsigned char buffer[84][6]; // screen buffer - the 6 is for the banks - each one is 8 bits; 00210 00211 private: // private variables 00212 SWSPI* spi; 00213 PwmOut* led; 00214 DigitalOut* pwr; 00215 DigitalOut* sce; 00216 DigitalOut* rst; 00217 DigitalOut* dc; 00218 00219 }; 00220 00221 const unsigned char font5x7[480] = { 00222 0x00, 0x00, 0x00, 0x00, 0x00,// (space) 00223 0x00, 0x00, 0x5F, 0x00, 0x00,// ! 00224 0x00, 0x07, 0x00, 0x07, 0x00,// " 00225 0x14, 0x7F, 0x14, 0x7F, 0x14,// # 00226 0x24, 0x2A, 0x7F, 0x2A, 0x12,// $ 00227 0x23, 0x13, 0x08, 0x64, 0x62,// % 00228 0x36, 0x49, 0x55, 0x22, 0x50,// & 00229 0x00, 0x05, 0x03, 0x00, 0x00,// ' 00230 0x00, 0x1C, 0x22, 0x41, 0x00,// ( 00231 0x00, 0x41, 0x22, 0x1C, 0x00,// ) 00232 0x08, 0x2A, 0x1C, 0x2A, 0x08,// * 00233 0x08, 0x08, 0x3E, 0x08, 0x08,// + 00234 0x00, 0x50, 0x30, 0x00, 0x00,// , 00235 0x08, 0x08, 0x08, 0x08, 0x08,// - 00236 0x00, 0x60, 0x60, 0x00, 0x00,// . 00237 0x20, 0x10, 0x08, 0x04, 0x02,// / 00238 0x3E, 0x51, 0x49, 0x45, 0x3E,// 0 00239 0x00, 0x42, 0x7F, 0x40, 0x00,// 1 00240 0x42, 0x61, 0x51, 0x49, 0x46,// 2 00241 0x21, 0x41, 0x45, 0x4B, 0x31,// 3 00242 0x18, 0x14, 0x12, 0x7F, 0x10,// 4 00243 0x27, 0x45, 0x45, 0x45, 0x39,// 5 00244 0x3C, 0x4A, 0x49, 0x49, 0x30,// 6 00245 0x01, 0x71, 0x09, 0x05, 0x03,// 7 00246 0x36, 0x49, 0x49, 0x49, 0x36,// 8 00247 0x06, 0x49, 0x49, 0x29, 0x1E,// 9 00248 0x00, 0x36, 0x36, 0x00, 0x00,// : 00249 0x00, 0x56, 0x36, 0x00, 0x00,// ; 00250 0x00, 0x08, 0x14, 0x22, 0x41,// < 00251 0x14, 0x14, 0x14, 0x14, 0x14,// = 00252 0x41, 0x22, 0x14, 0x08, 0x00,// > 00253 0x02, 0x01, 0x51, 0x09, 0x06,// ? 00254 0x32, 0x49, 0x79, 0x41, 0x3E,// @ 00255 0x7E, 0x11, 0x11, 0x11, 0x7E,// A 00256 0x7F, 0x49, 0x49, 0x49, 0x36,// B 00257 0x3E, 0x41, 0x41, 0x41, 0x22,// C 00258 0x7F, 0x41, 0x41, 0x22, 0x1C,// D 00259 0x7F, 0x49, 0x49, 0x49, 0x41,// E 00260 0x7F, 0x09, 0x09, 0x01, 0x01,// F 00261 0x3E, 0x41, 0x41, 0x51, 0x32,// G 00262 0x7F, 0x08, 0x08, 0x08, 0x7F,// H 00263 0x00, 0x41, 0x7F, 0x41, 0x00,// I 00264 0x20, 0x40, 0x41, 0x3F, 0x01,// J 00265 0x7F, 0x08, 0x14, 0x22, 0x41,// K 00266 0x7F, 0x40, 0x40, 0x40, 0x40,// L 00267 0x7F, 0x02, 0x04, 0x02, 0x7F,// M 00268 0x7F, 0x04, 0x08, 0x10, 0x7F,// N 00269 0x3E, 0x41, 0x41, 0x41, 0x3E,// O 00270 0x7F, 0x09, 0x09, 0x09, 0x06,// P 00271 0x3E, 0x41, 0x51, 0x21, 0x5E,// Q 00272 0x7F, 0x09, 0x19, 0x29, 0x46,// R 00273 0x46, 0x49, 0x49, 0x49, 0x31,// S 00274 0x01, 0x01, 0x7F, 0x01, 0x01,// T 00275 0x3F, 0x40, 0x40, 0x40, 0x3F,// U 00276 0x1F, 0x20, 0x40, 0x20, 0x1F,// V 00277 0x7F, 0x20, 0x18, 0x20, 0x7F,// W 00278 0x63, 0x14, 0x08, 0x14, 0x63,// X 00279 0x03, 0x04, 0x78, 0x04, 0x03,// Y 00280 0x61, 0x51, 0x49, 0x45, 0x43,// Z 00281 0x00, 0x00, 0x7F, 0x41, 0x41,// [ 00282 0x02, 0x04, 0x08, 0x10, 0x20,// "\" 00283 0x41, 0x41, 0x7F, 0x00, 0x00,// ] 00284 0x04, 0x02, 0x01, 0x02, 0x04,// ^ 00285 0x40, 0x40, 0x40, 0x40, 0x40,// _ 00286 0x00, 0x01, 0x02, 0x04, 0x00,// ` 00287 0x20, 0x54, 0x54, 0x54, 0x78,// a 00288 0x7F, 0x48, 0x44, 0x44, 0x38,// b 00289 0x38, 0x44, 0x44, 0x44, 0x20,// c 00290 0x38, 0x44, 0x44, 0x48, 0x7F,// d 00291 0x38, 0x54, 0x54, 0x54, 0x18,// e 00292 0x08, 0x7E, 0x09, 0x01, 0x02,// f 00293 0x08, 0x14, 0x54, 0x54, 0x3C,// g 00294 0x7F, 0x08, 0x04, 0x04, 0x78,// h 00295 0x00, 0x44, 0x7D, 0x40, 0x00,// i 00296 0x20, 0x40, 0x44, 0x3D, 0x00,// j 00297 0x00, 0x7F, 0x10, 0x28, 0x44,// k 00298 0x00, 0x41, 0x7F, 0x40, 0x00,// l 00299 0x7C, 0x04, 0x18, 0x04, 0x78,// m 00300 0x7C, 0x08, 0x04, 0x04, 0x78,// n 00301 0x38, 0x44, 0x44, 0x44, 0x38,// o 00302 0x7C, 0x14, 0x14, 0x14, 0x08,// p 00303 0x08, 0x14, 0x14, 0x18, 0x7C,// q 00304 0x7C, 0x08, 0x04, 0x04, 0x08,// r 00305 0x48, 0x54, 0x54, 0x54, 0x20,// s 00306 0x04, 0x3F, 0x44, 0x40, 0x20,// t 00307 0x3C, 0x40, 0x40, 0x20, 0x7C,// u 00308 0x1C, 0x20, 0x40, 0x20, 0x1C,// v 00309 0x3C, 0x40, 0x30, 0x40, 0x3C,// w 00310 0x44, 0x28, 0x10, 0x28, 0x44,// x 00311 0x0C, 0x50, 0x50, 0x50, 0x3C,// y 00312 0x44, 0x64, 0x54, 0x4C, 0x44,// z 00313 0x00, 0x08, 0x36, 0x41, 0x00,// { 00314 0x00, 0x00, 0x7F, 0x00, 0x00,// | 00315 0x00, 0x41, 0x36, 0x08, 0x00,// } 00316 0x08, 0x08, 0x2A, 0x1C, 0x08,// -> 00317 0x08, 0x1C, 0x2A, 0x08, 0x08 // <- 00318 }; 00319 00320 #endif
Generated on Wed Jul 20 2022 04:01:43 by 1.7.2