joseph adamu / Mbed OS CW_final_thr

Fork of CW_copy by Calvin Kalintra

Committer:
joseph_adamu
Date:
Wed Jan 10 09:50:29 2018 +0000
Revision:
1:dc648c5624b9
version for export

Who changed what in which revision?

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