Embed:
(wiki syntax)
Show/hide line numbers
I2CTextLCD.h
00001 /* mbed I2CTextLCD Library 00002 * Copyright (c) 2007-2009 sford 00003 * Copyright (c) 2010 Wim De Roeve changed to work with I2C PCF8575 00004 * Released under the MIT License: http://mbed.org/license/mit 00005 */ 00006 00007 #ifndef MBED_I2CTextLCD_H 00008 #define MBED_I2CTextLCD_H 00009 00010 #include "mbed.h" 00011 #include "Stream.h" 00012 00013 #define RS_ON 0x01 //PCF port P0 00014 #define E1_ON 0x02 //PCF port P1 00015 #define E2_ON 0x40 //P6 00016 #define BACKLIGHT_ON 0x80 //P7 00017 00018 /* Display ON/OFF Control defines */ 00019 #define DON 0x0F //0b00001111 Display on 00020 #define DOFF 0x0B //0b00001011 Display off 00021 #define CURSOR_ON 0x0F //0b00001111 Cursor on 00022 #define CURSOR_OFF 0x0D //0b00001101 Cursor off 00023 #define BLINK_ON 0x0F //0b00001111 Cursor Blink 00024 #define BLINK_OFF 0x0E //0b00001110 Cursor No Blink 00025 00026 /* Cursor or Display Shift defines */ 00027 #define SHIFT_CUR_LEFT 0x13 //0b00010011 Cursor shifts to the left 00028 #define SHIFT_CUR_RIGHT 0x17 //0b00010111 Cursor shifts to the right 00029 #define SHIFT_DISP_LEFT 0x1B //0b00011011 Display shifts to the left 00030 #define SHIFT_DISP_RIGHT 0x1F //0b00011111 Display shifts to the right 00031 00032 /* Function Set defines */ 00033 #define EIGHT_BITMODE 0x03 //0b00000011 8-bit Interface D4-D7 00034 #define FOUR_BITMODE 0x02 //0b00000010 4-bit Interface D4-D7 00035 #define LINE_5X7 0x30 //0b00110000 00036 #define LINE_5X10 0x34 //0b00110100 00037 #define LINES_5X7 0x38 //0b00111000 00038 00039 // Addtional define to support display mode 00040 00041 #define DISP_FLIP_NONE 0x00 //0b00111100 No flip 00042 #define CLEAR_LCD 0x01 //0b00000001 00043 00044 // Addtional define to support entry mode & shift mode 00045 //#define ENTRY_CURSOR_DEC 0b00000101 /* Entry cursor move left */ 00046 //#define ENTRY_CURSOR_INC 0b00000111 /* Entry cursor move to right */ 00047 //#define ENTRY_DISPLAY_SHIFT 0b00000111 /* Entry the display to shift */ 00048 //#define ENTRY_DISPLAY_NO_SHIFT 0b00000110 /* Entry no shift */ 00049 00050 // Use generic address 00051 00052 #define LINE0 0x80 00053 #define LINE1 0xC0 00054 #define LINE2 0x94 00055 #define LINE3 0xD4 00056 namespace mbed { 00057 00058 /* Class: I2CTextLCD 00059 * A 16x2 Text LCD controller 00060 * 00061 * Allows you to print to a Text LCD screen, and locate/cls. Could be 00062 * turned in to a more generic libray. 00063 * 00064 * If you are connecting multiple displays, you can connect them all in 00065 * parallel, the address of the PCF8575 or PCF8574 must be unique for each 00066 * display. 00067 * 00068 * Example: 00069 * > #include "mbed.h" 00070 * > #include "I2CTextLCD.h" 00071 * > 00072 * > I2CTextLCD lcd(p9, P10, 0x40); // sda scl, address 00073 * > 00074 * > int main() { 00075 * > lcd.printf("Hello World!"); 00076 * > } 00077 */ 00078 class I2CTextLCD : public Stream { 00079 00080 public: 00081 /* Constructor: I2CTextLCD 00082 * Create a I2CTextLCD object 00083 * 00084 * wiring 00085 * 00086 * PCF8575/PCF8574 to LCD..........Rods Fassung: 00087 * ---------------------- 00088 * P0 - D4.............RS 00089 * P1 - D5..............E 00090 * P2 - D6.............D4 00091 * P3 - D7.............D5 00092 * P4 - RS.............D6 00093 * P5 - E1.............D7 00094 * P6 - E2 00095 * P7 - backlight (connected to a relay) 00096 * gnd - R/W 00097 * 00098 */ 00099 // I2C address for PCF8574AN [TI] is 0x38 for A0..2 = 000 0x39 for 001, NO it is 0x70. 00100 // I2C slave addres for NXP PCF8574 = 0x 40 for A0..2 = 000 0x42 for 001 00101 // I2C slave addres for NXP PCF8574A = 0x 70 for A0..2 = 000 0x72 for 001 00102 00103 I2CTextLCD(PinName sda, PinName scl, int address, int columns = 20, int rows = 4, bool backlight = false); 00104 00105 #if 0 // Inhereted from Stream, for documentation only 00106 /* Function: putc 00107 * Write a character 00108 * 00109 * Variables: 00110 * c - The character to write to the serial port 00111 */ 00112 int putc(int c); 00113 00114 /* Function: printf 00115 * Write a formated string 00116 * 00117 * Variables: 00118 * format - A printf-style format string, followed by the 00119 * variables to use in formating the string. 00120 */ 00121 int printf(const char* format, ...); 00122 #endif 00123 00124 /* Function: locate 00125 * Locate to a certian position 00126 * 00127 * Variables: 00128 * column - the column to locate to, from 0..15 00129 * row - the row to locate to, from 0..1 00130 */ 00131 virtual void locate(int column, int row); 00132 00133 /* Function: cls 00134 * Clear the screen, and locate to 0,0 00135 */ 00136 virtual void cls(); 00137 00138 virtual void reset(); 00139 00140 /* Function: backlight 00141 * Sets the backlight on or off 00142 * 00143 * Variables: 00144 * on (true or false) 00145 */ 00146 //virtual void backlight(bool on); 00147 00148 protected: 00149 00150 void clock(); 00151 void init8574A(void); 00152 void writeData(int data); 00153 void writeCommand(int command); 00154 void writeByte(int value, bool rs); 00155 //void writeNibble(int value, bool rs); 00156 // void writeI2CByte(int data); 00157 int readI2C(); 00158 virtual int _putc(int c); 00159 virtual int _getc(); 00160 virtual void newline(); 00161 00162 int _row; 00163 int _column; 00164 int _columns; 00165 int _rows; 00166 00167 I2C _i2c; 00168 int _i2cAddress; 00169 bool _backlight; 00170 00171 00172 private: 00173 00174 00175 00176 }; 00177 00178 } 00179 00180 #endif 00181
Generated on Thu Sep 22 2022 10:55:42 by
1.7.2