Thomas Milburn
/
FBRDash-tom
can't push chnages :(
Fork of FBRDash by
TextLCD/TextLCD.h@0:1f422ed56e0f, 2011-11-03 (annotated)
- Committer:
- intrinseca
- Date:
- Thu Nov 03 20:38:12 2011 +0000
- Revision:
- 0:1f422ed56e0f
Test Program
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
intrinseca |
0:1f422ed56e0f | 1 | /* mbed TextLCD Library, for a 4-bit LCD based on HD44780 |
intrinseca |
0:1f422ed56e0f | 2 | * Copyright (c) 2007-2010, sford, http://mbed.org |
intrinseca |
0:1f422ed56e0f | 3 | * |
intrinseca |
0:1f422ed56e0f | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
intrinseca |
0:1f422ed56e0f | 5 | * of this software and associated documentation files (the "Software"), to deal |
intrinseca |
0:1f422ed56e0f | 6 | * in the Software without restriction, including without limitation the rights |
intrinseca |
0:1f422ed56e0f | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
intrinseca |
0:1f422ed56e0f | 8 | * copies of the Software, and to permit persons to whom the Software is |
intrinseca |
0:1f422ed56e0f | 9 | * furnished to do so, subject to the following conditions: |
intrinseca |
0:1f422ed56e0f | 10 | * |
intrinseca |
0:1f422ed56e0f | 11 | * The above copyright notice and this permission notice shall be included in |
intrinseca |
0:1f422ed56e0f | 12 | * all copies or substantial portions of the Software. |
intrinseca |
0:1f422ed56e0f | 13 | * |
intrinseca |
0:1f422ed56e0f | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
intrinseca |
0:1f422ed56e0f | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
intrinseca |
0:1f422ed56e0f | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
intrinseca |
0:1f422ed56e0f | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
intrinseca |
0:1f422ed56e0f | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
intrinseca |
0:1f422ed56e0f | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
intrinseca |
0:1f422ed56e0f | 20 | * THE SOFTWARE. |
intrinseca |
0:1f422ed56e0f | 21 | */ |
intrinseca |
0:1f422ed56e0f | 22 | |
intrinseca |
0:1f422ed56e0f | 23 | #ifndef MBED_TEXTLCD_H |
intrinseca |
0:1f422ed56e0f | 24 | #define MBED_TEXTLCD_H |
intrinseca |
0:1f422ed56e0f | 25 | |
intrinseca |
0:1f422ed56e0f | 26 | #include "mbed.h" |
intrinseca |
0:1f422ed56e0f | 27 | |
intrinseca |
0:1f422ed56e0f | 28 | /** A TextLCD interface for driving 4-bit HD44780-based LCDs |
intrinseca |
0:1f422ed56e0f | 29 | * |
intrinseca |
0:1f422ed56e0f | 30 | * Currently supports 16x2, 20x2 and 20x4 panels |
intrinseca |
0:1f422ed56e0f | 31 | * |
intrinseca |
0:1f422ed56e0f | 32 | * @code |
intrinseca |
0:1f422ed56e0f | 33 | * #include "mbed.h" |
intrinseca |
0:1f422ed56e0f | 34 | * #include "TextLCD.h" |
intrinseca |
0:1f422ed56e0f | 35 | * |
intrinseca |
0:1f422ed56e0f | 36 | * TextLCD lcd(p10, p12, ,p13, p15, p16, p29, p30); // rs, rw, e, d0-d3 |
intrinseca |
0:1f422ed56e0f | 37 | * |
intrinseca |
0:1f422ed56e0f | 38 | * int main() { |
intrinseca |
0:1f422ed56e0f | 39 | * lcd.printf("Hello mbed\n"); |
intrinseca |
0:1f422ed56e0f | 40 | * |
intrinseca |
0:1f422ed56e0f | 41 | * //define user chars |
intrinseca |
0:1f422ed56e0f | 42 | * int pattern[8]; |
intrinseca |
0:1f422ed56e0f | 43 | * int pattern1[8]; |
intrinseca |
0:1f422ed56e0f | 44 | * pattern[0] = 1; // * |
intrinseca |
0:1f422ed56e0f | 45 | * pattern[1] = 3; // ** |
intrinseca |
0:1f422ed56e0f | 46 | * pattern[2] = 5; // * * |
intrinseca |
0:1f422ed56e0f | 47 | * pattern[3] = 9; // * * |
intrinseca |
0:1f422ed56e0f | 48 | * pattern[4] = 0x11; // * * |
intrinseca |
0:1f422ed56e0f | 49 | * pattern[5] = 0x19; // ** * |
intrinseca |
0:1f422ed56e0f | 50 | * pattern[6] = 0x1d; // *** * |
intrinseca |
0:1f422ed56e0f | 51 | * pattern[7] = 0x1f; // ***** |
intrinseca |
0:1f422ed56e0f | 52 | * |
intrinseca |
0:1f422ed56e0f | 53 | * pattern1[0] = 0x10; // * |
intrinseca |
0:1f422ed56e0f | 54 | * pattern1[1] = 0x18; // ** |
intrinseca |
0:1f422ed56e0f | 55 | * pattern1[2] = 0x14; // * * |
intrinseca |
0:1f422ed56e0f | 56 | * pattern1[3] = 0x12; // * * |
intrinseca |
0:1f422ed56e0f | 57 | * pattern1[4] = 0x11; // * * |
intrinseca |
0:1f422ed56e0f | 58 | * pattern1[5] = 0x13; // * ** |
intrinseca |
0:1f422ed56e0f | 59 | * pattern1[6] = 0x17; // * *** |
intrinseca |
0:1f422ed56e0f | 60 | * pattern1[7] = 0x1f; // ***** |
intrinseca |
0:1f422ed56e0f | 61 | * |
intrinseca |
0:1f422ed56e0f | 62 | * lcd.writeCGRAM(0, pattern); |
intrinseca |
0:1f422ed56e0f | 63 | * lcd.writeCGRAM(1, pattern1); |
intrinseca |
0:1f422ed56e0f | 64 | * |
intrinseca |
0:1f422ed56e0f | 65 | * lcd.locate(15,0); |
intrinseca |
0:1f422ed56e0f | 66 | * lcd.putc(0); // user pattern 0 |
intrinseca |
0:1f422ed56e0f | 67 | * lcd.putc(1); // user pattern 1 |
intrinseca |
0:1f422ed56e0f | 68 | * } |
intrinseca |
0:1f422ed56e0f | 69 | * @endcode |
intrinseca |
0:1f422ed56e0f | 70 | */ |
intrinseca |
0:1f422ed56e0f | 71 | class TextLCD : public Stream { |
intrinseca |
0:1f422ed56e0f | 72 | public: |
intrinseca |
0:1f422ed56e0f | 73 | |
intrinseca |
0:1f422ed56e0f | 74 | /** LCD panel format */ |
intrinseca |
0:1f422ed56e0f | 75 | enum LCDType { |
intrinseca |
0:1f422ed56e0f | 76 | LCD16x2 /**< 16x2 LCD panel (default) */ |
intrinseca |
0:1f422ed56e0f | 77 | , LCD16x2B /**< 16x2 LCD panel alternate addressing */ |
intrinseca |
0:1f422ed56e0f | 78 | , LCD20x2 /**< 20x2 LCD panel */ |
intrinseca |
0:1f422ed56e0f | 79 | , LCD20x4 /**< 20x4 LCD panel */ |
intrinseca |
0:1f422ed56e0f | 80 | }; |
intrinseca |
0:1f422ed56e0f | 81 | |
intrinseca |
0:1f422ed56e0f | 82 | /** Create a TextLCD interface |
intrinseca |
0:1f422ed56e0f | 83 | * |
intrinseca |
0:1f422ed56e0f | 84 | * @param rs Instruction/data control line |
intrinseca |
0:1f422ed56e0f | 85 | * @param e Enable line (clock) |
intrinseca |
0:1f422ed56e0f | 86 | * @param rw read / write |
intrinseca |
0:1f422ed56e0f | 87 | * @param d0-d3 Data lines |
intrinseca |
0:1f422ed56e0f | 88 | * @param type Sets the panel size/addressing mode (default = LCD16x2) |
intrinseca |
0:1f422ed56e0f | 89 | */ |
intrinseca |
0:1f422ed56e0f | 90 | TextLCD(PinName rs, PinName rw, PinName e, PinName d0, PinName d1, PinName d2, PinName d3, LCDType type = LCD16x2); |
intrinseca |
0:1f422ed56e0f | 91 | |
intrinseca |
0:1f422ed56e0f | 92 | #if DOXYGEN_ONLY |
intrinseca |
0:1f422ed56e0f | 93 | /** Write a character to the LCD |
intrinseca |
0:1f422ed56e0f | 94 | * |
intrinseca |
0:1f422ed56e0f | 95 | * @param c The character to write to the display |
intrinseca |
0:1f422ed56e0f | 96 | */ |
intrinseca |
0:1f422ed56e0f | 97 | int putc(int c); |
intrinseca |
0:1f422ed56e0f | 98 | |
intrinseca |
0:1f422ed56e0f | 99 | /** Write a formated string to the LCD |
intrinseca |
0:1f422ed56e0f | 100 | * |
intrinseca |
0:1f422ed56e0f | 101 | * @param format A printf-style format string, followed by the |
intrinseca |
0:1f422ed56e0f | 102 | * variables to use in formating the string. |
intrinseca |
0:1f422ed56e0f | 103 | */ |
intrinseca |
0:1f422ed56e0f | 104 | int printf(const char* format, ...); |
intrinseca |
0:1f422ed56e0f | 105 | #endif |
intrinseca |
0:1f422ed56e0f | 106 | |
intrinseca |
0:1f422ed56e0f | 107 | /** Locate to a screen column and row |
intrinseca |
0:1f422ed56e0f | 108 | * |
intrinseca |
0:1f422ed56e0f | 109 | * @param column The horizontal position from the left, indexed from 0 |
intrinseca |
0:1f422ed56e0f | 110 | * @param row The vertical position from the top, indexed from 0 |
intrinseca |
0:1f422ed56e0f | 111 | */ |
intrinseca |
0:1f422ed56e0f | 112 | void locate(int column, int row); |
intrinseca |
0:1f422ed56e0f | 113 | |
intrinseca |
0:1f422ed56e0f | 114 | /** Clear the screen and locate to 0,0 */ |
intrinseca |
0:1f422ed56e0f | 115 | void cls(); |
intrinseca |
0:1f422ed56e0f | 116 | |
intrinseca |
0:1f422ed56e0f | 117 | int rows(); |
intrinseca |
0:1f422ed56e0f | 118 | int columns(); |
intrinseca |
0:1f422ed56e0f | 119 | |
intrinseca |
0:1f422ed56e0f | 120 | /** write a user defined char |
intrinseca |
0:1f422ed56e0f | 121 | * |
intrinseca |
0:1f422ed56e0f | 122 | * @param address The user defined char (0-7) |
intrinseca |
0:1f422ed56e0f | 123 | * @param pattern[8] bit pattern 5*8 of char |
intrinseca |
0:1f422ed56e0f | 124 | */ |
intrinseca |
0:1f422ed56e0f | 125 | void writeCGRAM(int address, int pattern[8]); |
intrinseca |
0:1f422ed56e0f | 126 | |
intrinseca |
0:1f422ed56e0f | 127 | /** Get the char at the current position |
intrinseca |
0:1f422ed56e0f | 128 | * |
intrinseca |
0:1f422ed56e0f | 129 | * int getc() |
intrinseca |
0:1f422ed56e0f | 130 | */ |
intrinseca |
0:1f422ed56e0f | 131 | |
intrinseca |
0:1f422ed56e0f | 132 | protected: |
intrinseca |
0:1f422ed56e0f | 133 | |
intrinseca |
0:1f422ed56e0f | 134 | // Stream implementation functions |
intrinseca |
0:1f422ed56e0f | 135 | virtual int _putc(int value); |
intrinseca |
0:1f422ed56e0f | 136 | virtual int _getc(); |
intrinseca |
0:1f422ed56e0f | 137 | |
intrinseca |
0:1f422ed56e0f | 138 | int address(int column, int row); |
intrinseca |
0:1f422ed56e0f | 139 | void character(int column, int row, int c); |
intrinseca |
0:1f422ed56e0f | 140 | void writeByte(int value); |
intrinseca |
0:1f422ed56e0f | 141 | void writeCommand(int command); |
intrinseca |
0:1f422ed56e0f | 142 | void writeData(int data); |
intrinseca |
0:1f422ed56e0f | 143 | int readData(); |
intrinseca |
0:1f422ed56e0f | 144 | void waitBusy(); |
intrinseca |
0:1f422ed56e0f | 145 | DigitalOut _rs, _rw, _e; |
intrinseca |
0:1f422ed56e0f | 146 | BusInOut _d; |
intrinseca |
0:1f422ed56e0f | 147 | LCDType _type; |
intrinseca |
0:1f422ed56e0f | 148 | |
intrinseca |
0:1f422ed56e0f | 149 | int _column; |
intrinseca |
0:1f422ed56e0f | 150 | int _row; |
intrinseca |
0:1f422ed56e0f | 151 | }; |
intrinseca |
0:1f422ed56e0f | 152 | |
intrinseca |
0:1f422ed56e0f | 153 | #endif |