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