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