TextLCD
Revision 2:227356c7d12c, committed 2010-05-27
- Comitter:
- simon
- Date:
- Thu May 27 17:52:15 2010 +0000
- Parent:
- 1:ac48b187213c
- Child:
- 3:2a46d5820a78
- Commit message:
Changed in this revision
--- a/TextLCD.cpp Thu May 27 13:44:15 2010 +0000 +++ b/TextLCD.cpp Thu May 27 17:52:15 2010 +0000 @@ -23,33 +23,6 @@ #include "TextLCD.h" #include "mbed.h" -/* useful info found at http://www.a-netz.de/lcd.en.php - * - * Initialisation - * ============== - * - * After attaching the supply voltage/after a reset, the display needs to be brought in to a defined state - * - * - wait approximately 15 ms so the display is ready to execute commands - * - Execute the command 0x30 ("Display Settings") three times (wait 1,64ms after each command, the busy flag cannot be queried now). - * - The display is in 8 bit mode, so if you have only connected 4 data pins you should only transmit the higher nibble of each command. - * - If you want to use the 4 bit mode, now you can execute the command to switch over to this mode now. - * - Execute the "clear display" command - * - * Timing - * ====== - * - * Nearly all commands transmitted to the display need 40us for execution. - * Exceptions are the commands "Clear Display and Reset" and "Set Cursor to Start Position" - * These commands need 1.64ms for execution. These timings are valid for all displays working with an - * internal clock of 250kHz. But I do not know any displays that use other frequencies. Any time you - * can use the busy flag to test if the display is ready to accept the next command. - * - * _e is kept high apart from calling clock - * _rw is kept 0 (write) apart from actions that uyse it differently - * _rs is set by the data/command writes - */ - TextLCD::TextLCD(PinName rs, PinName e, PinName d0, PinName d1, PinName d2, PinName d3, LCDType type) : _rs(rs), _e(e), _d(d0, d1, d2, d3),
--- a/TextLCD.h Thu May 27 13:44:15 2010 +0000 +++ b/TextLCD.h Thu May 27 17:52:15 2010 +0000 @@ -7,10 +7,10 @@ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -24,48 +24,90 @@ #define MBED_TEXTLCD_H #include "mbed.h" + +/** A TextLCD interface for 4-bit HD44780-based LCDs + * + * Supports a number of different panel configurations + * + * @code + * #include "mbed.h" + * #include "TextLCD.h" + * + * TextLCD lcd(p5, p6, p7, p8, p9); + * + * int main() { + * lcd.printf("Hello World!\n"); + * } + * @endcode + */ class TextLCD : public Stream { public: - // the different LCDs and addressing modes - /** Select the type of LCD */ + /** LCD panel format */ enum LCDType { - LCD16x2 - , LCD16x2B - , LCD20x2 - , LCD20x4 + LCD16x2 /**< 16x2 LCD panel (default) */ + , LCD16x2B /**< 16x2 LCD panel alternate addressing */ + , LCD20x2 /**< 20x2 LCD panel */ + , LCD20x4 /**< 20x4 LCD panel */ }; + /** Create a TextLCD interface + * + * @param rs Instruction/data control line + * @param e Enable line (clock) + * @param d0-d3 Data lines + * @param type Sets the panel size/addressing mode (default = LCD16x2) + */ TextLCD(PinName rs, PinName e, PinName d0, PinName d1, PinName d2, PinName d3, LCDType type = LCD16x2); - // int putc(int c) inherited from Stream - // int printf(...) inherited from Stream - void character(int column, int row, int c); + +#if DOXYGEN_ONLY + /** Write a character to the LCD + * + * @param c The character to write to the display + */ + int putc(int c); + + /** Write a formated string to the LCD + * + * @param format A printf-style format string, followed by the + * variables to use in formating the string. + */ + int printf(const char* format, ...); +#endif + + /** Locate to a screen column and row + * + * @param column The horizontal position from the left, indexed from 0 + * @param row The vertical position from the top, indexed from 0 + */ void locate(int column, int row); + + /** Clear the screen and locate to 0,0 */ void cls(); - + int rows(); - int columns(); - - + int columns(); + protected: // Stream implementation functions virtual int _putc(int value); virtual int _getc(); - // internal tx functions + int address(int column, int row); + void character(int column, int row, int c); void writeByte(int value); void writeCommand(int command); void writeData(int data); - int address(int column, int row); DigitalOut _rs, _e; BusOut _d; LCDType _type; - // current row/column int _column; int _row; }; +} + #endif
--- a/main.cpp Thu May 27 13:44:15 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -// Write to all HD44780 TextLCD RAM locations, sford -// -// A quick hack to write to all the display RAM locations -// in an HD44780 display, to identify which location maps -// to which character. -// -// Instructions: -// - Change TextLCD pinout as appropriate so it works -// - Run, and it should fill the screen with characters -// - Identify what characters are at the start of each row -// -// To determine what address each line starts at, you subtract the -// ascii code for '0'(48) from the character at the start of each line -// - see http://www.asciitable.com/ -// -// e.g. -// +----------------+ -// |0123456789:;<=>?| first char = '0' (48) -// |XYZ.... | first char = 'X' (88) -// +----------------+ -// -// So in this case, the RAM offsets are 0 and 40 - -#include "mbed.h" -#include "TextLCD.h" -DigitalOut zero(p11); -TextLCD lcd(p10, p12, p15, p16, p29, p30, TextLCD::LCD16x2B); - -int main() { - lcd.printf("hithere"); - wait(1); - lcd.putc('i'); - wait(1); - lcd.cls(); - wait(1); - lcd.locate(4, 1); - wait(1); - lcd.printf("jdlkjfksj"); - for(int i=0; i<30; i++) { - lcd.putc('A' + i); - wait(0.3); - } -}
--- a/mbed.bld Thu May 27 13:44:15 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/e6be4cd80aad