LCD display

Dependents:   LAB05_Oppgave4

Fork of LCDLib by Rune Langoy

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers TextLCD.h Source File

TextLCD.h

00001 /* mbed TextLCD Library,4-bit 16x2 LCD for KS0066U
00002  * Copyright (c) 2015 Rune Langøy
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a copy
00005  * of this software and associated documentation files (the "Software"), to deal
00006  * in the Software without restriction, including without limitation the rights
00007  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008  * copies of the Software, and to permit persons to whom the Software is
00009  * furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included in
00012  * all copies or substantial portions of the Software.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00019  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00020  * THE SOFTWARE.
00021  */
00022 #ifndef LCD_H_
00023 #define LCD_H_
00024 
00025 /**  A TextLCD interface for driving 4-bit 16x2 KS0066U LCD
00026  *
00027  * Simple example:
00028  * @code
00029  * #include "mbed.h"
00030  * #include "TextLCD.h"
00031  *
00032  * TextLCD lcd(D11,D10,D9,D5,D4,D3,D2);
00033  * int main()
00034  * {
00035  *    lcd.gotoxy(1,1);
00036  *    lcd.printf("Hello");
00037  *
00038  *    lcd.gotoxy(1,2);
00039  *    lcd.printf("       World");
00040  *
00041  *    while(1) {
00042  *        wait_ms(300);
00043  *    }
00044  * }
00045  * @endcode
00046  */
00047 class TextLCD : public Stream
00048 {
00049 public:
00050 
00051 
00052     /** Create a TextLCD interface and initiated 16x2 char mode
00053       *
00054       * @param rs    Instruction/data control line
00055       * @param rw    Read/Write (is forced to '1')
00056       * @param e     Enable line (clock)
00057       * @param d4-d7 Data lines for using as a 4-bit interface
00058       * @param name  I/O stream name (Optional)
00059       * Stream example:
00060       * @code
00061       * #include "mbed.h"
00062       * #include "TextLCD.h"
00063       *
00064       * TextLCD lcd(D11,D10,D9,D5,D4,D3,D2,"lcdOut");
00065       * int main()
00066       * {
00067       *     freopen("/lcdOut", "w", stdout);
00068       *     printf("Hello World");
00069       *     while(1) {
00070       *         wait_ms(300);
00071       *     }
00072       * }
00073       * @endcode
00074       */
00075     TextLCD(PinName rs,PinName rw, PinName e, PinName d4, PinName d5,
00076             PinName d6, PinName d7,const char* name=NULL) ;
00077 
00078     /**  Writes the low nible of data to the LCD-module
00079       *
00080       * @param data  Writes the low-nible to the LCD data pins D4 to D7
00081       */
00082     void writeLcdBitD4toD7(char data);
00083 
00084     /**  Writes a Command to the LCD-module
00085      *
00086      * @param cmd command to be sendt to the LCD-Controller
00087      */
00088     void lcdCommand(unsigned char cmd);
00089 
00090 
00091     /**  Writes charecters to the LCD display
00092      *
00093      * @param data char to be sendt to the LCD-Controller
00094      */
00095     void lcdData(unsigned char data);
00096 
00097     /** moves text cursor to a screen column and row
00098      *
00099      * @param column  The horizontal position from the left, indexed from 0
00100      * @param row     The vertical position from the top, indexed from 0
00101      */
00102     void gotoxy(int , int );
00103 #if DOXYGEN_ONLY
00104     /** Write a character to the LCD
00105      *
00106      * @param c The character to write to the display
00107      */
00108     int putc(int c);
00109 
00110     /** Write a formatted string to the LCD
00111      *
00112      * @param format A printf-style format string, followed by the
00113      *               variables to use in formatting the string.
00114      */
00115     int printf(const char* format, ...);
00116 #endif
00117 protected:
00118     // EN = 1 for L-to-H /
00119     // EN = 0 for H-to-L
00120     // Causes the LCD-module to read the data on the data input pins
00121     void pulseEn();
00122     //Enable 4 bit mode  From KS0066U Documentation
00123     void init_4BitMode2LinesDisplayOn();
00124 
00125     // Stream implementation functions
00126     virtual int _putc(int value);
00127     virtual int _getc();
00128 
00129     DigitalOut LCD_RS,LCD_RW,LCD_EN;
00130     BusOut LCD_D4to7;
00131 };
00132 
00133 #endif /* LCD_H_ */