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