I2CTextLCD.h
- Committer:
- Wimpie
- Date:
- 2011-04-17
- Revision:
- 3:704f87be7993
- Parent:
- 2:1c5dea5d8783
File content as of revision 3:704f87be7993:
/* mbed I2CTextLCD Library * Copyright (c) 2007-2009 sford * Copyright (c) 2010 Wim De Roeve changed to work with I2C PCF8575 * Released under the MIT License: http://mbed.org/license/mit */ #ifndef MBED_I2CTextLCD_H #define MBED_I2CTextLCD_H #include "mbed.h" #include "Stream.h" #define RS_ON 0x10 //P4 #define E1_ON 0x20 //P5 #define E2_ON 0x40 //P6 #define BACKLIGHT_ON 0x80 //P7 /* Display ON/OFF Control defines */ #define DON 0x0F //0b00001111 Display on #define DOFF 0x0B //0b00001011 Display off #define CURSOR_ON 0x0F //0b00001111 Cursor on #define CURSOR_OFF OxOD //0b00001101 Cursor off #define BLINK_ON 0x0F //0b00001111 Cursor Blink #define BLINK_OFF 0x0E //0b00001110 Cursor No Blink /* Cursor or Display Shift defines */ #define SHIFT_CUR_LEFT Ox13 //0b00010011 Cursor shifts to the left #define SHIFT_CUR_RIGHT Ox17 //0b00010111 Cursor shifts to the right #define SHIFT_DISP_LEFT Ox1B //0b00011011 Display shifts to the left #define SHIFT_DISP_RIGHT 0x1F //0b00011111 Display shifts to the right /* Function Set defines */ #define EIGHT_BITMODE 0x03 //0b00000011 8-bit Interface D4-D7 #define FOUR_BITMODE 0x02 //0b00000010 4-bit Interface D4-D7 #define LINE_5X7 0x30 //0b00110000 #define LINE_5X10 0x34 //0b00110100 #define LINES_5X7 0x38 //0b00111000 // Addtional define to support display mode #define DISP_FLIP_NONE 0x00 //0b00111100 No flip #define CLEAR_LCD 0x01 //0b00000001 // Addtional define to support entry mode & shift mode //#define ENTRY_CURSOR_DEC 0b00000101 /* Entry cursor move left */ //#define ENTRY_CURSOR_INC 0b00000111 /* Entry cursor move to right */ //#define ENTRY_DISPLAY_SHIFT 0b00000111 /* Entry the display to shift */ //#define ENTRY_DISPLAY_NO_SHIFT 0b00000110 /* Entry no shift */ // Use generic address #define LINE0 0x80 #define LINE1 0xC0 #define LINE2 0x94 #define LINE3 0xD4 namespace mbed { /* Class: I2CTextLCD * A 16x2 Text LCD controller * * Allows you to print to a Text LCD screen, and locate/cls. Could be * turned in to a more generic libray. * * If you are connecting multiple displays, you can connect them all in * parallel, the address of the PCF8575 or PCF8574 must be unique for each * display. * * Example: * > #include "mbed.h" * > #include "I2CTextLCD.h" * > * > I2CTextLCD lcd(p9, P10, 0x40); // sda scl, address * > * > int main() { * > lcd.printf("Hello World!"); * > } */ class I2CTextLCD : public Stream { public: /* Constructor: I2CTextLCD * Create a I2CTextLCD object * * wiring * * PCF8575/PCF8574 to LCD * ---------------------- * P0 - D4 * P1 - D5 * P2 - D6 * P3 - D7 * P4 - RS * P5 - E1 * P6 - E2 * P7 - backlight (connected to a relay) * gnd - R/W * */ I2CTextLCD(PinName sda, PinName scl, int address, int columns = 16, int rows = 2, bool backlight = true); #if 0 // Inhereted from Stream, for documentation only /* Function: putc * Write a character * * Variables: * c - The character to write to the serial port */ int putc(int c); /* Function: printf * Write a formated string * * Variables: * format - A printf-style format string, followed by the * variables to use in formating the string. */ int printf(const char* format, ...); #endif /* Function: locate * Locate to a certian position * * Variables: * column - the column to locate to, from 0..15 * row - the row to locate to, from 0..1 */ virtual void locate(int column, int row); /* Function: cls * Clear the screen, and locate to 0,0 */ virtual void cls(); virtual void reset(); /* Function: backlight * Sets the backlight on or off * * Variables: * on (true or false) */ virtual void backlight(bool on); protected: void clock(); void writeData(int data); void writeCommand(int command); void writeByte(int value, bool rs); void writeNibble(int value, bool rs); void writeI2CByte(int data); int readI2C(); virtual int _putc(int c); virtual int _getc(); virtual void newline(); int _row; int _column; int _columns; int _rows; I2C _i2c; int _i2cAddress; bool _backlight; private: }; } #endif