平成24年中国四国技術職員研修用

Dependencies:   MSCUsbHost NetServices RPCInterface TextLCD mbed

Committer:
yueee_yt
Date:
Sat Aug 18 07:26:48 2012 +0000
Revision:
0:fd83f3540b1a
NTP????????

Who changed what in which revision?

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