Traditional LCD library that has been modified to be used with a 16x4 LCD display along with using the 16bit Timer wait function used in the 'LCD_Wait' library to measure Pulsewidth

Dependents:   PulseWidthCapture_Program

Committer:
Ellor1
Date:
Thu Dec 11 08:59:57 2014 +0000
Revision:
1:6ad3406d5912
Parent:
0:473988c75437
Library to include 16x4 LCD

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Ellor1 1:6ad3406d5912 1 /***********************************************************************************************************************
Ellor1 1:6ad3406d5912 2 This library is based upon the original TextLCD library. This library has been modified so it can be used with a 16x4 LCD
Ellor1 1:6ad3406d5912 3 The traditional 'wait' function has been chnaged to use 16 bit Timer 1 rather than 32 bit Timer 0 which is what is set up
Ellor1 1:6ad3406d5912 4 usually in the mbed library. The reason for this change is so that the new wait function and this library could be used
Ellor1 1:6ad3406d5912 5 alongside a PulseWidthCapture program which needs to use the 32 bit timer.
Ellor1 1:6ad3406d5912 6
Ellor1 1:6ad3406d5912 7 This program requires Library 'LCD_Wait' to work
Ellor1 1:6ad3406d5912 8 Callum Ellor
Ellor1 1:6ad3406d5912 9 **************************************************************************************************************************/
Ellor1 0:473988c75437 10
Ellor1 0:473988c75437 11 #ifndef MBED_TEXTLCD_H
Ellor1 0:473988c75437 12 #define MBED_TEXTLCD_H
Ellor1 0:473988c75437 13
Ellor1 0:473988c75437 14 #include "mbed.h"
Ellor1 0:473988c75437 15
Ellor1 0:473988c75437 16 /** A TextLCD interface for driving 4-bit HD44780-based LCDs
Ellor1 0:473988c75437 17 *
Ellor1 0:473988c75437 18 * Currently supports 16x2, 20x2 and 20x4 panels
Ellor1 0:473988c75437 19 *
Ellor1 0:473988c75437 20 * @code
Ellor1 0:473988c75437 21 * #include "mbed.h"
Ellor1 0:473988c75437 22 * #include "TextLCD.h"
Ellor1 0:473988c75437 23 *
Ellor1 0:473988c75437 24 * TextLCD lcd(p10, p12, p15, p16, p29, p30); // rs, e, d4-d7
Ellor1 0:473988c75437 25 *
Ellor1 0:473988c75437 26 * int main() {
Ellor1 0:473988c75437 27 * lcd.printf("Hello World!\n");
Ellor1 0:473988c75437 28 * }
Ellor1 0:473988c75437 29 * @endcode
Ellor1 0:473988c75437 30 */
Ellor1 0:473988c75437 31 class TextLCD : public Stream {
Ellor1 0:473988c75437 32 public:
Ellor1 0:473988c75437 33
Ellor1 0:473988c75437 34 /** LCD panel format */
Ellor1 0:473988c75437 35 enum LCDType {
Ellor1 0:473988c75437 36 LCD16x2 /**< 16x2 LCD panel (default) */
Ellor1 0:473988c75437 37 , LCD16x2B /**< 16x2 LCD panel alternate addressing */
Ellor1 0:473988c75437 38 , LCD20x2 /**< 20x2 LCD panel */
Ellor1 0:473988c75437 39 , LCD20x4 /**< 20x4 LCD panel */
Ellor1 1:6ad3406d5912 40 , LCD16x4 /**< 16x4 LCD panel */ //added to work with 16x4
Ellor1 0:473988c75437 41 };
Ellor1 0:473988c75437 42
Ellor1 0:473988c75437 43 /** Create a TextLCD interface
Ellor1 0:473988c75437 44 *
Ellor1 0:473988c75437 45 * @param rs Instruction/data control line
Ellor1 0:473988c75437 46 * @param e Enable line (clock)
Ellor1 0:473988c75437 47 * @param d4-d7 Data lines for using as a 4-bit interface
Ellor1 0:473988c75437 48 * @param type Sets the panel size/addressing mode (default = LCD16x2)
Ellor1 0:473988c75437 49 */
Ellor1 0:473988c75437 50 TextLCD(PinName rs, PinName e, PinName d4, PinName d5, PinName d6, PinName d7, LCDType type = LCD16x2);
Ellor1 0:473988c75437 51
Ellor1 0:473988c75437 52 #if DOXYGEN_ONLY
Ellor1 0:473988c75437 53 /** Write a character to the LCD
Ellor1 0:473988c75437 54 *
Ellor1 0:473988c75437 55 * @param c The character to write to the display
Ellor1 0:473988c75437 56 */
Ellor1 0:473988c75437 57 int putc(int c);
Ellor1 0:473988c75437 58
Ellor1 0:473988c75437 59 /** Write a formated string to the LCD
Ellor1 0:473988c75437 60 *
Ellor1 0:473988c75437 61 * @param format A printf-style format string, followed by the
Ellor1 0:473988c75437 62 * variables to use in formating the string.
Ellor1 0:473988c75437 63 */
Ellor1 0:473988c75437 64 int printf(const char* format, ...);
Ellor1 0:473988c75437 65 #endif
Ellor1 0:473988c75437 66
Ellor1 0:473988c75437 67 /** Locate to a screen column and row
Ellor1 0:473988c75437 68 *
Ellor1 0:473988c75437 69 * @param column The horizontal position from the left, indexed from 0
Ellor1 0:473988c75437 70 * @param row The vertical position from the top, indexed from 0
Ellor1 0:473988c75437 71 */
Ellor1 0:473988c75437 72 void locate(int column, int row);
Ellor1 0:473988c75437 73
Ellor1 0:473988c75437 74 /** Clear the screen and locate to 0,0 */
Ellor1 0:473988c75437 75 void cls();
Ellor1 0:473988c75437 76
Ellor1 0:473988c75437 77 int rows();
Ellor1 0:473988c75437 78 int columns();
Ellor1 0:473988c75437 79
Ellor1 0:473988c75437 80 protected:
Ellor1 0:473988c75437 81
Ellor1 0:473988c75437 82 // Stream implementation functions
Ellor1 0:473988c75437 83 virtual int _putc(int value);
Ellor1 0:473988c75437 84 virtual int _getc();
Ellor1 0:473988c75437 85
Ellor1 0:473988c75437 86 int address(int column, int row);
Ellor1 0:473988c75437 87 void character(int column, int row, int c);
Ellor1 0:473988c75437 88 void writeByte(int value);
Ellor1 0:473988c75437 89 void writeCommand(int command);
Ellor1 0:473988c75437 90 void writeData(int data);
Ellor1 0:473988c75437 91 int wait_n;
Ellor1 0:473988c75437 92
Ellor1 0:473988c75437 93 DigitalOut _rs, _e;
Ellor1 0:473988c75437 94 BusOut _d;
Ellor1 0:473988c75437 95 LCDType _type;
Ellor1 0:473988c75437 96
Ellor1 0:473988c75437 97 int _column;
Ellor1 0:473988c75437 98 int _row;
Ellor1 0:473988c75437 99
Ellor1 0:473988c75437 100 };
Ellor1 0:473988c75437 101
Ellor1 0:473988c75437 102 #endif