Final Report

Dependencies:   mbed

Fork of ecu_reader by Sukkin Pang

Committer:
LAvtec818
Date:
Mon Oct 27 02:46:55 2014 +0000
Revision:
6:dae9630af6e3
report

Who changed what in which revision?

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