Adapted code from original GT_Tuner code (by Andrew Durand) for a school project by Tapton School.

Dependencies:   mbed

Committer:
mptapton
Date:
Mon Feb 06 09:30:34 2017 +0000
Revision:
2:c242fd25e7e2
Parent:
0:6b0b61d411ad
Tapton School guitar project

Who changed what in which revision?

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