Bitmap_draw added

Dependents:   NOKIA_KOMBAT

Committer:
bengisuakyurek
Date:
Mon May 27 14:53:21 2019 +0000
Revision:
1:73f226b84b70
Parent:
0:9cfce382e741
I added draw_bitmap method

Who changed what in which revision?

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