Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
NewTextLCD.h
00001 /* mbed TextLCD Library, for a 4-bit LCD based on HD44780 00002 * Copyright (c) 2007-2010, sford, http://mbed.org 00003 * 2011-06-11 TP modified for Elmicro Testbed with display GDM4000D 00004 * 00005 * Permission is hereby granted, free of charge, to any person obtaining a copy 00006 * of this software and associated documentation files (the "Software"), to deal 00007 * in the Software without restriction, including without limitation the rights 00008 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00009 * copies of the Software, and to permit persons to whom the Software is 00010 * furnished to do so, subject to the following conditions: 00011 * 00012 * The above copyright notice and this permission notice shall be included in 00013 * all copies or substantial portions of the Software. 00014 * 00015 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00016 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00017 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00018 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00019 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00020 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00021 * THE SOFTWARE. 00022 */ 00023 00024 #ifndef MBED_TEXTLCD_H 00025 #define MBED_TEXTLCD_H 00026 00027 #include "mbed.h" 00028 00029 /** A TextLCD interface for driving 4-bit HD44780-based LCDs 00030 * 00031 * Currently supports 16x2, 20x2 and 20x4 panels 00032 * 00033 * @code 00034 * #include "mbed.h" 00035 * #include "NewTextLCD.h" 00036 * 00037 * TextLCD lcd(p26, p25, p24, p23, p22, p20, p19, TextLCD::LCD20x4); // rs, rw, e, d4-d7 00038 * 00039 * int main() { 00040 * lcd.printf("Hello mbed\n"); 00041 * 00042 * //define user chars 00043 * int pattern[8]; 00044 * int pattern1[8]; 00045 * pattern[0] = 1; // * 00046 * pattern[1] = 3; // ** 00047 * pattern[2] = 5; // * * 00048 * pattern[3] = 9; // * * 00049 * pattern[4] = 0x11; // * * 00050 * pattern[5] = 0x19; // ** * 00051 * pattern[6] = 0x1d; // *** * 00052 * pattern[7] = 0x1f; // ***** 00053 * 00054 * pattern1[0] = 0x10; // * 00055 * pattern1[1] = 0x18; // ** 00056 * pattern1[2] = 0x14; // * * 00057 * pattern1[3] = 0x12; // * * 00058 * pattern1[4] = 0x11; // * * 00059 * pattern1[5] = 0x13; // * ** 00060 * pattern1[6] = 0x17; // * *** 00061 * pattern1[7] = 0x1f; // ***** 00062 * 00063 * lcd.writeCGRAM(0, pattern); 00064 * lcd.writeCGRAM(1, pattern1); 00065 * 00066 * lcd.locate(15,0); 00067 * lcd.putc(0); // user pattern 0 00068 * lcd.putc(1); // user pattern 1 00069 * } 00070 * @endcode 00071 */ 00072 class TextLCD : public Stream { 00073 public: 00074 00075 /** LCD panel format */ 00076 enum LCDType { 00077 LCD16x2 /**< 16x2 LCD panel (default) */ 00078 , LCD16x2B /**< 16x2 LCD panel alternate addressing */ 00079 , LCD20x2 /**< 20x2 LCD panel */ 00080 , LCD20x4 /**< 20x4 LCD panel */ 00081 , LCD24x2 /**< 24x2 LCD panel */ 00082 , LCDuser /** User defined LCD, rows/columns must be set */ 00083 }; 00084 00085 /** Create a TextLCD interface 00086 * 00087 * @param rs Instruction/data control line 00088 * @param rw R/W line 00089 * @param e Enable line (clock) 00090 * @param d4-d7 Data lines 00091 * @param type Sets the panel size/addressing mode (default = LCD16x2) 00092 */ 00093 TextLCD(PinName rs, PinName rw, PinName e, PinName d4, PinName d5, PinName d6, PinName d7, LCDType type = LCD16x2); 00094 00095 #if DOXYGEN_ONLY 00096 /** Write a character to the LCD 00097 * 00098 * @param c The character to write to the display 00099 */ 00100 int putc(int c); 00101 00102 /** Write a formated string to the LCD 00103 * 00104 * @param format A printf-style format string, followed by the 00105 * variables to use in formating the string. 00106 */ 00107 int printf(const char* format, ...); 00108 #endif 00109 00110 /** Locate to a screen column and row 00111 * 00112 * @param column The horizontal position from the left, indexed from 0 00113 * @param row The vertical position from the top, indexed from 0 00114 */ 00115 void locate(int column, int row); 00116 00117 /** Clear the screen and locate to 0,0 */ 00118 void cls(); 00119 00120 struct LCDparam { 00121 int rows; // number of lines // 00122 int columns; // number of columns // 00123 int delay; // delay for commands microseconds // 00124 int adresses[4]; // start adresses for 4 lines // 00125 } LCDparam; 00126 00127 /** write a user defined char 00128 * 00129 * @param address The user defined char (0-7) 00130 * @param pattern[8] bit pattern 5*8 of char 00131 */ 00132 void writeCGRAM(int address, int pattern[8]); 00133 00134 /** Get the char at the current position 00135 * 00136 * int getc() 00137 */ 00138 void writeCommand(int command); 00139 00140 protected: 00141 00142 // Stream implementation functions 00143 virtual int _putc(int value); 00144 virtual int _getc(); 00145 00146 int address(int column, int row); 00147 void character(int column, int row, int c); 00148 void writeByte(int value); 00149 void writeData(int data); 00150 void setLCDparam(LCDType _type); 00151 DigitalOut _rs, _rw, _e; 00152 BusOut _d; 00153 LCDType _type; 00154 00155 int _column; 00156 int _row; 00157 }; 00158 00159 #endif
Generated on Wed Jul 13 2022 07:13:43 by
1.7.2