light text library for 5110 nokia lcd * easy to modify * proportional font, bold / inverse modes * easy to add / change fonts * fixed rows for fast update
Library finished! :-) If you use 5110 and need fast menus - try this library. No overhead - small and robust, optimized for this display type only, fast update. Nice looking font. Power management. Displays from 5110 and 3110 are cheap as dirt :-)
medvdv5110.cpp@1:cce4622d70f6, 2012-09-25 (annotated)
- Committer:
- medvdv
- Date:
- Tue Sep 25 16:03:34 2012 +0000
- Revision:
- 1:cce4622d70f6
- Parent:
- 0:0a6619901f2e
- Child:
- 2:65df20ffef51
publish, no comments yet
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
medvdv | 0:0a6619901f2e | 1 | // |
medvdv | 0:0a6619901f2e | 2 | // 5110 LCD Driver |
medvdv | 1:cce4622d70f6 | 3 | // (c) 2012 medvdv.com |
medvdv | 0:0a6619901f2e | 4 | // Alexander Medvedev |
medvdv | 0:0a6619901f2e | 5 | // |
medvdv | 0:0a6619901f2e | 6 | |
medvdv | 0:0a6619901f2e | 7 | #include "mbed.h" |
medvdv | 0:0a6619901f2e | 8 | #include "medvdv5110.h" |
medvdv | 0:0a6619901f2e | 9 | |
medvdv | 1:cce4622d70f6 | 10 | const char lcd_font8p_widths[] = { |
medvdv | 1:cce4622d70f6 | 11 | 2, 1, 3, 5, 5, 5, 5, 1, 2, 2, 5, 5, 4, |
medvdv | 1:cce4622d70f6 | 12 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 6, 5, 6, 5, 6, 5, 5, 5, 5, 5, 5, 5, 5, 3, |
medvdv | 0:0a6619901f2e | 13 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, |
medvdv | 1:cce4622d70f6 | 14 | 1, 3, 4, 1, 5, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 4, 4, 4, 2, 4, 5, 4 |
medvdv | 1:cce4622d70f6 | 15 | }; |
medvdv | 0:0a6619901f2e | 16 | |
medvdv | 0:0a6619901f2e | 17 | const char* lcd_font8p[] = { |
medvdv | 1:cce4622d70f6 | 18 | (const char[]){ 0x00, 0x00 }, |
medvdv | 1:cce4622d70f6 | 19 | (const char[]){ 0x2F }, |
medvdv | 1:cce4622d70f6 | 20 | (const char[]){ 0x03, 0x00, 0x03 }, |
medvdv | 1:cce4622d70f6 | 21 | (const char[]){ 0x14, 0x3E, 0x14, 0x3E, 0x14 }, |
medvdv | 1:cce4622d70f6 | 22 | (const char[]){ 0x24, 0x6A, 0x3E, 0x2B, 0x12 }, |
medvdv | 1:cce4622d70f6 | 23 | (const char[]){ 0x22, 0x10, 0x08, 0x04, 0x22 }, |
medvdv | 1:cce4622d70f6 | 24 | (const char[]){ 0x14, 0x2A, 0x2A, 0x14, 0x20 }, |
medvdv | 1:cce4622d70f6 | 25 | (const char[]){ 0x03 }, |
medvdv | 1:cce4622d70f6 | 26 | (const char[]){ 0x1E, 0x21 }, |
medvdv | 1:cce4622d70f6 | 27 | (const char[]){ 0x21, 0x1E }, |
medvdv | 1:cce4622d70f6 | 28 | (const char[]){ 0x14, 0x08, 0x3E, 0x08, 0x14 }, |
medvdv | 1:cce4622d70f6 | 29 | (const char[]){ 0x08, 0x08, 0x3E, 0x08, 0x08 }, |
medvdv | 1:cce4622d70f6 | 30 | (const char[]){ 0x00, 0x80, 0x70, 0x30 }, |
medvdv | 1:cce4622d70f6 | 31 | (const char[]){ 0x08, 0x08, 0x08, 0x08, 0x08 }, |
medvdv | 1:cce4622d70f6 | 32 | (const char[]){ 0x00, 0x00, 0x30, 0x30, 0x00 }, |
medvdv | 1:cce4622d70f6 | 33 | (const char[]){ 0x20, 0x10, 0x08, 0x04, 0x02 }, |
medvdv | 1:cce4622d70f6 | 34 | (const char[]){ 0x1E, 0x31, 0x2D, 0x23, 0x1E }, |
medvdv | 1:cce4622d70f6 | 35 | (const char[]){ 0x00, 0x00, 0x02, 0x3F, 0x00 }, |
medvdv | 1:cce4622d70f6 | 36 | (const char[]){ 0x22, 0x31, 0x29, 0x25, 0x22 }, |
medvdv | 1:cce4622d70f6 | 37 | (const char[]){ 0x12, 0x21, 0x25, 0x25, 0x1A }, |
medvdv | 1:cce4622d70f6 | 38 | (const char[]){ 0x18, 0x14, 0x12, 0x3F, 0x10 }, |
medvdv | 1:cce4622d70f6 | 39 | (const char[]){ 0x17, 0x25, 0x25, 0x25, 0x19 }, |
medvdv | 1:cce4622d70f6 | 40 | (const char[]){ 0x1E, 0x25, 0x25, 0x25, 0x18 }, |
medvdv | 1:cce4622d70f6 | 41 | (const char[]){ 0x01, 0x01, 0x39, 0x05, 0x03 }, |
medvdv | 1:cce4622d70f6 | 42 | (const char[]){ 0x1A, 0x25, 0x25, 0x25, 0x1A }, |
medvdv | 1:cce4622d70f6 | 43 | (const char[]){ 0x06, 0x29, 0x29, 0x29, 0x1E }, |
medvdv | 1:cce4622d70f6 | 44 | (const char[]){ 0x00, 0x00, 0x36, 0x36 }, |
medvdv | 1:cce4622d70f6 | 45 | (const char[]){ 0x00, 0x80, 0x76, 0x36 }, |
medvdv | 1:cce4622d70f6 | 46 | (const char[]){ 0x08, 0x08, 0x14, 0x14, 0x22, 0x22 }, |
medvdv | 1:cce4622d70f6 | 47 | (const char[]){ 0x14, 0x14, 0x14, 0x14, 0x14 }, |
medvdv | 1:cce4622d70f6 | 48 | (const char[]){ 0x22, 0x22, 0x14, 0x14, 0x08, 0x08 }, |
medvdv | 1:cce4622d70f6 | 49 | (const char[]){ 0x02, 0x01, 0x29, 0x05, 0x02 }, |
medvdv | 1:cce4622d70f6 | 50 | (const char[]){ 0x3E, 0x41, 0x5D, 0x55, 0x5E, 0x20 }, |
medvdv | 1:cce4622d70f6 | 51 | (const char[]){ 0x3E, 0x09, 0x09, 0x09, 0x3E }, |
medvdv | 1:cce4622d70f6 | 52 | (const char[]){ 0x3F, 0x25, 0x25, 0x25, 0x1A }, |
medvdv | 1:cce4622d70f6 | 53 | (const char[]){ 0x1E, 0x21, 0x21, 0x21, 0x12 }, |
medvdv | 1:cce4622d70f6 | 54 | (const char[]){ 0x3F, 0x21, 0x21, 0x22, 0x1C }, |
medvdv | 1:cce4622d70f6 | 55 | (const char[]){ 0x3F, 0x25, 0x25, 0x25, 0x21 }, |
medvdv | 1:cce4622d70f6 | 56 | (const char[]){ 0x3F, 0x05, 0x05, 0x05, 0x01 }, |
medvdv | 1:cce4622d70f6 | 57 | (const char[]){ 0x1E, 0x21, 0x21, 0x29, 0x1A }, |
medvdv | 1:cce4622d70f6 | 58 | (const char[]){ 0x3F, 0x04, 0x04, 0x04, 0x3F }, |
medvdv | 1:cce4622d70f6 | 59 | (const char[]){ 0x21, 0x3F, 0x21 }, |
medvdv | 1:cce4622d70f6 | 60 | (const char[]){ 0x18, 0x20, 0x21, 0x1F, 0x01 }, |
medvdv | 1:cce4622d70f6 | 61 | (const char[]){ 0x3F, 0x04, 0x04, 0x0A, 0x31 }, |
medvdv | 1:cce4622d70f6 | 62 | (const char[]){ 0x3F, 0x20, 0x20, 0x20, 0x20 }, |
medvdv | 1:cce4622d70f6 | 63 | (const char[]){ 0x3F, 0x02, 0x04, 0x02, 0x3F }, |
medvdv | 1:cce4622d70f6 | 64 | (const char[]){ 0x3F, 0x02, 0x04, 0x08, 0x3F }, |
medvdv | 1:cce4622d70f6 | 65 | (const char[]){ 0x1E, 0x21, 0x21, 0x21, 0x1E }, |
medvdv | 1:cce4622d70f6 | 66 | (const char[]){ 0x3F, 0x09, 0x09, 0x09, 0x06 }, |
medvdv | 1:cce4622d70f6 | 67 | (const char[]){ 0x1E, 0x21, 0x29, 0x31, 0x3E }, |
medvdv | 1:cce4622d70f6 | 68 | (const char[]){ 0x3F, 0x09, 0x09, 0x19, 0x26 }, |
medvdv | 1:cce4622d70f6 | 69 | (const char[]){ 0x12, 0x25, 0x25, 0x25, 0x1A }, |
medvdv | 1:cce4622d70f6 | 70 | (const char[]){ 0x01, 0x01, 0x3F, 0x01, 0x01 }, |
medvdv | 1:cce4622d70f6 | 71 | (const char[]){ 0x1F, 0x20, 0x20, 0x20, 0x1F }, |
medvdv | 1:cce4622d70f6 | 72 | (const char[]){ 0x03, 0x0C, 0x30, 0x0C, 0x03 }, |
medvdv | 1:cce4622d70f6 | 73 | (const char[]){ 0x1F, 0x20, 0x18, 0x20, 0x1F }, |
medvdv | 1:cce4622d70f6 | 74 | (const char[]){ 0x21, 0x12, 0x0C, 0x12, 0x21 }, |
medvdv | 1:cce4622d70f6 | 75 | (const char[]){ 0x03, 0x04, 0x38, 0x04, 0x03 }, |
medvdv | 1:cce4622d70f6 | 76 | (const char[]){ 0x31, 0x29, 0x25, 0x23, 0x21 }, |
medvdv | 1:cce4622d70f6 | 77 | (const char[]){ 0x00, 0x3F, 0x21, 0x21 }, |
medvdv | 1:cce4622d70f6 | 78 | (const char[]){ 0x02, 0x04, 0x08, 0x10, 0x20 }, |
medvdv | 1:cce4622d70f6 | 79 | (const char[]){ 0x00, 0x00, 0x21, 0x21, 0x3F }, |
medvdv | 1:cce4622d70f6 | 80 | (const char[]){ 0x04, 0x02, 0x01, 0x02, 0x04 }, |
medvdv | 1:cce4622d70f6 | 81 | (const char[]){ 0x20, 0x20, 0x20, 0x20, 0x20 }, |
medvdv | 1:cce4622d70f6 | 82 | (const char[]){ 0x00, 0x01, 0x03, 0x04 }, |
medvdv | 1:cce4622d70f6 | 83 | (const char[]){ 0x10, 0x2A, 0x2A, 0x3C }, |
medvdv | 1:cce4622d70f6 | 84 | (const char[]){ 0x3F, 0x24, 0x22, 0x1C }, |
medvdv | 1:cce4622d70f6 | 85 | (const char[]){ 0x1C, 0x22, 0x22, 0x14 }, |
medvdv | 1:cce4622d70f6 | 86 | (const char[]){ 0x1C, 0x22, 0x24, 0x3F }, |
medvdv | 1:cce4622d70f6 | 87 | (const char[]){ 0x1C, 0x2A, 0x2A, 0x2C }, |
medvdv | 1:cce4622d70f6 | 88 | (const char[]){ 0x3E, 0x09, 0x01, 0x02 }, |
medvdv | 1:cce4622d70f6 | 89 | (const char[]){ 0x0C, 0x52, 0x4A, 0x3C }, |
medvdv | 1:cce4622d70f6 | 90 | (const char[]){ 0x3F, 0x04, 0x02, 0x3C }, |
medvdv | 1:cce4622d70f6 | 91 | (const char[]){ 0x3D }, |
medvdv | 1:cce4622d70f6 | 92 | (const char[]){ 0x40, 0x40, 0x3D }, |
medvdv | 1:cce4622d70f6 | 93 | (const char[]){ 0x3F, 0x08, 0x0C, 0x32 }, |
medvdv | 1:cce4622d70f6 | 94 | (const char[]){ 0x3F }, |
medvdv | 1:cce4622d70f6 | 95 | (const char[]){ 0x3C, 0x02, 0x3C, 0x02, 0x3C }, |
medvdv | 1:cce4622d70f6 | 96 | (const char[]){ 0x3C, 0x02, 0x02, 0x3C }, |
medvdv | 1:cce4622d70f6 | 97 | (const char[]){ 0x1C, 0x22, 0x22, 0x1C }, |
medvdv | 1:cce4622d70f6 | 98 | (const char[]){ 0x7E, 0x22, 0x22, 0x1C }, |
medvdv | 1:cce4622d70f6 | 99 | (const char[]){ 0x1C, 0x22, 0x22, 0x7E }, |
medvdv | 1:cce4622d70f6 | 100 | (const char[]){ 0x02, 0x3C, 0x02, 0x02 }, |
medvdv | 1:cce4622d70f6 | 101 | (const char[]){ 0x24, 0x2A, 0x2A, 0x12 }, |
medvdv | 1:cce4622d70f6 | 102 | (const char[]){ 0x02, 0x1F, 0x22, 0x22 }, |
medvdv | 1:cce4622d70f6 | 103 | (const char[]){ 0x1E, 0x20, 0x20, 0x3E }, |
medvdv | 1:cce4622d70f6 | 104 | (const char[]){ 0x06, 0x18, 0x20, 0x3C, 0x02 }, |
medvdv | 1:cce4622d70f6 | 105 | (const char[]){ 0x1E, 0x20, 0x1C, 0x20, 0x1E }, |
medvdv | 1:cce4622d70f6 | 106 | (const char[]){ 0x22, 0x14, 0x08, 0x14, 0x22 }, |
medvdv | 1:cce4622d70f6 | 107 | (const char[]){ 0x0E, 0x50, 0x50, 0x3E }, |
medvdv | 1:cce4622d70f6 | 108 | (const char[]){ 0x22, 0x32, 0x2A, 0x26 }, |
medvdv | 1:cce4622d70f6 | 109 | (const char[]){ 0x00, 0x08, 0x36, 0x41 }, |
medvdv | 1:cce4622d70f6 | 110 | (const char[]){ 0x00, 0x7F }, |
medvdv | 1:cce4622d70f6 | 111 | (const char[]){ 0x00, 0x41, 0x36, 0x08 }, |
medvdv | 1:cce4622d70f6 | 112 | (const char[]){ 0x08, 0x04, 0x08, 0x10, 0x08 }, |
medvdv | 1:cce4622d70f6 | 113 | (const char[]) { |
medvdv | 1:cce4622d70f6 | 114 | 0x2A, 0x55, 0x2A, 0x55 |
medvdv | 1:cce4622d70f6 | 115 | } |
medvdv | 1:cce4622d70f6 | 116 | }; |
medvdv | 0:0a6619901f2e | 117 | |
medvdv | 1:cce4622d70f6 | 118 | // Internals |
medvdv | 0:0a6619901f2e | 119 | |
medvdv | 0:0a6619901f2e | 120 | void lcd5110::write(char data, bool cmd) |
medvdv | 0:0a6619901f2e | 121 | { |
medvdv | 0:0a6619901f2e | 122 | sce -> write(0); |
medvdv | 0:0a6619901f2e | 123 | dc -> write(cmd ? 0:1); |
medvdv | 1:cce4622d70f6 | 124 | spi -> write(data); |
medvdv | 0:0a6619901f2e | 125 | sce -> write(1); |
medvdv | 0:0a6619901f2e | 126 | } |
medvdv | 0:0a6619901f2e | 127 | |
medvdv | 0:0a6619901f2e | 128 | // Public |
medvdv | 0:0a6619901f2e | 129 | |
medvdv | 0:0a6619901f2e | 130 | lcd5110::lcd5110(PinName mosi, PinName sclk, PinName dc, PinName sce, PinName rst) |
medvdv | 0:0a6619901f2e | 131 | { |
medvdv | 0:0a6619901f2e | 132 | spi = new SPI(mosi, NC, sclk); |
medvdv | 1:cce4622d70f6 | 133 | |
medvdv | 0:0a6619901f2e | 134 | spi -> format(8, 1); |
medvdv | 0:0a6619901f2e | 135 | spi -> frequency(4000000); |
medvdv | 1:cce4622d70f6 | 136 | |
medvdv | 0:0a6619901f2e | 137 | this -> rst = new DigitalOut(rst); |
medvdv | 0:0a6619901f2e | 138 | this -> sce = new DigitalOut(sce); |
medvdv | 0:0a6619901f2e | 139 | this -> dc = new DigitalOut(dc); |
medvdv | 1:cce4622d70f6 | 140 | |
medvdv | 0:0a6619901f2e | 141 | font.first_code = 32; |
medvdv | 0:0a6619901f2e | 142 | font.glyphs_total = 128 - 32; |
medvdv | 0:0a6619901f2e | 143 | font.widths = lcd_font8p_widths; |
medvdv | 0:0a6619901f2e | 144 | font.glyphs = lcd_font8p; |
medvdv | 1:cce4622d70f6 | 145 | |
medvdv | 0:0a6619901f2e | 146 | invert = false; |
medvdv | 0:0a6619901f2e | 147 | bold = false; |
medvdv | 0:0a6619901f2e | 148 | } |
medvdv | 0:0a6619901f2e | 149 | |
medvdv | 0:0a6619901f2e | 150 | void lcd5110::Invert(bool invert) |
medvdv | 0:0a6619901f2e | 151 | { |
medvdv | 0:0a6619901f2e | 152 | this -> invert = invert; |
medvdv | 0:0a6619901f2e | 153 | } |
medvdv | 0:0a6619901f2e | 154 | |
medvdv | 0:0a6619901f2e | 155 | void lcd5110::Bold(bool bold) |
medvdv | 0:0a6619901f2e | 156 | { |
medvdv | 0:0a6619901f2e | 157 | this -> bold = bold; |
medvdv | 0:0a6619901f2e | 158 | } |
medvdv | 0:0a6619901f2e | 159 | |
medvdv | 0:0a6619901f2e | 160 | void lcd5110::Reset() |
medvdv | 0:0a6619901f2e | 161 | { |
medvdv | 0:0a6619901f2e | 162 | rst -> write(0); |
medvdv | 0:0a6619901f2e | 163 | wait_ms(100); |
medvdv | 0:0a6619901f2e | 164 | rst -> write(1); |
medvdv | 0:0a6619901f2e | 165 | write(0x21, true); |
medvdv | 0:0a6619901f2e | 166 | write(0x80 + contrast, true); |
medvdv | 0:0a6619901f2e | 167 | write(0x04, true); |
medvdv | 0:0a6619901f2e | 168 | write(0x14, true); |
medvdv | 0:0a6619901f2e | 169 | write(0x20, true); |
medvdv | 0:0a6619901f2e | 170 | write(0x0C, true); |
medvdv | 0:0a6619901f2e | 171 | XY(); |
medvdv | 1:cce4622d70f6 | 172 | } |
medvdv | 1:cce4622d70f6 | 173 | |
medvdv | 0:0a6619901f2e | 174 | void lcd5110::Contrast(char contrast) |
medvdv | 0:0a6619901f2e | 175 | { |
medvdv | 0:0a6619901f2e | 176 | this -> contrast = contrast; |
medvdv | 0:0a6619901f2e | 177 | write(0x21, true); |
medvdv | 0:0a6619901f2e | 178 | write(0x80 + contrast, true); |
medvdv | 0:0a6619901f2e | 179 | write(0x20, true); |
medvdv | 0:0a6619901f2e | 180 | } |
medvdv | 0:0a6619901f2e | 181 | |
medvdv | 0:0a6619901f2e | 182 | void lcd5110::Init() |
medvdv | 0:0a6619901f2e | 183 | { |
medvdv | 0:0a6619901f2e | 184 | contrast = DEFAULT_CONTRAST; |
medvdv | 1:cce4622d70f6 | 185 | Reset(); |
medvdv | 0:0a6619901f2e | 186 | } |
medvdv | 0:0a6619901f2e | 187 | |
medvdv | 0:0a6619901f2e | 188 | void lcd5110::PowerOff() |
medvdv | 0:0a6619901f2e | 189 | { |
medvdv | 0:0a6619901f2e | 190 | // TBD |
medvdv | 0:0a6619901f2e | 191 | } |
medvdv | 0:0a6619901f2e | 192 | |
medvdv | 0:0a6619901f2e | 193 | void lcd5110::Clear(char pattern) |
medvdv | 0:0a6619901f2e | 194 | { |
medvdv | 0:0a6619901f2e | 195 | Write(pattern,504); |
medvdv | 0:0a6619901f2e | 196 | XY(); |
medvdv | 0:0a6619901f2e | 197 | } |
medvdv | 0:0a6619901f2e | 198 | |
medvdv | 0:0a6619901f2e | 199 | void lcd5110::XY(int x, int y) |
medvdv | 0:0a6619901f2e | 200 | { |
medvdv | 0:0a6619901f2e | 201 | if (x<0) x=0; |
medvdv | 0:0a6619901f2e | 202 | if (x>83) x=83; |
medvdv | 0:0a6619901f2e | 203 | if (y<0) y=0; |
medvdv | 0:0a6619901f2e | 204 | if (y>5) y=5; |
medvdv | 1:cce4622d70f6 | 205 | |
medvdv | 1:cce4622d70f6 | 206 | X = x; |
medvdv | 0:0a6619901f2e | 207 | Y = y; |
medvdv | 1:cce4622d70f6 | 208 | |
medvdv | 0:0a6619901f2e | 209 | write( 0x80 | (x & 0x3f), true); |
medvdv | 0:0a6619901f2e | 210 | write( 0x40 | (y & 0x3f), true); |
medvdv | 0:0a6619901f2e | 211 | } |
medvdv | 1:cce4622d70f6 | 212 | |
medvdv | 0:0a6619901f2e | 213 | void lcd5110::Write(char byte) |
medvdv | 1:cce4622d70f6 | 214 | { |
medvdv | 0:0a6619901f2e | 215 | write(invert?(~byte):byte, false); |
medvdv | 1:cce4622d70f6 | 216 | if (++X > 83) { |
medvdv | 1:cce4622d70f6 | 217 | X=0; |
medvdv | 1:cce4622d70f6 | 218 | if (++Y > 5) Y=0; |
medvdv | 0:0a6619901f2e | 219 | } |
medvdv | 0:0a6619901f2e | 220 | } |
medvdv | 0:0a6619901f2e | 221 | |
medvdv | 0:0a6619901f2e | 222 | void lcd5110::Write(char* data, int size) |
medvdv | 0:0a6619901f2e | 223 | { |
medvdv | 0:0a6619901f2e | 224 | for(int i=0; i<size; i++) Write(data[i]); |
medvdv | 0:0a6619901f2e | 225 | } |
medvdv | 0:0a6619901f2e | 226 | |
medvdv | 0:0a6619901f2e | 227 | void lcd5110::Write2(char* data, int size) |
medvdv | 0:0a6619901f2e | 228 | { |
medvdv | 1:cce4622d70f6 | 229 | for(int i=0; i<size; i++) { |
medvdv | 1:cce4622d70f6 | 230 | Write(data[i]); |
medvdv | 1:cce4622d70f6 | 231 | Write(data[i]); |
medvdv | 1:cce4622d70f6 | 232 | } |
medvdv | 0:0a6619901f2e | 233 | } |
medvdv | 1:cce4622d70f6 | 234 | |
medvdv | 0:0a6619901f2e | 235 | void lcd5110::Write(char byte, int count) |
medvdv | 0:0a6619901f2e | 236 | { |
medvdv | 0:0a6619901f2e | 237 | for(int i=0; i<count; i++) Write(byte); |
medvdv | 0:0a6619901f2e | 238 | } |
medvdv | 1:cce4622d70f6 | 239 | |
medvdv | 0:0a6619901f2e | 240 | void lcd5110::Character(char chr) |
medvdv | 0:0a6619901f2e | 241 | { |
medvdv | 0:0a6619901f2e | 242 | if( chr < font.first_code ) return; |
medvdv | 0:0a6619901f2e | 243 | if( chr > font.first_code + font.glyphs_total - 1 ) return; |
medvdv | 1:cce4622d70f6 | 244 | |
medvdv | 0:0a6619901f2e | 245 | chr -= font.first_code; |
medvdv | 1:cce4622d70f6 | 246 | |
medvdv | 0:0a6619901f2e | 247 | int width = font.widths[chr]; |
medvdv | 1:cce4622d70f6 | 248 | |
medvdv | 0:0a6619901f2e | 249 | if (bold) width*=2; |
medvdv | 1:cce4622d70f6 | 250 | |
medvdv | 0:0a6619901f2e | 251 | if ((X + width) > 83) { |
medvdv | 0:0a6619901f2e | 252 | if (++Y > 5) Y = 0; |
medvdv | 0:0a6619901f2e | 253 | XY(0,Y); |
medvdv | 0:0a6619901f2e | 254 | } |
medvdv | 1:cce4622d70f6 | 255 | |
medvdv | 0:0a6619901f2e | 256 | if (bold) { |
medvdv | 0:0a6619901f2e | 257 | Write2( (char*) font.glyphs[chr], (int) font.widths[chr] ); |
medvdv | 1:cce4622d70f6 | 258 | if (X != 0) { |
medvdv | 1:cce4622d70f6 | 259 | Write( 0 ); |
medvdv | 1:cce4622d70f6 | 260 | Write( 0 ); |
medvdv | 1:cce4622d70f6 | 261 | } |
medvdv | 0:0a6619901f2e | 262 | } else { |
medvdv | 0:0a6619901f2e | 263 | Write( (char*) font.glyphs[chr], (int) font.widths[chr] ); |
medvdv | 0:0a6619901f2e | 264 | if (X != 0) Write( 0 ); |
medvdv | 0:0a6619901f2e | 265 | } |
medvdv | 0:0a6619901f2e | 266 | } |
medvdv | 0:0a6619901f2e | 267 | |
medvdv | 0:0a6619901f2e | 268 | int lcd5110::CharacterWidth(char chr) |
medvdv | 0:0a6619901f2e | 269 | { |
medvdv | 0:0a6619901f2e | 270 | if( chr < font.first_code ) return 0; |
medvdv | 0:0a6619901f2e | 271 | if( chr > font.first_code + font.glyphs_total - 1 ) return 0; |
medvdv | 1:cce4622d70f6 | 272 | |
medvdv | 0:0a6619901f2e | 273 | chr -= font.first_code; |
medvdv | 1:cce4622d70f6 | 274 | |
medvdv | 1:cce4622d70f6 | 275 | if (bold) |
medvdv | 0:0a6619901f2e | 276 | return 2 * (font.widths[chr] + 1); |
medvdv | 0:0a6619901f2e | 277 | else |
medvdv | 0:0a6619901f2e | 278 | return font.widths[chr] + 1; |
medvdv | 0:0a6619901f2e | 279 | } |
medvdv | 0:0a6619901f2e | 280 | |
medvdv | 0:0a6619901f2e | 281 | void lcd5110::String(char* str) |
medvdv | 0:0a6619901f2e | 282 | { |
medvdv | 0:0a6619901f2e | 283 | while(*str) Character(*str++); |
medvdv | 0:0a6619901f2e | 284 | } |
medvdv | 0:0a6619901f2e | 285 | |
medvdv | 0:0a6619901f2e | 286 | int lcd5110::StringWidth(char* str) |
medvdv | 0:0a6619901f2e | 287 | { |
medvdv | 0:0a6619901f2e | 288 | int width = 0; |
medvdv | 1:cce4622d70f6 | 289 | |
medvdv | 0:0a6619901f2e | 290 | while(*str) width += CharacterWidth(*str++); |
medvdv | 1:cce4622d70f6 | 291 | |
medvdv | 0:0a6619901f2e | 292 | return width; |
medvdv | 0:0a6619901f2e | 293 | } |
medvdv | 0:0a6619901f2e | 294 | |
medvdv | 0:0a6619901f2e | 295 | void lcd5110::Row(int Y, char* str) |
medvdv | 0:0a6619901f2e | 296 | { |
medvdv | 0:0a6619901f2e | 297 | XY(0, Y); |
medvdv | 0:0a6619901f2e | 298 | Write((char) 0, 84); |
medvdv | 0:0a6619901f2e | 299 | XY(0, Y); |
medvdv | 1:cce4622d70f6 | 300 | String(str); |
medvdv | 0:0a6619901f2e | 301 | } |
medvdv | 0:0a6619901f2e | 302 | |
medvdv | 0:0a6619901f2e | 303 | lcd5110::~lcd5110() |
medvdv | 0:0a6619901f2e | 304 | { |
medvdv | 0:0a6619901f2e | 305 | delete spi; |
medvdv | 1:cce4622d70f6 | 306 | |
medvdv | 0:0a6619901f2e | 307 | delete rst; |
medvdv | 0:0a6619901f2e | 308 | delete sce; |
medvdv | 1:cce4622d70f6 | 309 | delete dc; |
medvdv | 0:0a6619901f2e | 310 | } |
medvdv | 0:0a6619901f2e | 311 | |
medvdv | 0:0a6619901f2e | 312 | |
medvdv | 0:0a6619901f2e | 313 | |
medvdv | 0:0a6619901f2e | 314 |