Modified TextLCD lib. The RW signal is also connected to a IO pin. This enable to read out the display memory and the busy flag. The timing is switched from delays to wait for the busy flag. Added writeCGRAM function to define user chars 0-7.

Fork of TextLCD by Peter Drescher

Committer:
dreschpe
Date:
Mon Dec 06 00:01:25 2010 +0000
Revision:
1:ac2c6d0cc538
Parent:
0:2ceba7f90dd4
Child:
2:e8326f05cdcb
0.2

Who changed what in which revision?

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