Functions test with Optrex LCD 20x4

Dependencies:   mbed

Dependents:   DatatypesLength AsciiCode IntegerFormatSpecifiers FloatFormatSpecifier

Committer:
Eduard
Date:
Mon Nov 22 21:58:23 2010 +0000
Revision:
0:ef7b6dec773f
Enable puls duration 75us instead of 40us and cls duration 3ms instead of1.64ms

Who changed what in which revision?

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