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