Edutech IoT Team / EPB_TextLCD
Committer:
dwijaybane
Date:
Mon Jan 25 07:36:26 2016 +0000
Revision:
1:b71e1da4be91
Parent:
TextLCD.h@0:c1ed4a9787c7
Child:
2:c80a4f135575
LCD Updated

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dwijaybane 0:c1ed4a9787c7 1 /* mbed TextLCD Library, for a 4-bit LCD based on HD44780 */
dwijaybane 0:c1ed4a9787c7 2 /* Copyright (C) 2016,Edutech IoT Team, mbed.org, MIT License
dwijaybane 0:c1ed4a9787c7 3 *
dwijaybane 0:c1ed4a9787c7 4 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
dwijaybane 0:c1ed4a9787c7 5 * and associated documentation files (the "Software"), to deal in the Software without restriction,
dwijaybane 0:c1ed4a9787c7 6 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
dwijaybane 0:c1ed4a9787c7 7 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
dwijaybane 0:c1ed4a9787c7 8 * furnished to do so, subject to the following conditions:
dwijaybane 0:c1ed4a9787c7 9 *
dwijaybane 0:c1ed4a9787c7 10 * The above copyright notice and this permission notice shall be included in all copies or
dwijaybane 0:c1ed4a9787c7 11 * substantial portions of the Software.
dwijaybane 0:c1ed4a9787c7 12 *
dwijaybane 0:c1ed4a9787c7 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
dwijaybane 0:c1ed4a9787c7 14 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
dwijaybane 0:c1ed4a9787c7 15 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
dwijaybane 0:c1ed4a9787c7 16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
dwijaybane 0:c1ed4a9787c7 17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
dwijaybane 0:c1ed4a9787c7 18 */
dwijaybane 0:c1ed4a9787c7 19
dwijaybane 0:c1ed4a9787c7 20 #ifndef MBED_TEXTLCD_H
dwijaybane 0:c1ed4a9787c7 21 #define MBED_TEXTLCD_H
dwijaybane 0:c1ed4a9787c7 22
dwijaybane 0:c1ed4a9787c7 23 #include "mbed.h"
dwijaybane 0:c1ed4a9787c7 24
dwijaybane 0:c1ed4a9787c7 25 /** A TextLCD interface for driving 4-bit HD44780-based LCDs
dwijaybane 0:c1ed4a9787c7 26 *
dwijaybane 0:c1ed4a9787c7 27 * Currently supports 16x2, 20x2 and 20x4 panels
dwijaybane 0:c1ed4a9787c7 28 *
dwijaybane 0:c1ed4a9787c7 29 * @code
dwijaybane 0:c1ed4a9787c7 30 * #include "mbed.h"
dwijaybane 0:c1ed4a9787c7 31 * #include "TextLCD.h"
dwijaybane 0:c1ed4a9787c7 32 *
dwijaybane 0:c1ed4a9787c7 33 * TextLCD lcd(p10, p11, p12, p15, p16, p29, p30); // rs, rw, e, d4-d7
dwijaybane 0:c1ed4a9787c7 34 *
dwijaybane 0:c1ed4a9787c7 35 * int main() {
dwijaybane 0:c1ed4a9787c7 36 * lcd.printf("Hello World!\n");
dwijaybane 0:c1ed4a9787c7 37 * }
dwijaybane 0:c1ed4a9787c7 38 * @endcode
dwijaybane 0:c1ed4a9787c7 39 */
dwijaybane 0:c1ed4a9787c7 40 class TextLCD : public Stream {
dwijaybane 0:c1ed4a9787c7 41 public:
dwijaybane 0:c1ed4a9787c7 42
dwijaybane 0:c1ed4a9787c7 43 /** LCD panel format */
dwijaybane 0:c1ed4a9787c7 44 enum LCDType {
dwijaybane 0:c1ed4a9787c7 45 LCD16x2 /**< 16x2 LCD panel (default) */
dwijaybane 0:c1ed4a9787c7 46 , LCD16x2B /**< 16x2 LCD panel alternate addressing */
dwijaybane 0:c1ed4a9787c7 47 , LCD20x2 /**< 20x2 LCD panel */
dwijaybane 0:c1ed4a9787c7 48 , LCD20x4 /**< 20x4 LCD panel */
dwijaybane 0:c1ed4a9787c7 49 };
dwijaybane 0:c1ed4a9787c7 50
dwijaybane 0:c1ed4a9787c7 51 /** Create a TextLCD interface
dwijaybane 0:c1ed4a9787c7 52 *
dwijaybane 0:c1ed4a9787c7 53 * @param rs Instruction/data control line
dwijaybane 0:c1ed4a9787c7 54 * @param rw Read/Write Instruction Control line
dwijaybane 0:c1ed4a9787c7 55 * @param e Enable line (clock)
dwijaybane 0:c1ed4a9787c7 56 * @param d4-d7 Data lines for using as a 4-bit interface
dwijaybane 0:c1ed4a9787c7 57 * @param type Sets the panel size/addressing mode (default = LCD16x2)
dwijaybane 0:c1ed4a9787c7 58 */
dwijaybane 0:c1ed4a9787c7 59 TextLCD(PinName rs, PinName rw, PinName e, PinName d4, PinName d5, PinName d6, PinName d7, LCDType type = LCD16x2);
dwijaybane 0:c1ed4a9787c7 60
dwijaybane 0:c1ed4a9787c7 61 #if DOXYGEN_ONLY
dwijaybane 0:c1ed4a9787c7 62 /** Write a character to the LCD
dwijaybane 0:c1ed4a9787c7 63 *
dwijaybane 0:c1ed4a9787c7 64 * @param c The character to write to the display
dwijaybane 0:c1ed4a9787c7 65 */
dwijaybane 0:c1ed4a9787c7 66 int putc(int c);
dwijaybane 0:c1ed4a9787c7 67
dwijaybane 0:c1ed4a9787c7 68 /** Write a formated string to the LCD
dwijaybane 0:c1ed4a9787c7 69 *
dwijaybane 0:c1ed4a9787c7 70 * @param format A printf-style format string, followed by the
dwijaybane 0:c1ed4a9787c7 71 * variables to use in formating the string.
dwijaybane 0:c1ed4a9787c7 72 */
dwijaybane 0:c1ed4a9787c7 73 int printf(const char* format, ...);
dwijaybane 0:c1ed4a9787c7 74 #endif
dwijaybane 0:c1ed4a9787c7 75
dwijaybane 0:c1ed4a9787c7 76 /** Locate to a screen column and row
dwijaybane 0:c1ed4a9787c7 77 *
dwijaybane 0:c1ed4a9787c7 78 * @param column The horizontal position from the left, indexed from 0
dwijaybane 0:c1ed4a9787c7 79 * @param row The vertical position from the top, indexed from 0
dwijaybane 0:c1ed4a9787c7 80 */
dwijaybane 0:c1ed4a9787c7 81 void locate(int column, int row);
dwijaybane 0:c1ed4a9787c7 82
dwijaybane 0:c1ed4a9787c7 83 /** Clear the screen and locate to 0,0 */
dwijaybane 0:c1ed4a9787c7 84 void cls();
dwijaybane 0:c1ed4a9787c7 85
dwijaybane 0:c1ed4a9787c7 86 int rows();
dwijaybane 0:c1ed4a9787c7 87 int columns();
dwijaybane 0:c1ed4a9787c7 88
dwijaybane 0:c1ed4a9787c7 89 protected:
dwijaybane 0:c1ed4a9787c7 90
dwijaybane 0:c1ed4a9787c7 91 // Stream implementation functions
dwijaybane 0:c1ed4a9787c7 92 virtual int _putc(int value);
dwijaybane 0:c1ed4a9787c7 93 virtual int _getc();
dwijaybane 0:c1ed4a9787c7 94
dwijaybane 0:c1ed4a9787c7 95 int address(int column, int row);
dwijaybane 0:c1ed4a9787c7 96 void character(int column, int row, int c);
dwijaybane 0:c1ed4a9787c7 97 void writeByte(int value);
dwijaybane 0:c1ed4a9787c7 98 void writeCommand(int command);
dwijaybane 0:c1ed4a9787c7 99 void writeData(int data);
dwijaybane 0:c1ed4a9787c7 100
dwijaybane 0:c1ed4a9787c7 101 DigitalOut _rs, _rw, _e;
dwijaybane 0:c1ed4a9787c7 102 BusOut _d;
dwijaybane 0:c1ed4a9787c7 103 LCDType _type;
dwijaybane 0:c1ed4a9787c7 104
dwijaybane 0:c1ed4a9787c7 105 int _column;
dwijaybane 0:c1ed4a9787c7 106 int _row;
dwijaybane 0:c1ed4a9787c7 107 };
dwijaybane 0:c1ed4a9787c7 108
dwijaybane 0:c1ed4a9787c7 109 #endif