TextLCD
Revision 11:9ec02df863a1, committed 2013-02-05
- Comitter:
- wim
- Date:
- Tue Feb 05 21:03:43 2013 +0000
- Parent:
- 10:dd9b3a696acd
- Child:
- 12:6bf9d9957d31
- Commit message:
- Added User Defined Character support
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 Mon Feb 04 21:48:24 2013 +0000 +++ b/TextLCD.cpp Tue Feb 05 21:03:43 2013 +0000 @@ -84,15 +84,15 @@ break; } - writeCommand(0x0C); // Display Ctrl 0000 1 D C B - // Display On, Cursor Off, Blink Off - _cursor = CurOff; - writeCommand(0x06); // Entry Mode 0000 01 CD S // Cursor Direction and Display Shift // CD=1 (Cur incr) // S=0 (No display shift) +// writeCommand(0x0C); // Display Ctrl 0000 1 D C B +// // Display On, Cursor Off, Blink Off + cursor(TextLCD::CurOff_BlkOff); + cls(); } @@ -326,25 +326,43 @@ } -TextLCD::LCDCursor TextLCD::cursor(TextLCD::LCDCursor show) { - LCDCursor cur = _cursor; +void TextLCD::cursor(TextLCD::LCDCursor show) { switch (show) { - case CurOn : writeCommand(0x0F); // Cursor on and Blink char - wait_us(40); - _cursor = show; - break; - case CurOff : writeCommand(0x0C); - wait_us(40); - _cursor = show; - break; + case CurOff_BlkOff : writeCommand(0x0C); // Cursor off and Blink Off + wait_us(40); + _cursor = show; + break; + + case CurOn_BlkOff : writeCommand(0x0E); // Cursor on and Blink Off + wait_us(40); + _cursor = show; + break; + + case CurOff_BlkOn : writeCommand(0x0D); // Cursor off and Blink On + wait_us(40); + _cursor = show; + break; + + case CurOn_BlkOn : writeCommand(0x0F); // Cursor on and Blink char + wait_us(40); + _cursor = show; + break; + default : - break; + break; } - return cur; + } +void TextLCD::setUDC(unsigned char c, char *udc_data) { + writeCommand(0x40 + ((c & 0x07) << 3)); //Set CG-RAM address + + for (int i=0; i<8; i++) { + writeData(*udc_data++); + } +}
--- a/TextLCD.h Mon Feb 04 21:48:24 2013 +0000 +++ b/TextLCD.h Tue Feb 05 21:03:43 2013 +0000 @@ -34,7 +34,7 @@ * #include "mbed.h" * #include "TextLCD.h" * - * TextLCD lcd(p10, p12, p15, p16, p29, p30); // rs, e, d4-d7 + * TextLCD lcd(p15, p16, p17, p18, p19, p20); // RS, E, D4-D7 * * int main() { * lcd.printf("Hello World!\n"); @@ -42,7 +42,29 @@ * @endcode */ - +/** User Defined Chars 5x7 dots */ +const char udc_ae[] = {0x00, 0x00, 0x1B, 0x05, 0x1F, 0x14, 0x1F, 0x00}; //æ +const char udc_0e[] = {0x00, 0x00, 0x0E, 0x13, 0x15, 0x19, 0x0E, 0x00}; //ø +const char udc_ao[] = {0x0E, 0x0A, 0x0E, 0x01, 0x0F, 0x11, 0x0F, 0x00}; //å +const char udc_AE[] = {0x0F, 0x14, 0x14, 0x1F, 0x14, 0x14, 0x17, 0x00}; //Æ +const char udc_0E[] = {0x0E, 0x13, 0x15, 0x15, 0x15, 0x19, 0x0E, 0x00}; //Ø +const char udc_AA[] = {0x0E, 0x0A, 0x0E, 0x11, 0x1F, 0x11, 0x11, 0x00}; //Å + +const char udc_0[] = {0x18, 0x14, 0x12, 0x11, 0x12, 0x14, 0x18, 0x00}; // |> +const char udc_1[] = {0x03, 0x05, 0x09, 0x11, 0x09, 0x05, 0x03, 0x00}; // <| +const char udc_2[] = {0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00}; // | +const char udc_3[] = {0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x00}; // || +const char udc_4[] = {0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x00}; // ||| +const char udc_5[] = {0x00, 0x1f, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00}; // = +const char udc_6[] = {0x15, 0x0a, 0x15, 0x0a, 0x15, 0x0a, 0x15, 0x00}; // checkerboard +const char udc_7[] = {0x10, 0x08, 0x04, 0x02, 0x01, 0x00, 0x10, 0x00}; // \ + + +/** A TextLCD interface for driving 4-bit HD44780-based LCDs + * + * Currently supports 8x1, 8x2, 16x2, 16x4, 20x2, 20x4, 24x2, 24x4 and 40x2 panels + * + */ class TextLCD : public Stream { public: @@ -62,8 +84,10 @@ /** LCD Cursor control */ enum LCDCursor { - CurOn, - CurOff + CurOff_BlkOff, + CurOn_BlkOff, + CurOff_BlkOn, + CurOn_BlkOn, }; @@ -115,12 +139,6 @@ */ void setAddress(int column, int row); - /** Set the Cursormode - * - * @param show The Cursor mode (CurOn or CurOff) - * @param return The current Cursor mode - */ - LCDCursor cursor(LCDCursor show); /** Clear the screen and locate to 0,0 */ void cls(); @@ -137,6 +155,20 @@ */ int columns(); + /** Set the Cursormode + * + * @param show The Cursor mode (CurOff_BlkOff, CurOn_BlkOff, CurOff_BlkOn, CurOn_BlkOn) + */ + void cursor(LCDCursor show); + + + /** Set User Defined Characters + * + * @param unsigned char c The Index of the UDC (0..7) + * @param char *udc_char The bitpatterns for the UDC (8 bytes of 5 significant bits) + */ + void setUDC(unsigned char c, char *udc_data); + protected: // Stream implementation functions virtual int _putc(int value);