Michael Fischler / Mbed 2 deprecated Contest_Winner

Dependencies:   mbed

Committer:
mafischl
Date:
Thu Oct 13 18:01:31 2011 +0000
Revision:
1:5a7cce9994a3
Parent:
0:d9266031f832

        

Who changed what in which revision?

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