TextLCD library for controlling various LCD panels based on the HD44780 4-bit interface
Fork of TextLCD by
Revision 9:8ba443e7fdca, committed 2017-04-25
- Comitter:
- atomicLogic
- Date:
- Tue Apr 25 20:10:03 2017 +0000
- Parent:
- 8:308d188a2d3a
- Child:
- 10:5f557ed7ca4e
- Commit message:
- lcd interface
Changed in this revision
TextLCD.cpp | Show annotated file Show diff for this revision Revisions of this file |
TextLCD.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/TextLCD.cpp Thu Jan 02 21:07:01 2014 +0000 +++ b/TextLCD.cpp Tue Apr 25 20:10:03 2017 +0000 @@ -25,8 +25,9 @@ TextLCD::TextLCD(PinName rs, PinName e, PinName d4, PinName d5, PinName d6, PinName d7, LCDType type) : _rs(rs), - _e(e), _d(d4, d5, d6, d7), - _type(type) { + _e(e), _d(d4, d5, d6, d7), + _type(type) +{ _e = 1; _rs = 0; // command mode @@ -47,24 +48,37 @@ cls(); } -void TextLCD::character(int column, int row, int c) { +void TextLCD::character(int column, int row, int c) +{ int a = address(column, row); writeCommand(a); writeData(c); } -void TextLCD::cls() { +void TextLCD::cls() +{ writeCommand(0x01); // cls, and set cursor to 0 wait(0.00164f); // This command takes 1.64 ms locate(0, 0); } -void TextLCD::locate(int column, int row) { +void TextLCD::locate(int column, int row) +{ _column = column; _row = row; } -int TextLCD::_putc(int value) { +void TextLCD::defineChar(int index, char *data) +{ + if (index<0||index>7) + return; + writeCommand(0x40+index*8); + for (int i=0; i<8; i++) + writeData(*data++); +} + +int TextLCD::_putc(int value) +{ if (value == '\n') { _column = 0; _row++; @@ -85,11 +99,13 @@ return value; } -int TextLCD::_getc() { +int TextLCD::_getc() +{ return -1; } -void TextLCD::writeByte(int value) { +void TextLCD::writeByte(int value) +{ _d = value >> 4; wait(0.000040f); // most instructions take 40us _e = 0; @@ -102,17 +118,20 @@ _e = 1; } -void TextLCD::writeCommand(int command) { +void TextLCD::writeCommand(int command) +{ _rs = 0; writeByte(command); } -void TextLCD::writeData(int data) { +void TextLCD::writeData(int data) +{ _rs = 1; writeByte(data); } -int TextLCD::address(int column, int row) { +int TextLCD::address(int column, int row) +{ switch (_type) { case LCD20x4: switch (row) { @@ -134,7 +153,8 @@ } } -int TextLCD::columns() { +int TextLCD::columns() +{ switch (_type) { case LCD20x4: case LCD20x2: @@ -146,7 +166,8 @@ } } -int TextLCD::rows() { +int TextLCD::rows() +{ switch (_type) { case LCD20x4: return 4; @@ -156,4 +177,4 @@ default: return 2; } -} +} \ No newline at end of file
--- a/TextLCD.h Thu Jan 02 21:07:01 2014 +0000 +++ b/TextLCD.h Tue Apr 25 20:10:03 2017 +0000 @@ -32,15 +32,16 @@ * @code * #include "mbed.h" * #include "TextLCD.h" - * + * * TextLCD lcd(p10, p12, p15, p16, p29, p30); // rs, e, d4-d7 - * + * * int main() { * lcd.printf("Hello World!\n"); * } * @endcode */ -class TextLCD : public Stream { +class TextLCD : public Stream +{ public: /** LCD panel format */ @@ -85,6 +86,13 @@ /** Clear the screen and locate to 0,0 */ void cls(); + /** Defines a custom character bitmap + * + * @param index The index of the custom character slot (0-7) + * @param data Array of 8 bytes defining the custom character. + */ + void defineChar(int index, char *data); + int rows(); int columns(); @@ -108,4 +116,4 @@ int _row; }; -#endif +#endif \ No newline at end of file