NUCLEO-F070R-DS1820

Dependencies:   mbed

Fork of NUCLEO-F401RE-DS1820andThermistorNTC10K by Enrico Marinoni

Committer:
anywill
Date:
Fri Oct 21 09:09:11 2016 +0000
Revision:
6:7f43285de85b
nucleo 5110;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
anywill 6:7f43285de85b 1 // Project: Nokia5110 - Controlling a NK5110 display from an NXP LPC1768
anywill 6:7f43285de85b 2 // File: NOKIA_5110.h
anywill 6:7f43285de85b 3 // Author: Chris Yan
anywill 6:7f43285de85b 4 // Created: January, 2012
anywill 6:7f43285de85b 5 // Revised: January, 2014
anywill 6:7f43285de85b 6 // Desc: Commands, fonts, and class for using a
anywill 6:7f43285de85b 7 // Nokia 5110 LCD via the Phillips 8554 LCD driver.
anywill 6:7f43285de85b 8 //
anywill 6:7f43285de85b 9 // Typical Usage: User must fill the LcdPins struct with the pinout used to control the LCD and
anywill 6:7f43285de85b 10 // instantiate the NokiaLcd class - passing the created LcdPins struct to the constructor.
anywill 6:7f43285de85b 11 // The class function NokiaLcd::InitLcd may then be called to reset and start the LCD driver.
anywill 6:7f43285de85b 12 // A simple 6x6 font (6x8 in LCD space and ~5x5 character space) is included to facilitate
anywill 6:7f43285de85b 13 // the NokiaLcd::DrawChar( char character ) function, which will copy the character 8 bits
anywill 6:7f43285de85b 14 // at a time for 6 clock cycles.
anywill 6:7f43285de85b 15 // Commands may be sent to the LCD via the NokiaLcd::SendFunction(char cmd)
anywill 6:7f43285de85b 16 // function, but be aware that certain commands require the Function Set register's H-value
anywill 6:7f43285de85b 17 // to be either 1 or 0, depending on the command. This class does not check to see whether
anywill 6:7f43285de85b 18 // the H-value is of proper status. The Function Set register /may/ be changed via the
anywill 6:7f43285de85b 19 // NokiaLcd::SendFunction(char cmd), but the code uses this internally and expects that
anywill 6:7f43285de85b 20 // most function registers have not been changed by the user.
anywill 6:7f43285de85b 21 //
anywill 6:7f43285de85b 22 // Example:
anywill 6:7f43285de85b 23 // #include "mbed.h"
anywill 6:7f43285de85b 24 // #include "NOKIA_5110.h"
anywill 6:7f43285de85b 25 //
anywill 6:7f43285de85b 26 // int main() {
anywill 6:7f43285de85b 27 // LcdPins myLcdPins = { p11, NC, p13, p10, p8, p9 };
anywill 6:7f43285de85b 28 // NokiaLcd myLcd( myLcdPins ); // SPI is started here (8-bits, mode 1)
anywill 6:7f43285de85b 29 // myLcd.InitLcd(); // LCD is reset and DDRAM is cleared
anywill 6:7f43285de85b 30 // myLcd.TestLcd( 0xAA ); // Draws a vertical pattern where every other pixel is on
anywill 6:7f43285de85b 31 // wait(10);
anywill 6:7f43285de85b 32 // myLcd.ShutdownLcd(); // Clears the LCD's DDRAM and powers it down via CMD_FS_POWER_DOWN_MODE, H=0
anywill 6:7f43285de85b 33 // while(1)
anywill 6:7f43285de85b 34 // { };
anywill 6:7f43285de85b 35 // }
anywill 6:7f43285de85b 36
anywill 6:7f43285de85b 37 // Command Instructions
anywill 6:7f43285de85b 38 // H = 0
anywill 6:7f43285de85b 39 #ifndef __NOKIA_5110_H__
anywill 6:7f43285de85b 40 #define __NOKIA_5110_H__
anywill 6:7f43285de85b 41
anywill 6:7f43285de85b 42 // Command Instructions
anywill 6:7f43285de85b 43 // H = 0
anywill 6:7f43285de85b 44 #define CMD_DC_CLEAR_DISPLAY 0x08
anywill 6:7f43285de85b 45 #define CMD_DC_NORMAL_MODE 0x0C
anywill 6:7f43285de85b 46 #define CMD_DC_FILL_DISPLAY 0x09
anywill 6:7f43285de85b 47 #define CMD_DC_INVERT_VIDEO 0x0D
anywill 6:7f43285de85b 48 #define CMD_FS_HORIZONTAL_MODE 0x00
anywill 6:7f43285de85b 49 #define CMD_FS_VERTICAL_MODE 0x02
anywill 6:7f43285de85b 50 #define CMD_FS_BASIC_MODE 0x00
anywill 6:7f43285de85b 51 #define CMD_FS_EXTENDED_MODE 0x01
anywill 6:7f43285de85b 52 #define CMD_FS_ACTIVE_MODE 0x00
anywill 6:7f43285de85b 53 #define CMD_FS_POWER_DOWN_MODE 0x04
anywill 6:7f43285de85b 54 // H = 1
anywill 6:7f43285de85b 55 #define CMD_TC_TEMP_0 0x04
anywill 6:7f43285de85b 56 #define CMD_TC_TEMP_1 0x05
anywill 6:7f43285de85b 57 #define CMD_TC_TEMP_2 0x06
anywill 6:7f43285de85b 58 #define CMD_TC_TEMP_3 0x07
anywill 6:7f43285de85b 59 #define CMD_BI_MUX_24 0x15
anywill 6:7f43285de85b 60 #define CMD_BI_MUX_48 0x13
anywill 6:7f43285de85b 61 #define CMD_BI_MUX_100 0x10
anywill 6:7f43285de85b 62 #define CMD_VOP_6V06 0xB2
anywill 6:7f43285de85b 63 #define CMD_VOP_7V38 0xC8
anywill 6:7f43285de85b 64
anywill 6:7f43285de85b 65 // LCD Characteristics
anywill 6:7f43285de85b 66 #define LCD_FREQ 2000000
anywill 6:7f43285de85b 67 #define LCD_SPI_MODE 0x01
anywill 6:7f43285de85b 68 #define LCD_SPI_BITS 0x08
anywill 6:7f43285de85b 69 #define LCD_X_MAX 84
anywill 6:7f43285de85b 70 #define LCD_Y_MAX 48
anywill 6:7f43285de85b 71
anywill 6:7f43285de85b 72 #define PIN_RST 0x00
anywill 6:7f43285de85b 73 #define PIN_SCE 0x01
anywill 6:7f43285de85b 74 #define PIN_DC 0x02
anywill 6:7f43285de85b 75
anywill 6:7f43285de85b 76 #include "mbed.h"
anywill 6:7f43285de85b 77
anywill 6:7f43285de85b 78 struct LcdPins
anywill 6:7f43285de85b 79 {
anywill 6:7f43285de85b 80 PinName mosi;
anywill 6:7f43285de85b 81 PinName miso;
anywill 6:7f43285de85b 82 PinName sclk;
anywill 6:7f43285de85b 83 PinName dc;
anywill 6:7f43285de85b 84 PinName sce;
anywill 6:7f43285de85b 85 PinName rst;
anywill 6:7f43285de85b 86 };
anywill 6:7f43285de85b 87
anywill 6:7f43285de85b 88 struct LcdFunctionSet
anywill 6:7f43285de85b 89 {
anywill 6:7f43285de85b 90 char PD;
anywill 6:7f43285de85b 91 char V;
anywill 6:7f43285de85b 92 char H;
anywill 6:7f43285de85b 93 };
anywill 6:7f43285de85b 94
anywill 6:7f43285de85b 95 typedef char LcdFunctionChar;
anywill 6:7f43285de85b 96 typedef char LcdTempControl;
anywill 6:7f43285de85b 97 typedef char LcdDispControl;
anywill 6:7f43285de85b 98 typedef char LcdBiasChar;
anywill 6:7f43285de85b 99 typedef char LcdVopChar;
anywill 6:7f43285de85b 100
anywill 6:7f43285de85b 101 class NokiaLcd
anywill 6:7f43285de85b 102 {
anywill 6:7f43285de85b 103 public:
anywill 6:7f43285de85b 104 NokiaLcd(LcdPins lcd_pinout);
anywill 6:7f43285de85b 105 ~NokiaLcd();
anywill 6:7f43285de85b 106
anywill 6:7f43285de85b 107 public:
anywill 6:7f43285de85b 108 void InitLcd();
anywill 6:7f43285de85b 109 void ClearLcdMem();
anywill 6:7f43285de85b 110 void ShutdownLcd();
anywill 6:7f43285de85b 111 void SendFunction(char cmd);
anywill 6:7f43285de85b 112 void TestLcd(char test_pattern);
anywill 6:7f43285de85b 113 void SendDrawData(char data);
anywill 6:7f43285de85b 114
anywill 6:7f43285de85b 115 public:
anywill 6:7f43285de85b 116 void DrawString(char* str);
anywill 6:7f43285de85b 117 void DrawChar(char character);
anywill 6:7f43285de85b 118 void SetXY(char x, char y);
anywill 6:7f43285de85b 119 void DrawFrameChar(char character);
anywill 6:7f43285de85b 120 void DrawNegFrameChar(char character);
anywill 6:7f43285de85b 121 char* NumToStr(int num);
anywill 6:7f43285de85b 122
anywill 6:7f43285de85b 123 private:
anywill 6:7f43285de85b 124 char CreateFunctionChar();
anywill 6:7f43285de85b 125 void ResetLcd();
anywill 6:7f43285de85b 126
anywill 6:7f43285de85b 127 private:
anywill 6:7f43285de85b 128 LcdFunctionChar FunctionChar;
anywill 6:7f43285de85b 129 LcdTempControl TempControlChar;
anywill 6:7f43285de85b 130 LcdDispControl DispControlChar;
anywill 6:7f43285de85b 131 LcdFunctionSet FunctionSet;
anywill 6:7f43285de85b 132 LcdBiasChar BiasChar;
anywill 6:7f43285de85b 133 LcdVopChar VopChar;
anywill 6:7f43285de85b 134 DigitalOut** Pins;
anywill 6:7f43285de85b 135 SPI* LcdSpi;
anywill 6:7f43285de85b 136
anywill 6:7f43285de85b 137 };
anywill 6:7f43285de85b 138
anywill 6:7f43285de85b 139 const char FONT_6x6[570] = //should be 564 total char
anywill 6:7f43285de85b 140 {
anywill 6:7f43285de85b 141 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // SPACE 1
anywill 6:7f43285de85b 142 0x00, 0x06, 0x2F, 0x06, 0x00, 0x00, // ! 2
anywill 6:7f43285de85b 143 0x00, 0x06, 0x00, 0x06, 0x00, 0x00, // " 3
anywill 6:7f43285de85b 144 0x14, 0x3E, 0x14, 0x3E, 0x14, 0x00, // # 4
anywill 6:7f43285de85b 145 0x2E, 0x2A, 0x3F, 0x2A, 0x3A, 0x00, // $ 5
anywill 6:7f43285de85b 146 0x26, 0x16, 0x08, 0x34, 0x32, 0x00, // % 6
anywill 6:7f43285de85b 147 0x34, 0x2A, 0x3C, 0x18, 0x28, 0x00, // & 7
anywill 6:7f43285de85b 148 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, // ' 8
anywill 6:7f43285de85b 149 0x00, 0x00, 0x1C, 0x36, 0x22, 0x00, // ( 9
anywill 6:7f43285de85b 150 0x22, 0x36, 0x1C, 0x00, 0x00, 0x00, // ) 10
anywill 6:7f43285de85b 151 0x24, 0x18, 0x0E, 0x18, 0x24, 0x00, // * 11
anywill 6:7f43285de85b 152 0x08, 0x08, 0x3E, 0x08, 0x08, 0x00, // + 12
anywill 6:7f43285de85b 153 0x20, 0x30, 0x00, 0x00, 0x00, 0x00, // , 13
anywill 6:7f43285de85b 154 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, // - 14
anywill 6:7f43285de85b 155 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, // . 15
anywill 6:7f43285de85b 156 0x30, 0x18, 0x0C, 0x06, 0x00, 0x00, // / 16
anywill 6:7f43285de85b 157 0x00, 0x1C, 0x22, 0x22, 0x1C, 0x00, // 0 17
anywill 6:7f43285de85b 158 0x00, 0x24, 0x3E, 0x20, 0x00, 0x00, // 1 18
anywill 6:7f43285de85b 159 0x3A, 0x2A, 0x2A, 0x2A, 0x2E, 0x00, // 2 19
anywill 6:7f43285de85b 160 0x22, 0x2A, 0x2A, 0x2A, 0x3E, 0x00, // 3 20
anywill 6:7f43285de85b 161 0x0E, 0x08, 0x08, 0x3E, 0x08, 0x00, // 4 21
anywill 6:7f43285de85b 162 0x2E, 0x2A, 0x2A, 0x2A, 0x3A, 0x00, // 5 22
anywill 6:7f43285de85b 163 0x3E, 0x2A, 0x2A, 0x2A, 0x3A, 0x00, // 6 23
anywill 6:7f43285de85b 164 0x22, 0x12, 0x0A, 0x06, 0x02, 0x00, // 7 24
anywill 6:7f43285de85b 165 0x3E, 0x2A, 0x2A, 0x2A, 0x3E, 0x00, // 8 25
anywill 6:7f43285de85b 166 0x00, 0x2E, 0x2A, 0x2A, 0x3E, 0x00, // 9 26
anywill 6:7f43285de85b 167 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, // : 27
anywill 6:7f43285de85b 168 0x00, 0x20, 0x14, 0x00, 0x00, 0x00, // ; 28
anywill 6:7f43285de85b 169 0x00, 0x00, 0x08, 0x14, 0x22, 0x00, // < 29
anywill 6:7f43285de85b 170 0x14, 0x14, 0x14, 0x14, 0x14, 0x00, // = 30
anywill 6:7f43285de85b 171 0x22, 0x14, 0x08, 0x00, 0x00, 0x00, // > 31
anywill 6:7f43285de85b 172 0x06, 0x01, 0x2D, 0x06, 0x00, 0x00, // ? 32
anywill 6:7f43285de85b 173 0x1E, 0x23, 0x19, 0x35, 0x3E, 0x00, // @ 33
anywill 6:7f43285de85b 174 0x3C, 0x0A, 0x0A, 0x0A, 0x3C, 0x00, // A 34
anywill 6:7f43285de85b 175 0x3E, 0x2A, 0x2A, 0x2A, 0x1C, 0x00, // B 35
anywill 6:7f43285de85b 176 0x1C, 0x22, 0x22, 0x22, 0x22, 0x00, // C 36
anywill 6:7f43285de85b 177 0x3E, 0x22, 0x22, 0x22, 0x1C, 0x00, // D 37
anywill 6:7f43285de85b 178 0x3E, 0x2A, 0x2A, 0x2A, 0x22, 0x00, // E 38
anywill 6:7f43285de85b 179 0x3E, 0x0A, 0x0A, 0x0A, 0x02, 0x00, // F 39
anywill 6:7f43285de85b 180 0x1C, 0x22, 0x2A, 0x2A, 0x18, 0x00, // G 40
anywill 6:7f43285de85b 181 0x3E, 0x08, 0x08, 0x08, 0x3E, 0x00, // H
anywill 6:7f43285de85b 182 0x22, 0x22, 0x3E, 0x22, 0x22, 0x00, // I
anywill 6:7f43285de85b 183 0x10, 0x22, 0x22, 0x1E, 0x02, 0x00, // J
anywill 6:7f43285de85b 184 0x3E, 0x08, 0x14, 0x22, 0x00, 0x00, // K
anywill 6:7f43285de85b 185 0x00, 0x3E, 0x20, 0x20, 0x20, 0x00, // L 45
anywill 6:7f43285de85b 186 0x3E, 0x04, 0x08, 0x04, 0x3E, 0x00, // M
anywill 6:7f43285de85b 187 0x3C, 0x02, 0x02, 0x02, 0x3C, 0x00, // N
anywill 6:7f43285de85b 188 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x00, // O
anywill 6:7f43285de85b 189 0x3E, 0x0A, 0x0A, 0x04, 0x00, 0x00, // P
anywill 6:7f43285de85b 190 0x1C, 0x22, 0x32, 0x3C, 0x20, 0x00, // Q 50
anywill 6:7f43285de85b 191 0x3E, 0x0A, 0x0A, 0x1A, 0x24, 0x00, // R
anywill 6:7f43285de85b 192 0x24, 0x2A, 0x2A, 0x2A, 0x12, 0x00, // S
anywill 6:7f43285de85b 193 0x02, 0x02, 0x3E, 0x02, 0x02, 0x00, // T
anywill 6:7f43285de85b 194 0x1E, 0x20, 0x20, 0x20, 0x1E, 0x00, // U
anywill 6:7f43285de85b 195 0x06, 0x18, 0x20, 0x18, 0x06, 0x00, // V 55
anywill 6:7f43285de85b 196 0x0E, 0x30, 0x18, 0x30, 0x0E, 0x00, // W
anywill 6:7f43285de85b 197 0x22, 0x14, 0x08, 0x14, 0x22, 0x00, // X
anywill 6:7f43285de85b 198 0x02, 0x04, 0x38, 0x04, 0x02, 0x00, // Y
anywill 6:7f43285de85b 199 0x22, 0x32, 0x2A, 0x26, 0x22, 0x00, // Z
anywill 6:7f43285de85b 200 0x00, 0x00, 0x00, 0x3E, 0x22, 0x00, // [ 60
anywill 6:7f43285de85b 201 0x06, 0x0C, 0x18, 0x30, 0x00, 0x00, // backslash
anywill 6:7f43285de85b 202 0x22, 0x3E, 0x00, 0x00, 0x00, 0x00, // ]
anywill 6:7f43285de85b 203 0x00, 0x04, 0x02, 0x02, 0x04, 0x00, // ^
anywill 6:7f43285de85b 204 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, // _
anywill 6:7f43285de85b 205 0x00, 0x00, 0x04, 0x08, 0x00, 0x00, // ` 65
anywill 6:7f43285de85b 206 0x18, 0x24, 0x14, 0x38, 0x00, 0x00, // a
anywill 6:7f43285de85b 207 0x1E, 0x28, 0x28, 0x10, 0x00, 0x00, // b
anywill 6:7f43285de85b 208 0x18, 0x24, 0x24, 0x00, 0x00, 0x00, // c
anywill 6:7f43285de85b 209 0x10, 0x28, 0x28, 0x1E, 0x00, 0x00, // d
anywill 6:7f43285de85b 210 0x18, 0x2C, 0x2C, 0x08, 0x00, 0x00, // e 70
anywill 6:7f43285de85b 211 0x00, 0x3C, 0x12, 0x04, 0x00, 0x00, // f
anywill 6:7f43285de85b 212 0x24, 0x2A, 0x1E, 0x00, 0x00, 0x00, // g
anywill 6:7f43285de85b 213 0x3E, 0x08, 0x30, 0x00, 0x00, 0x00, // h
anywill 6:7f43285de85b 214 0x00, 0x3A, 0x00, 0x00, 0x00, 0x00, // i
anywill 6:7f43285de85b 215 0x10, 0x20, 0x1A, 0x00, 0x00, 0x00, // j 75
anywill 6:7f43285de85b 216 0x3E, 0x10, 0x2C, 0x20, 0x00, 0x00, // k
anywill 6:7f43285de85b 217 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00, // l
anywill 6:7f43285de85b 218 0x38, 0x08, 0x18, 0x08, 0x30, 0x00, // m
anywill 6:7f43285de85b 219 0x30, 0x08, 0x08, 0x30, 0x00, 0x00, // n
anywill 6:7f43285de85b 220 0x10, 0x28, 0x28, 0x10, 0x00, 0x00, // o 80
anywill 6:7f43285de85b 221 0x38, 0x14, 0x14, 0x08, 0x00, 0x00, // p
anywill 6:7f43285de85b 222 0x08, 0x14, 0x14, 0x38, 0x00, 0x00, // q
anywill 6:7f43285de85b 223 0x3C, 0x08, 0x04, 0x00, 0x00, 0x00, // r
anywill 6:7f43285de85b 224 0x2C, 0x34, 0x00, 0x00, 0x00, 0x00, // s
anywill 6:7f43285de85b 225 0x08, 0x3C, 0x28, 0x00, 0x00, 0x00, // t 85
anywill 6:7f43285de85b 226 0x18, 0x20, 0x20, 0x18, 0x00, 0x00, // u
anywill 6:7f43285de85b 227 0x08, 0x10, 0x20, 0x10, 0x08, 0x00, // v
anywill 6:7f43285de85b 228 0x18, 0x20, 0x10, 0x20, 0x18, 0x00, // w
anywill 6:7f43285de85b 229 0x28, 0x10, 0x28, 0x00, 0x00, 0x00, // x
anywill 6:7f43285de85b 230 0x2C, 0x30, 0x1C, 0x00, 0x00, 0x00, // y 90
anywill 6:7f43285de85b 231 0x24, 0x34, 0x2C, 0x24, 0x00, 0x00, // z
anywill 6:7f43285de85b 232 0x00, 0x00, 0x08, 0x3E, 0x22, 0x00, // {
anywill 6:7f43285de85b 233 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, // |
anywill 6:7f43285de85b 234 0x22, 0x3E, 0x08, 0x00, 0x00, 0x00, // }
anywill 6:7f43285de85b 235 0x10, 0x08, 0x18, 0x10, 0x08, 0x00, // ~ 95
anywill 6:7f43285de85b 236 };
anywill 6:7f43285de85b 237
anywill 6:7f43285de85b 238 #endif