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