A collection of Analog Devices drivers for the mbed platform
Embed:
(wiki syntax)
Show/hide line numbers
Lcd.cpp
00001 /** 00002 ****************************************************************************** 00003 * @file Lcd.c 00004 * @brief Source file for ST7565R LCD control. 00005 * @author ADI 00006 * @date March 2016 00007 * 00008 ******************************************************************************* 00009 * Copyright 2015(c) Analog Devices, Inc. 00010 * 00011 * All rights reserved. 00012 * 00013 * Redistribution and use in source and binary forms, with or without modification, 00014 * are permitted provided that the following conditions are met: 00015 * - Redistributions of source code must retain the above copyright 00016 * notice, this list of conditions and the following disclaimer. 00017 * - Redistributions in binary form must reproduce the above copyright 00018 * notice, this list of conditions and the following disclaimer in 00019 * the documentation and/or other materials provided with the 00020 * distribution. 00021 * - Neither the name of Analog Devices, Inc. nor the names of its 00022 * contributors may be used to endorse or promote products derived 00023 * from this software without specific prior written permission. 00024 * - The use of this software may or may not infringe the patent rights 00025 * of one or more patent holders. This license does not release you 00026 * from the requirement that you obtain separate licenses from these 00027 * patent holders to use this software. 00028 * - Use of the software either in source or binary form, must be run 00029 * on or directly connected to an Analog Devices Inc. component. 00030 * 00031 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED 00032 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY 00033 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00034 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00035 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00036 * INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00037 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00038 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00039 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00040 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00041 * 00042 ******************************************************************************* 00043 **/ 00044 00045 /******************************************************************************/ 00046 /***************************** Include Files **********************************/ 00047 /******************************************************************************/ 00048 #include "Lcd.h" 00049 #include "mbed.h" 00050 00051 00052 00053 Lcd::Lcd(PinName rst_pin, PinName a0_pin, PinName bl_pin, 00054 PinName cs_pin, PinName MOSI, 00055 PinName MISO, PinName SCK) : 00056 00057 rst(rst_pin), a0(a0_pin), bl(bl_pin), cs(cs_pin), lcd_spi(MOSI, MISO, SCK) 00058 { 00059 rst = 1; 00060 } 00061 00062 /** 00063 @brief Initialization of LCD screen 00064 @return none 00065 **/ 00066 00067 void Lcd::write_cmd(uint8_t cmd) 00068 { 00069 cs = 0; 00070 a0 = 0; 00071 lcd_spi.write(cmd); 00072 cs = 1; 00073 } 00074 00075 void Lcd::write_data(uint8_t data) 00076 { 00077 cs = 0; 00078 a0 = 1; 00079 lcd_spi.write(data); 00080 cs = 1; 00081 } 00082 00083 void Lcd::bl_enable() 00084 { 00085 bl = 1; 00086 } 00087 00088 void Lcd::bl_disable() 00089 { 00090 bl = 0; 00091 } 00092 00093 void Lcd::init(void) 00094 { 00095 00096 write_cmd(CMD_DISPLAY_OFF); 00097 write_cmd(CMD_SET_BIAS_7); 00098 write_cmd(CMD_SET_ADC_NORMAL); 00099 write_cmd(CMD_SET_COM_REVERSE); 00100 write_cmd((CMD_SET_RESISTOR_RATIO | 0x02)); 00101 write_cmd(CMD_SET_VOLUME_FIRST); 00102 write_cmd((CMD_SET_VOLUME_SECOND | 0x04)); 00103 write_cmd((CMD_SET_POWER_CONTROL | 0x07)); 00104 fill_pages(0, 8, 0x00); 00105 00106 } 00107 00108 /** 00109 @brief Displays a string at the specified position for with 5x7 font size. 00110 @return none 00111 **/ 00112 void Lcd::display_string(uint8_t ui8row, uint8_t ui8col, int8_t *pi8str) 00113 { 00114 uint8_t ui8x; 00115 uint8_t ui8i; 00116 uint8_t ui8ch; 00117 uint8_t ui8data; 00118 00119 ui8ch = 0; 00120 ui8x = ui8col; 00121 00122 while ((pi8str[ui8ch] != 0) && (ui8col < LCD_COLUMNS)) { 00123 set_cursor(ui8row, ui8x); /* Set cursor position */ 00124 00125 for (ui8i = 0; ui8i < 5; ui8i++) { /* Symbol matrix column loop */ 00126 ui8data = pui8font5x7[pi8str[ui8ch] - OFFS_ASCII][ui8i]; 00127 00128 write_data(ui8data); 00129 } 00130 00131 ui8x += 6; /* Increase column counter with 6 pixels */ 00132 ui8ch++; /* Increment counter */ 00133 } 00134 write_cmd(CMD_DISPLAY_ON); 00135 00136 } 00137 00138 /** 00139 @brief Displays a symbol (8 x width) at the specified position on the LCD. 00140 @param ui8row - row number 00141 @param ui8col - column number 00142 @param ui8width - symbol width 00143 @param pui8symbol - symbol to display 00144 @return none 00145 **/ 00146 00147 void Lcd::display_symbol(uint8_t ui8row, uint8_t ui8col, uint8_t ui8width, 00148 const uint8_t *pui8symbol) 00149 { 00150 uint8_t ui8i; 00151 uint8_t ui8data; 00152 00153 set_cursor(ui8row, ui8col); /* Set cursor position */ 00154 for (ui8i = 0; ui8i < ui8width; ui8i++) { /* Symbol matrix column loop */ 00155 ui8data = pui8symbol[ui8i]; 00156 write_data(ui8data); 00157 } 00158 write_cmd(CMD_DISPLAY_ON); 00159 } 00160 00161 /** 00162 @brief Fills the selected LCD pages with the data specified. 00163 @param ui8start - start element 00164 @param ui8num - elements numbers to fill 00165 @param ui8Data - data to fill 00166 @return none 00167 **/ 00168 00169 void Lcd::fill_pages(uint8_t ui8start, uint8_t ui8num, uint8_t ui8Data) 00170 { 00171 00172 uint8_t ui8p; 00173 uint8_t ui8c; 00174 00175 for (ui8p = ui8start; ui8p < (ui8start + ui8num); ui8p++) { 00176 set_cursor(ui8p, 0); 00177 00178 for (ui8c = 0; ui8c < LCD_COLUMNS; ui8c++) { 00179 write_data(ui8Data); 00180 } 00181 } 00182 00183 write_cmd(CMD_DISPLAY_ON); 00184 } 00185 00186 /** 00187 @brief Sets the start line of the LCD. 00188 @param ui8line - line to start with 00189 @return none 00190 **/ 00191 00192 void Lcd::set_line(uint8_t ui8line) 00193 { 00194 00195 uint8_t ui8Cmd; 00196 ui8Cmd = CMD_SET_DISP_START_LINE | (ui8line & 0x3F); /* Set start line */ 00197 write_cmd(ui8Cmd); 00198 00199 } 00200 00201 00202 /** 00203 @brief Sets the cursor position at which data will be written. 00204 @param ui8PA - page number 00205 @param ui8CA - column number 00206 @return none 00207 **/ 00208 00209 void Lcd::set_cursor(uint8_t ui8PA, uint8_t ui8CA) 00210 { 00211 uint8_t ui8Cmd; 00212 00213 ui8Cmd = 0xB0 | (ui8PA & 0x0F); /* Set page address */ 00214 write_cmd(ui8Cmd); 00215 00216 ui8Cmd = ui8CA & 0x0F; /* Set column address LSB CA[3:0] */ 00217 write_cmd(ui8Cmd); 00218 00219 ui8Cmd = 0x10 | (ui8CA >> 4); /* Set column address MSB CA[7:4] */ 00220 write_cmd(ui8Cmd); 00221 } 00222 00223 00224 const uint8_t Lcd::pui8Rec8x8[8] = { 00225 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF 00226 }; 00227 const uint8_t Lcd::pui8RecInv8x8[8] = { 00228 0xFF, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xFF 00229 }; 00230 00231 const uint8_t Lcd::pui8font5x7[96][5] = { 00232 {0x00, 0x00, 0x00, 0x00, 0x00}, /* 32 */ 00233 {0x00, 0x00, 0x4F, 0x00, 0x00}, /* ! 33 */ 00234 {0x00, 0x07, 0x00, 0x07, 0x00}, /* " 34 */ 00235 {0x14, 0x7F, 0x14, 0x7F, 0x14}, /* # 35 */ 00236 {0x24, 0x2A, 0x7F, 0x2A, 0x12}, /* $ 36 */ 00237 {0x23, 0x13, 0x08, 0x64, 0x62}, /* % 37 */ 00238 {0x36, 0x49, 0x55, 0x22, 0x50}, /* & 38 */ 00239 {0x00, 0x05, 0x03, 0x00, 0x00}, /* ' 39 */ 00240 {0x00, 0x1C, 0x22, 0x41, 0x00}, /* ( 40 */ 00241 {0x00, 0x41, 0x22, 0x1C, 0x00}, /* ) 41 */ 00242 {0x14, 0x08, 0x3E, 0x08, 0x14}, /* * 42 */ 00243 {0x08, 0x08, 0x3E, 0x08, 0x08}, /* + 43 */ 00244 {0x00, 0x50, 0x30, 0x00, 0x00}, /* , 44 */ 00245 {0x08, 0x08, 0x08, 0x08, 0x08}, /* - 45 */ 00246 {0x00, 0x60, 0x60, 0x00, 0x00}, /* . 46 */ 00247 {0x20, 0x10, 0x08, 0x04, 0x02}, /* / 47 */ 00248 {0x3E, 0x51, 0x49, 0x45, 0x3E}, /* 0 48 */ 00249 {0x00, 0x42, 0x7F, 0x40, 0x00}, /* 1 49 */ 00250 {0x42, 0x61, 0x51, 0x49, 0x46}, /* 2 50 */ 00251 {0x21, 0x41, 0x45, 0x4B, 0x31}, /* 3 51 */ 00252 {0x18, 0x14, 0x12, 0x7F, 0x10}, /* 4 52 */ 00253 {0x27, 0x45, 0x45, 0x45, 0x39}, /* 5 53 */ 00254 {0x3C, 0x4A, 0x49, 0x49, 0x30}, /* 6 54 */ 00255 {0x01, 0x71, 0x09, 0x05, 0x03}, /* 7 55 */ 00256 {0x36, 0x49, 0x49, 0x49, 0x36}, /* 8 56 */ 00257 {0x06, 0x49, 0x49, 0x29, 0x1E}, /* 9 57 */ 00258 {0x36, 0x36, 0x00, 0x00, 0x00}, /* : 58 */ 00259 {0x56, 0x36, 0x00, 0x00, 0x00}, /* ; 59 */ 00260 {0x08, 0x14, 0x22, 0x41, 0x00}, /* < 60 */ 00261 {0x14, 0x14, 0x14, 0x14, 0x14}, /* = 61 */ 00262 {0x00, 0x41, 0x22, 0x14, 0x08}, /* > 62 */ 00263 {0x02, 0x01, 0x51, 0x09, 0x06}, /* ? 63 */ 00264 {0x30, 0x49, 0x79, 0x41, 0x3E}, /* @ 64 */ 00265 {0x7E, 0x11, 0x11, 0x11, 0x7E}, /* A 65 */ 00266 {0x7F, 0x49, 0x49, 0x49, 0x36}, /* B 66 */ 00267 {0x3E, 0x41, 0x41, 0x41, 0x22}, /* C 67 */ 00268 {0x7F, 0x41, 0x41, 0x22, 0x1C}, /* D 68 */ 00269 {0x7F, 0x49, 0x49, 0x49, 0x41}, /* E 69 */ 00270 {0x7F, 0x09, 0x09, 0x09, 0x01}, /* F 70 */ 00271 {0x3E, 0x41, 0x49, 0x49, 0x7A}, /* G 71 */ 00272 {0x7F, 0x08, 0x08, 0x08, 0x7F}, /* H 72 */ 00273 {0x00, 0x41, 0x7F, 0x41, 0x00}, /* I 73 */ 00274 {0x20, 0x40, 0x41, 0x3F, 0x01}, /* J 74 */ 00275 {0x7F, 0x08, 0x14, 0x22, 0x41}, /* K 75 */ 00276 {0x7F, 0x40, 0x40, 0x40, 0x40}, /* L 76 */ 00277 {0x7F, 0x02, 0x0C, 0x02, 0x7F}, /* M 77 */ 00278 {0x7F, 0x04, 0x08, 0x10, 0x7F}, /* N 78 */ 00279 {0x3E, 0x41, 0x41, 0x41, 0x3E}, /* O 79 */ 00280 {0x7F, 0x09, 0x09, 0x09, 0x06}, /* P 80 */ 00281 {0x3E, 0x41, 0x51, 0x21, 0x5E}, /* Q 81 */ 00282 {0x7F, 0x09, 0x19, 0x29, 0x46}, /* R 82 */ 00283 {0x46, 0x49, 0x49, 0x49, 0x31}, /* S 83 */ 00284 {0x01, 0x01, 0x7F, 0x01, 0x01}, /* T 84 */ 00285 {0x3F, 0x40, 0x40, 0x40, 0x3F}, /* U 85 */ 00286 {0x1F, 0x20, 0x40, 0x20, 0x1F}, /* V 86 */ 00287 {0x3F, 0x40, 0x30, 0x40, 0x3F}, /* W 87 */ 00288 {0x63, 0x14, 0x08, 0x14, 0x63}, /* X 88 */ 00289 {0x07, 0x08, 0x70, 0x08, 0x07}, /* Y 89 */ 00290 {0x61, 0x51, 0x49, 0x45, 0x43}, /* Z 90 */ 00291 {0x00, 0x7F, 0x41, 0x41, 0x00}, /* [ 91 */ 00292 {0x02, 0x04, 0x08, 0x10, 0x20}, /* \ 92 */ 00293 {0x00, 0x41, 0x41, 0x7F, 0x00}, /* ] 93 */ 00294 {0x04, 0x02, 0x01, 0x02, 0x04}, /* ^ 94 */ 00295 {0x40, 0x40, 0x40, 0x40, 0x40}, /* _ 95 */ 00296 {0x00, 0x01, 0x02, 0x04, 0x00}, /* ` 96 */ 00297 {0x20, 0x54, 0x54, 0x54, 0x78}, /* a 97 */ 00298 {0x7F, 0x50, 0x48, 0x48, 0x30}, /* b 98 */ 00299 {0x38, 0x44, 0x44, 0x44, 0x20}, /* c 99 */ 00300 {0x38, 0x44, 0x44, 0x48, 0x7F}, /* d 100 */ 00301 {0x38, 0x54, 0x54, 0x54, 0x18}, /* e 101 */ 00302 {0x08, 0x7E, 0x09, 0x01, 0x02}, /* f 102 */ 00303 {0x0C, 0x52, 0x52, 0x52, 0x3E}, /* g 103 */ 00304 {0x7F, 0x08, 0x04, 0x04, 0x78}, /* h 104 */ 00305 {0x00, 0x44, 0x7D, 0x40, 0x00}, /* i 105 */ 00306 {0x20, 0x40, 0x44, 0x3D, 0x00}, /* j 106 */ 00307 {0x7F, 0x10, 0x28, 0x44, 0x00}, /* k 107 */ 00308 {0x00, 0x41, 0x7F, 0x40, 0x00}, /* l 108 */ 00309 {0x78, 0x04, 0x18, 0x04, 0x78}, /* m 109 */ 00310 {0x7C, 0x08, 0x04, 0x04, 0x78}, /* n 110 */ 00311 {0x38, 0x44, 0x44, 0x44, 0x38}, /* o 111 */ 00312 {0x7C, 0x14, 0x14, 0x14, 0x08}, /* p 112 */ 00313 {0x08, 0x14, 0x14, 0x18, 0x7C}, /* q 113 */ 00314 {0x7C, 0x08, 0x04, 0x04, 0x08}, /* r 114 */ 00315 {0x48, 0x54, 0x54, 0x54, 0x20}, /* s 115 */ 00316 {0x04, 0x3F, 0x44, 0x40, 0x20}, /* t 116 */ 00317 {0x3C, 0x40, 0x40, 0x20, 0x7C}, /* u 117 */ 00318 {0x1C, 0x20, 0x40, 0x20, 0x1C}, /* v 118 */ 00319 {0x3C, 0x40, 0x30, 0x40, 0x3C}, /* w 119 */ 00320 {0x44, 0x28, 0x10, 0x28, 0x44}, /* x 120 */ 00321 {0x0C, 0x50, 0x50, 0x50, 0x3C}, /* y 121 */ 00322 {0x44, 0x64, 0x54, 0x4C, 0x44}, /* z 122 */ 00323 {0x00, 0x08, 0x36, 0x41, 0x00}, /* { 123 */ 00324 {0x00, 0x00, 0x7F, 0x00, 0x00}, /* | 124 */ 00325 {0x00, 0x41, 0x36, 0x08, 0x00}, /* } 125 */ 00326 {0x0C, 0x02, 0x0C, 0x10, 0x0C}, /* ~ 126 */ 00327 {0x00, 0x00, 0x00, 0x00, 0x00} /* 127 */ 00328 };
Generated on Tue Jul 12 2022 17:59:52 by 1.7.2