Yoann Bonnard / TextLCD
Committer:
Bonnardy
Date:
Thu May 25 13:01:49 2017 +0000
Revision:
0:3d764ac53494
Add code ihm

Who changed what in which revision?

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