Fork tetxldc

Fork of TextLCD_piano by Adeline Galasso

Committer:
aknin001
Date:
Tue Jul 03 02:04:42 2018 +0000
Revision:
10:4276b56b4400
Parent:
9:05c9b97e4a91
piano with 4  octaves and 8 notes, bug display notes

Who changed what in which revision?

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