Oct122012mbedLab

Dependents:   Lab3_VoiceMeter

Fork of TextLCD by Simon Ford

Committer:
psawant9
Date:
Fri Oct 12 16:02:26 2012 +0000
Revision:
8:bd49ebdd4f64
Parent:
5:a53b3e2d6f1e
Done

Who changed what in which revision?

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