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.

Dependents:   TwitterClient CSVParser _EXAMPLE_RFM12B mbed_blinky6 ... more

Committer:
dreschpe
Date:
Tue Dec 14 16:47:47 2010 +0000
Revision:
4:a7c74d4c6911
Parent:
3:8582013914a0
0.2 change small delays to __nop();

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 3:8582013914a0 36 * TextLCD lcd(p10, p12, ,p13, p15, p16, p29, p30); // rs, rw, e, d0-d3
dreschpe 0:2ceba7f90dd4 37 *
dreschpe 0:2ceba7f90dd4 38 * int main() {
dreschpe 2:e8326f05cdcb 39 * lcd.printf("Hello mbed\n");
dreschpe 2:e8326f05cdcb 40 *
dreschpe 2:e8326f05cdcb 41 * //define user chars
dreschpe 2:e8326f05cdcb 42 * int pattern[8];
dreschpe 2:e8326f05cdcb 43 * int pattern1[8];
dreschpe 2:e8326f05cdcb 44 * pattern[0] = 1; // *
dreschpe 2:e8326f05cdcb 45 * pattern[1] = 3; // **
dreschpe 2:e8326f05cdcb 46 * pattern[2] = 5; // * *
dreschpe 2:e8326f05cdcb 47 * pattern[3] = 9; // * *
dreschpe 2:e8326f05cdcb 48 * pattern[4] = 0x11; // * *
dreschpe 2:e8326f05cdcb 49 * pattern[5] = 0x19; // ** *
dreschpe 2:e8326f05cdcb 50 * pattern[6] = 0x1d; // *** *
dreschpe 2:e8326f05cdcb 51 * pattern[7] = 0x1f; // *****
dreschpe 2:e8326f05cdcb 52 *
dreschpe 2:e8326f05cdcb 53 * pattern1[0] = 0x10; // *
dreschpe 2:e8326f05cdcb 54 * pattern1[1] = 0x18; // **
dreschpe 2:e8326f05cdcb 55 * pattern1[2] = 0x14; // * *
dreschpe 2:e8326f05cdcb 56 * pattern1[3] = 0x12; // * *
dreschpe 2:e8326f05cdcb 57 * pattern1[4] = 0x11; // * *
dreschpe 2:e8326f05cdcb 58 * pattern1[5] = 0x13; // * **
dreschpe 2:e8326f05cdcb 59 * pattern1[6] = 0x17; // * ***
dreschpe 2:e8326f05cdcb 60 * pattern1[7] = 0x1f; // *****
dreschpe 2:e8326f05cdcb 61 *
dreschpe 2:e8326f05cdcb 62 * lcd.writeCGRAM(0, pattern);
dreschpe 2:e8326f05cdcb 63 * lcd.writeCGRAM(1, pattern1);
dreschpe 2:e8326f05cdcb 64 *
dreschpe 2:e8326f05cdcb 65 * lcd.locate(15,0);
dreschpe 2:e8326f05cdcb 66 * lcd.putc(0); // user pattern 0
dreschpe 2:e8326f05cdcb 67 * lcd.putc(1); // user pattern 1
dreschpe 0:2ceba7f90dd4 68 * }
dreschpe 0:2ceba7f90dd4 69 * @endcode
dreschpe 0:2ceba7f90dd4 70 */
dreschpe 0:2ceba7f90dd4 71 class TextLCD : public Stream {
dreschpe 0:2ceba7f90dd4 72 public:
dreschpe 0:2ceba7f90dd4 73
dreschpe 0:2ceba7f90dd4 74 /** LCD panel format */
dreschpe 0:2ceba7f90dd4 75 enum LCDType {
dreschpe 0:2ceba7f90dd4 76 LCD16x2 /**< 16x2 LCD panel (default) */
dreschpe 0:2ceba7f90dd4 77 , LCD16x2B /**< 16x2 LCD panel alternate addressing */
dreschpe 0:2ceba7f90dd4 78 , LCD20x2 /**< 20x2 LCD panel */
dreschpe 0:2ceba7f90dd4 79 , LCD20x4 /**< 20x4 LCD panel */
dreschpe 0:2ceba7f90dd4 80 };
dreschpe 0:2ceba7f90dd4 81
dreschpe 0:2ceba7f90dd4 82 /** Create a TextLCD interface
dreschpe 0:2ceba7f90dd4 83 *
dreschpe 0:2ceba7f90dd4 84 * @param rs Instruction/data control line
dreschpe 0:2ceba7f90dd4 85 * @param e Enable line (clock)
dreschpe 0:2ceba7f90dd4 86 * @param rw read / write
dreschpe 0:2ceba7f90dd4 87 * @param d0-d3 Data lines
dreschpe 0:2ceba7f90dd4 88 * @param type Sets the panel size/addressing mode (default = LCD16x2)
dreschpe 0:2ceba7f90dd4 89 */
dreschpe 0:2ceba7f90dd4 90 TextLCD(PinName rs, PinName rw, PinName e, PinName d0, PinName d1, PinName d2, PinName d3, LCDType type = LCD16x2);
dreschpe 0:2ceba7f90dd4 91
dreschpe 0:2ceba7f90dd4 92 #if DOXYGEN_ONLY
dreschpe 0:2ceba7f90dd4 93 /** Write a character to the LCD
dreschpe 0:2ceba7f90dd4 94 *
dreschpe 0:2ceba7f90dd4 95 * @param c The character to write to the display
dreschpe 0:2ceba7f90dd4 96 */
dreschpe 0:2ceba7f90dd4 97 int putc(int c);
dreschpe 0:2ceba7f90dd4 98
dreschpe 0:2ceba7f90dd4 99 /** Write a formated string to the LCD
dreschpe 0:2ceba7f90dd4 100 *
dreschpe 0:2ceba7f90dd4 101 * @param format A printf-style format string, followed by the
dreschpe 0:2ceba7f90dd4 102 * variables to use in formating the string.
dreschpe 0:2ceba7f90dd4 103 */
dreschpe 0:2ceba7f90dd4 104 int printf(const char* format, ...);
dreschpe 0:2ceba7f90dd4 105 #endif
dreschpe 0:2ceba7f90dd4 106
dreschpe 0:2ceba7f90dd4 107 /** Locate to a screen column and row
dreschpe 0:2ceba7f90dd4 108 *
dreschpe 0:2ceba7f90dd4 109 * @param column The horizontal position from the left, indexed from 0
dreschpe 0:2ceba7f90dd4 110 * @param row The vertical position from the top, indexed from 0
dreschpe 0:2ceba7f90dd4 111 */
dreschpe 0:2ceba7f90dd4 112 void locate(int column, int row);
dreschpe 0:2ceba7f90dd4 113
dreschpe 0:2ceba7f90dd4 114 /** Clear the screen and locate to 0,0 */
dreschpe 0:2ceba7f90dd4 115 void cls();
dreschpe 0:2ceba7f90dd4 116
dreschpe 0:2ceba7f90dd4 117 int rows();
dreschpe 0:2ceba7f90dd4 118 int columns();
dreschpe 1:ac2c6d0cc538 119
dreschpe 1:ac2c6d0cc538 120 /** write a user defined char
dreschpe 1:ac2c6d0cc538 121 *
dreschpe 1:ac2c6d0cc538 122 * @param address The user defined char (0-7)
dreschpe 1:ac2c6d0cc538 123 * @param pattern[8] bit pattern 5*8 of char
dreschpe 1:ac2c6d0cc538 124 */
dreschpe 0:2ceba7f90dd4 125 void writeCGRAM(int address, int pattern[8]);
dreschpe 1:ac2c6d0cc538 126
dreschpe 1:ac2c6d0cc538 127 /** Get the char at the current position
dreschpe 1:ac2c6d0cc538 128 *
dreschpe 1:ac2c6d0cc538 129 * int getc()
dreschpe 1:ac2c6d0cc538 130 */
dreschpe 1:ac2c6d0cc538 131
dreschpe 0:2ceba7f90dd4 132 protected:
dreschpe 0:2ceba7f90dd4 133
dreschpe 0:2ceba7f90dd4 134 // Stream implementation functions
dreschpe 0:2ceba7f90dd4 135 virtual int _putc(int value);
dreschpe 0:2ceba7f90dd4 136 virtual int _getc();
dreschpe 0:2ceba7f90dd4 137
dreschpe 0:2ceba7f90dd4 138 int address(int column, int row);
dreschpe 0:2ceba7f90dd4 139 void character(int column, int row, int c);
dreschpe 0:2ceba7f90dd4 140 void writeByte(int value);
dreschpe 0:2ceba7f90dd4 141 void writeCommand(int command);
dreschpe 0:2ceba7f90dd4 142 void writeData(int data);
dreschpe 0:2ceba7f90dd4 143 int readData();
dreschpe 0:2ceba7f90dd4 144 void waitBusy();
dreschpe 0:2ceba7f90dd4 145 DigitalOut _rs, _e, _rw;
dreschpe 0:2ceba7f90dd4 146 BusInOut _d;
dreschpe 0:2ceba7f90dd4 147 LCDType _type;
dreschpe 0:2ceba7f90dd4 148
dreschpe 0:2ceba7f90dd4 149 int _column;
dreschpe 0:2ceba7f90dd4 150 int _row;
dreschpe 0:2ceba7f90dd4 151 };
dreschpe 0:2ceba7f90dd4 152
dreschpe 0:2ceba7f90dd4 153 #endif