V1.0: A simple lib to driver the nokia 5110 lcd. You can select the soft/hardware spi ports by define the HW_SPI word from the "sx5110.h ".

Committer:
shower_xu
Date:
Thu Jan 08 08:04:43 2015 +0000
Revision:
0:ab1ca9a3e847
V1.0: This lib can driver the nokia 5110 lcd by soft-SPI or hardware-SPI; Just need define the HW_SPI word in the sx5110.h

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shower_xu 0:ab1ca9a3e847 1 #ifndef _SX5110_H
shower_xu 0:ab1ca9a3e847 2 #define _SX5110_H
shower_xu 0:ab1ca9a3e847 3 #include "mbed.h"
shower_xu 0:ab1ca9a3e847 4
shower_xu 0:ab1ca9a3e847 5 #define HW_SPI
shower_xu 0:ab1ca9a3e847 6
shower_xu 0:ab1ca9a3e847 7 // LCD define
shower_xu 0:ab1ca9a3e847 8 #define LCD_FREQ 2000000
shower_xu 0:ab1ca9a3e847 9 #define LCD_SPI_MODE 0x03
shower_xu 0:ab1ca9a3e847 10 #define LCD_SPI_BITS 0x08
shower_xu 0:ab1ca9a3e847 11 #define LCD_X_MAX 84
shower_xu 0:ab1ca9a3e847 12 #define LCD_Y_MAX 6
shower_xu 0:ab1ca9a3e847 13
shower_xu 0:ab1ca9a3e847 14 #define PIN_RST 0x00
shower_xu 0:ab1ca9a3e847 15 #define PIN_SCE 0x01
shower_xu 0:ab1ca9a3e847 16 #define PIN_DC 0x02
shower_xu 0:ab1ca9a3e847 17
shower_xu 0:ab1ca9a3e847 18 #ifndef HW_SPI
shower_xu 0:ab1ca9a3e847 19 #define PIN_MOSI 0x00
shower_xu 0:ab1ca9a3e847 20 #define PIN_SCLK 0x01
shower_xu 0:ab1ca9a3e847 21 #endif
shower_xu 0:ab1ca9a3e847 22 struct LcdPins
shower_xu 0:ab1ca9a3e847 23 {
shower_xu 0:ab1ca9a3e847 24 PinName mosi;
shower_xu 0:ab1ca9a3e847 25 PinName sclk;
shower_xu 0:ab1ca9a3e847 26 PinName dc;
shower_xu 0:ab1ca9a3e847 27 PinName sce;
shower_xu 0:ab1ca9a3e847 28 PinName rst;
shower_xu 0:ab1ca9a3e847 29 };
shower_xu 0:ab1ca9a3e847 30
shower_xu 0:ab1ca9a3e847 31 class Lcd5110
shower_xu 0:ab1ca9a3e847 32 {
shower_xu 0:ab1ca9a3e847 33 public:
shower_xu 0:ab1ca9a3e847 34 Lcd5110(LcdPins lcd_pinout);
shower_xu 0:ab1ca9a3e847 35 ~Lcd5110();
shower_xu 0:ab1ca9a3e847 36
shower_xu 0:ab1ca9a3e847 37 public:
shower_xu 0:ab1ca9a3e847 38 void InitLcd();
shower_xu 0:ab1ca9a3e847 39 void clear();
shower_xu 0:ab1ca9a3e847 40 void ShutdownLcd();
shower_xu 0:ab1ca9a3e847 41 void SendCmd(char cmd);
shower_xu 0:ab1ca9a3e847 42 void SendData(char data);
shower_xu 0:ab1ca9a3e847 43 void TestLcd(char test_pattern);
shower_xu 0:ab1ca9a3e847 44
shower_xu 0:ab1ca9a3e847 45 public:
shower_xu 0:ab1ca9a3e847 46 void SetXY(char x, char y);
shower_xu 0:ab1ca9a3e847 47 void write_char(char c);
shower_xu 0:ab1ca9a3e847 48 void set_xy(unsigned char x,unsigned char y);
shower_xu 0:ab1ca9a3e847 49 void write_stringxy(unsigned char x,unsigned char y,char *p);
shower_xu 0:ab1ca9a3e847 50 void write_string(char *p);
shower_xu 0:ab1ca9a3e847 51 char* NumToStr(int num);
shower_xu 0:ab1ca9a3e847 52
shower_xu 0:ab1ca9a3e847 53 private:
shower_xu 0:ab1ca9a3e847 54 void ResetLcd();
shower_xu 0:ab1ca9a3e847 55
shower_xu 0:ab1ca9a3e847 56 private:
shower_xu 0:ab1ca9a3e847 57 #ifndef HW_SPI
shower_xu 0:ab1ca9a3e847 58 DigitalOut** SPins;
shower_xu 0:ab1ca9a3e847 59 #else
shower_xu 0:ab1ca9a3e847 60 SPI* LcdSpi;
shower_xu 0:ab1ca9a3e847 61 #endif
shower_xu 0:ab1ca9a3e847 62 DigitalOut** Pins;
shower_xu 0:ab1ca9a3e847 63
shower_xu 0:ab1ca9a3e847 64
shower_xu 0:ab1ca9a3e847 65 };
shower_xu 0:ab1ca9a3e847 66
shower_xu 0:ab1ca9a3e847 67 /*-----------------------------------------------
shower_xu 0:ab1ca9a3e847 68 6 x 8 font
shower_xu 0:ab1ca9a3e847 69 1 pixel space at left and bottom
shower_xu 0:ab1ca9a3e847 70 index = ASCII - 32 按ASCII-32排列的
shower_xu 0:ab1ca9a3e847 71 -----------------------------------------------*/
shower_xu 0:ab1ca9a3e847 72 const unsigned char ASCII[][6] =
shower_xu 0:ab1ca9a3e847 73 {
shower_xu 0:ab1ca9a3e847 74 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },// sp
shower_xu 0:ab1ca9a3e847 75 { 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00 },// !
shower_xu 0:ab1ca9a3e847 76 { 0x00, 0x00, 0x07, 0x00, 0x07, 0x00 },// "
shower_xu 0:ab1ca9a3e847 77 { 0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14 },// #
shower_xu 0:ab1ca9a3e847 78 { 0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12 },// $
shower_xu 0:ab1ca9a3e847 79 { 0x23, 0x13, 0x08, 0x64, 0x62, 0x00 },// %
shower_xu 0:ab1ca9a3e847 80 { 0x00, 0x36, 0x49, 0x55, 0x22, 0x50 },// &
shower_xu 0:ab1ca9a3e847 81 { 0x00, 0x00, 0x05, 0x03, 0x00, 0x00 },// '
shower_xu 0:ab1ca9a3e847 82 { 0x00, 0x00, 0x1c, 0x22, 0x41, 0x00 },// (
shower_xu 0:ab1ca9a3e847 83 { 0x00, 0x00, 0x41, 0x22, 0x1c, 0x00 },// )
shower_xu 0:ab1ca9a3e847 84 { 0x00, 0x14, 0x08, 0x3E, 0x08, 0x14 },// *
shower_xu 0:ab1ca9a3e847 85 { 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08 },// +
shower_xu 0:ab1ca9a3e847 86 { 0x00, 0x00, 0x00, 0xA0, 0x60, 0x00 },// ,
shower_xu 0:ab1ca9a3e847 87 { 0x00, 0x08, 0x08, 0x08, 0x08, 0x08 },// -
shower_xu 0:ab1ca9a3e847 88 { 0x00, 0x00, 0x60, 0x60, 0x00, 0x00 },// .
shower_xu 0:ab1ca9a3e847 89 { 0x00, 0x20, 0x10, 0x08, 0x04, 0x02 },// /
shower_xu 0:ab1ca9a3e847 90 { 0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E },// 0
shower_xu 0:ab1ca9a3e847 91 { 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00 },// 1
shower_xu 0:ab1ca9a3e847 92 { 0x00, 0x42, 0x61, 0x51, 0x49, 0x46 },// 2
shower_xu 0:ab1ca9a3e847 93 { 0x00, 0x21, 0x41, 0x45, 0x4B, 0x31 },// 3
shower_xu 0:ab1ca9a3e847 94 { 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10 },// 4
shower_xu 0:ab1ca9a3e847 95 { 0x00, 0x27, 0x45, 0x45, 0x45, 0x39 },// 5
shower_xu 0:ab1ca9a3e847 96 { 0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30 },// 6
shower_xu 0:ab1ca9a3e847 97 { 0x00, 0x01, 0x71, 0x09, 0x05, 0x03 },// 7
shower_xu 0:ab1ca9a3e847 98 { 0x00, 0x36, 0x49, 0x49, 0x49, 0x36 },// 8
shower_xu 0:ab1ca9a3e847 99 { 0x00, 0x06, 0x49, 0x49, 0x29, 0x1E },// 9
shower_xu 0:ab1ca9a3e847 100 { 0x00, 0x00, 0x36, 0x36, 0x00, 0x00 },// :
shower_xu 0:ab1ca9a3e847 101 { 0x00, 0x00, 0x56, 0x36, 0x00, 0x00 },// ;
shower_xu 0:ab1ca9a3e847 102 { 0x00, 0x08, 0x14, 0x22, 0x41, 0x00 },// <
shower_xu 0:ab1ca9a3e847 103 { 0x00, 0x14, 0x14, 0x14, 0x14, 0x14 },// =
shower_xu 0:ab1ca9a3e847 104 { 0x00, 0x00, 0x41, 0x22, 0x14, 0x08 },// >
shower_xu 0:ab1ca9a3e847 105 { 0x00, 0x02, 0x01, 0x51, 0x09, 0x06 },// ?
shower_xu 0:ab1ca9a3e847 106 { 0x00, 0x32, 0x49, 0x59, 0x51, 0x3E },// @
shower_xu 0:ab1ca9a3e847 107 { 0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C },// A
shower_xu 0:ab1ca9a3e847 108 { 0x00, 0x7F, 0x49, 0x49, 0x49, 0x36 },// B
shower_xu 0:ab1ca9a3e847 109 { 0x00, 0x3E, 0x41, 0x41, 0x41, 0x22 },// C
shower_xu 0:ab1ca9a3e847 110 { 0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C },// D
shower_xu 0:ab1ca9a3e847 111 { 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41 },// E
shower_xu 0:ab1ca9a3e847 112 { 0x00, 0x7F, 0x09, 0x09, 0x09, 0x01 },// F
shower_xu 0:ab1ca9a3e847 113 { 0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A },// G
shower_xu 0:ab1ca9a3e847 114 { 0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F },// H
shower_xu 0:ab1ca9a3e847 115 { 0x00, 0x00, 0x41, 0x7F, 0x41, 0x00 },// I
shower_xu 0:ab1ca9a3e847 116 { 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01 },// J
shower_xu 0:ab1ca9a3e847 117 { 0x00, 0x7F, 0x08, 0x14, 0x22, 0x41 },// K
shower_xu 0:ab1ca9a3e847 118 { 0x00, 0x7F, 0x40, 0x40, 0x40, 0x40 },// L
shower_xu 0:ab1ca9a3e847 119 { 0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F },// M
shower_xu 0:ab1ca9a3e847 120 { 0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F },// N
shower_xu 0:ab1ca9a3e847 121 { 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E },// O
shower_xu 0:ab1ca9a3e847 122 { 0x00, 0x7F, 0x09, 0x09, 0x09, 0x06 },// P
shower_xu 0:ab1ca9a3e847 123 { 0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E },// Q
shower_xu 0:ab1ca9a3e847 124 { 0x00, 0x7F, 0x09, 0x19, 0x29, 0x46 },// R
shower_xu 0:ab1ca9a3e847 125 { 0x00, 0x46, 0x49, 0x49, 0x49, 0x31 },// S
shower_xu 0:ab1ca9a3e847 126 { 0x00, 0x01, 0x01, 0x7F, 0x01, 0x01 },// T
shower_xu 0:ab1ca9a3e847 127 { 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F },// U
shower_xu 0:ab1ca9a3e847 128 { 0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F },// V
shower_xu 0:ab1ca9a3e847 129 { 0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F },// W
shower_xu 0:ab1ca9a3e847 130 { 0x00, 0x63, 0x14, 0x08, 0x14, 0x63 },// X
shower_xu 0:ab1ca9a3e847 131 { 0x00, 0x07, 0x08, 0x70, 0x08, 0x07 },// Y
shower_xu 0:ab1ca9a3e847 132 { 0x00, 0x61, 0x51, 0x49, 0x45, 0x43 },// Z
shower_xu 0:ab1ca9a3e847 133 { 0x00, 0x00, 0x7F, 0x41, 0x41, 0x00 },// [
shower_xu 0:ab1ca9a3e847 134 { 0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55 },// 55
shower_xu 0:ab1ca9a3e847 135 { 0x00, 0x00, 0x41, 0x41, 0x7F, 0x00 },// ]
shower_xu 0:ab1ca9a3e847 136 { 0x00, 0x04, 0x02, 0x01, 0x02, 0x04 },// ^
shower_xu 0:ab1ca9a3e847 137 { 0x00, 0x40, 0x40, 0x40, 0x40, 0x40 },// _
shower_xu 0:ab1ca9a3e847 138 { 0x00, 0x00, 0x01, 0x02, 0x04, 0x00 },// '
shower_xu 0:ab1ca9a3e847 139 { 0x00, 0x20, 0x54, 0x54, 0x54, 0x78 },// a
shower_xu 0:ab1ca9a3e847 140 { 0x00, 0x7F, 0x48, 0x44, 0x44, 0x38 },// b
shower_xu 0:ab1ca9a3e847 141 { 0x00, 0x38, 0x44, 0x44, 0x44, 0x20 },// c
shower_xu 0:ab1ca9a3e847 142 { 0x00, 0x38, 0x44, 0x44, 0x48, 0x7F },// d
shower_xu 0:ab1ca9a3e847 143 { 0x00, 0x38, 0x54, 0x54, 0x54, 0x18 },// e
shower_xu 0:ab1ca9a3e847 144 { 0x00, 0x08, 0x7E, 0x09, 0x01, 0x02 },// f
shower_xu 0:ab1ca9a3e847 145 { 0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C },// g
shower_xu 0:ab1ca9a3e847 146 { 0x00, 0x7F, 0x08, 0x04, 0x04, 0x78 },// h
shower_xu 0:ab1ca9a3e847 147 { 0x00, 0x00, 0x44, 0x7D, 0x40, 0x00 },// i
shower_xu 0:ab1ca9a3e847 148 { 0x00, 0x40, 0x80, 0x84, 0x7D, 0x00 },// j
shower_xu 0:ab1ca9a3e847 149 { 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00 },// k
shower_xu 0:ab1ca9a3e847 150 { 0x00, 0x00, 0x41, 0x7F, 0x40, 0x00 },// l
shower_xu 0:ab1ca9a3e847 151 { 0x00, 0x7C, 0x04, 0x18, 0x04, 0x78 },// m
shower_xu 0:ab1ca9a3e847 152 { 0x00, 0x7C, 0x08, 0x04, 0x04, 0x78 },// n
shower_xu 0:ab1ca9a3e847 153 { 0x00, 0x38, 0x44, 0x44, 0x44, 0x38 },// o
shower_xu 0:ab1ca9a3e847 154 { 0x00, 0xFC, 0x24, 0x24, 0x24, 0x18 },// p
shower_xu 0:ab1ca9a3e847 155 { 0x00, 0x18, 0x24, 0x24, 0x18, 0xFC },// q
shower_xu 0:ab1ca9a3e847 156 { 0x00, 0x7C, 0x08, 0x04, 0x04, 0x08 },// r
shower_xu 0:ab1ca9a3e847 157 { 0x00, 0x48, 0x54, 0x54, 0x54, 0x20 },// s
shower_xu 0:ab1ca9a3e847 158 { 0x00, 0x04, 0x3F, 0x44, 0x40, 0x20 },// t
shower_xu 0:ab1ca9a3e847 159 { 0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C },// u
shower_xu 0:ab1ca9a3e847 160 { 0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C },// v
shower_xu 0:ab1ca9a3e847 161 { 0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C },// w
shower_xu 0:ab1ca9a3e847 162 { 0x00, 0x44, 0x28, 0x10, 0x28, 0x44 },// x
shower_xu 0:ab1ca9a3e847 163 { 0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C },// y
shower_xu 0:ab1ca9a3e847 164 { 0x00, 0x44, 0x64, 0x54, 0x4C, 0x44 },// z
shower_xu 0:ab1ca9a3e847 165 { 0x14, 0x14, 0x14, 0x14, 0x14, 0x14 }// horiz lines
shower_xu 0:ab1ca9a3e847 166 };
shower_xu 0:ab1ca9a3e847 167
shower_xu 0:ab1ca9a3e847 168 #endif