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.
pcf2119.h
00001 /* mbed CD Library, for a i2c LCD based on PCF2119 00002 * Copyright (c) 2016, aracosta, http://mbed.org 00003 * Copyright (c) 2007-2010, sford, http://mbed.org 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_PCF2119_H 00025 #define MBED_PCF2119_H 00026 00027 #include "mbed.h" 00028 00029 /** A TextLCD interface for driving PCF2119-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(p10, p12, p13, p15, p16, p29, p30); // rs, e, d0-d3 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 TextLCD(void); 00086 /** Create a TextLCD interface 00087 * 00088 * @param rs Instruction/data control 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 pSDA, PinName pSCL, PinName pReset, 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 char i2c_address; 00122 int rows; // number of lines // 00123 int columns; // number of columns // 00124 int delay; // delay for commands microseconds // 00125 int addresses[4]; // start adresses for 4 lines // 00126 } LCDparam; 00127 00128 /** write a user defined char 00129 * 00130 * @param address The user defined char (0-7) 00131 * @param pattern[8] bit pattern 5*8 of char 00132 */ 00133 void writeCGRAM(int address, int pattern[8]); 00134 00135 /** Get the char at the current position 00136 * 00137 * int getc() 00138 */ 00139 void writeCommand(int command); 00140 00141 protected: 00142 00143 // Stream implementation functions 00144 virtual int _putc(int value); 00145 virtual int _getc(); 00146 00147 int address(int column, int row); 00148 void character(int column, int row, int c); 00149 void writeData(int data); 00150 void setLCDparam(LCDType _type); 00151 00152 I2C _i2c; 00153 DigitalOut _reset; 00154 char _i2cbuffer[4]; // i2c data buffer 00155 LCDType _type; 00156 00157 int _column; 00158 int _row; 00159 }; 00160 00161 #endif
Generated on Sun Jul 24 2022 04:29:55 by
