A TextLCD interface for driving 4-bit 16x2 KS0066U LCD

Dependents:   KS0066U4_16x2 LAB05_Oppgave4 LAB05_Oppgave2 LAB05_Oppgave3 ... more

Import program

00001  #include "mbed.h"
00002  #include "TextLCD.h"
00003  
00004  TextLCD lcd(D11,D10,D9,D5,D4,D3,D2);
00005  int main()
00006  {    
00007     lcd.gotoxy(1,1);
00008     lcd.printf("Hello");
00009  
00010     lcd.gotoxy(4,2);
00011     lcd.printf("World");
00012     
00013     while(1) {
00014         wait_ms(300);
00015     }
00016  }

Import library

Public Member Functions

TextLCD (PinName rs, PinName rw, PinName e, PinName d4, PinName d5, PinName d6, PinName d7, const char *name=NULL)
Create a TextLCD interface and initiated 16x2 char mode.
void lcdComand (unsigned char cmd)
Writes a Command to the LCD-module.
void lcdData (unsigned char data)
Writes charecters to the LCD display.
void gotoxy (int, int)
moves text cursor to a screen column and row
int putc (int c)
Write a character to the LCD.
int printf (const char *format,...)
Write a formatted string to the LCD.

Protected Member Functions

void writeLcdBitD4toD7 (char data)
Writes the low nible of data to the LCD-module.
void pulseEn ()
Causes the LCD-module to read the data on the data input pins EN = 1 for L-to-H / EN = 0 for H-to-L.
void init_4BitMode2LinesDisplayOn ()
Enable 4 bit mode From KS0066U Documentation.

/media/uploads/rlanghbv/lcdmoduletop.jpg /media/uploads/rlanghbv/lcdmodulebottom.jpg

Committer:
rlanghbv
Date:
Sun Sep 20 11:54:39 2015 +0000
Revision:
4:264d9b06bf60
Parent:
3:d2f70de20dbe
Child:
6:c80d81c3be4d
Doc Update

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rlanghbv 4:264d9b06bf60 1 /* mbed TextLCD Library,4-bit 16x2 LCD for KS0066U
rlanghbv 4:264d9b06bf60 2 * Copyright (c) 2015 Rune Langøy
rlanghbv 4:264d9b06bf60 3 *
rlanghbv 4:264d9b06bf60 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
rlanghbv 4:264d9b06bf60 5 * of this software and associated documentation files (the "Software"), to deal
rlanghbv 4:264d9b06bf60 6 * in the Software without restriction, including without limitation the rights
rlanghbv 4:264d9b06bf60 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
rlanghbv 4:264d9b06bf60 8 * copies of the Software, and to permit persons to whom the Software is
rlanghbv 4:264d9b06bf60 9 * furnished to do so, subject to the following conditions:
rlanghbv 1:8902f6be12a5 10 *
rlanghbv 4:264d9b06bf60 11 * The above copyright notice and this permission notice shall be included in
rlanghbv 4:264d9b06bf60 12 * all copies or substantial portions of the Software.
rlanghbv 4:264d9b06bf60 13 *
rlanghbv 4:264d9b06bf60 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
rlanghbv 4:264d9b06bf60 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
rlanghbv 4:264d9b06bf60 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
rlanghbv 4:264d9b06bf60 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
rlanghbv 4:264d9b06bf60 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
rlanghbv 4:264d9b06bf60 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
rlanghbv 4:264d9b06bf60 20 * THE SOFTWARE.
rlanghbv 4:264d9b06bf60 21 */
rlanghbv 1:8902f6be12a5 22 #ifndef LCD_H_
rlanghbv 1:8902f6be12a5 23 #define LCD_H_
rlanghbv 4:264d9b06bf60 24
rlanghbv 4:264d9b06bf60 25 /** A TextLCD interface for driving 4-bit 16x2 KS0066U LCD
rlanghbv 4:264d9b06bf60 26 *
rlanghbv 4:264d9b06bf60 27 * @code
rlanghbv 4:264d9b06bf60 28 * #include "mbed.h"
rlanghbv 4:264d9b06bf60 29 * #include "TextLCD.h"
rlanghbv 4:264d9b06bf60 30 *
rlanghbv 4:264d9b06bf60 31 * TextLCD lcd(D11,D10,D9,D5,D4,D3,D2);
rlanghbv 4:264d9b06bf60 32 * int main()
rlanghbv 4:264d9b06bf60 33 * {
rlanghbv 4:264d9b06bf60 34 * lcd.gotoxy(1,1);
rlanghbv 4:264d9b06bf60 35 * lcd.printf("Hello");
rlanghbv 4:264d9b06bf60 36 *
rlanghbv 4:264d9b06bf60 37 * lcd.gotoxy(1,2);
rlanghbv 4:264d9b06bf60 38 * lcd.printf(" World");
rlanghbv 4:264d9b06bf60 39 *
rlanghbv 4:264d9b06bf60 40 * while(1) {
rlanghbv 4:264d9b06bf60 41 * wait_ms(300);
rlanghbv 4:264d9b06bf60 42 * }
rlanghbv 4:264d9b06bf60 43 * }
rlanghbv 4:264d9b06bf60 44 * @endcode
rlanghbv 4:264d9b06bf60 45 */
rlanghbv 1:8902f6be12a5 46 class TextLCD : public Stream
rlanghbv 1:8902f6be12a5 47 {
rlanghbv 1:8902f6be12a5 48 public:
rlanghbv 1:8902f6be12a5 49
rlanghbv 4:264d9b06bf60 50
rlanghbv 4:264d9b06bf60 51 /** Create a TextLCD interface and initiated 16x2 char mode
rlanghbv 4:264d9b06bf60 52 *
rlanghbv 4:264d9b06bf60 53 * @param rs Instruction/data control line
rlanghbv 4:264d9b06bf60 54 * @param rw Read/Write (is forced to '1')
rlanghbv 4:264d9b06bf60 55 * @param e Enable line (clock)
rlanghbv 4:264d9b06bf60 56 * @param d4-d7 Data lines for using as a 4-bit interface
rlanghbv 4:264d9b06bf60 57 */
rlanghbv 3:d2f70de20dbe 58 TextLCD(PinName rs,PinName rw, PinName e, PinName d4, PinName d5,
rlanghbv 3:d2f70de20dbe 59 PinName d6, PinName d7) ;
rlanghbv 1:8902f6be12a5 60
rlanghbv 1:8902f6be12a5 61 //Writes the low lible of data to the LCD-module data pins D4 to D7
rlanghbv 1:8902f6be12a5 62 void writeLcdBitD4toD7(char );
rlanghbv 1:8902f6be12a5 63
rlanghbv 1:8902f6be12a5 64 //Writes the byte comand to the LCD-module using 4 bits mode
rlanghbv 1:8902f6be12a5 65 void lcdComand(unsigned char);
rlanghbv 1:8902f6be12a5 66
rlanghbv 1:8902f6be12a5 67 //Writes charecters to the LCD display
rlanghbv 1:8902f6be12a5 68 void lcdData(unsigned char);
rlanghbv 4:264d9b06bf60 69
rlanghbv 4:264d9b06bf60 70 /** moves text cursor to a screen column and row
rlanghbv 4:264d9b06bf60 71 *
rlanghbv 4:264d9b06bf60 72 * @param column The horizontal position from the left, indexed from 0
rlanghbv 4:264d9b06bf60 73 * @param row The vertical position from the top, indexed from 0
rlanghbv 4:264d9b06bf60 74 */
rlanghbv 4:264d9b06bf60 75 void gotoxy(int , int );
rlanghbv 1:8902f6be12a5 76
rlanghbv 4:264d9b06bf60 77 protected:
rlanghbv 4:264d9b06bf60 78 // EN = 1 for L-to-H /
rlanghbv 4:264d9b06bf60 79 // EN = 0 for H-to-L
rlanghbv 4:264d9b06bf60 80 // Causes the LCD-module to read the data on the data input pins
rlanghbv 4:264d9b06bf60 81 void pulseEn();
rlanghbv 1:8902f6be12a5 82 //Enable 4 bit mode From KS0066U Documentation
rlanghbv 1:8902f6be12a5 83 void init_4BitMode2LinesDisplayOn();
rlanghbv 4:264d9b06bf60 84
rlanghbv 1:8902f6be12a5 85 // Stream implementation functions
rlanghbv 4:264d9b06bf60 86 /** Write a character to the LCD
rlanghbv 4:264d9b06bf60 87 *
rlanghbv 4:264d9b06bf60 88 * @param c The character to write to the display
rlanghbv 4:264d9b06bf60 89 */
rlanghbv 1:8902f6be12a5 90 virtual int _putc(int value);
rlanghbv 1:8902f6be12a5 91 virtual int _getc();
rlanghbv 3:d2f70de20dbe 92
rlanghbv 3:d2f70de20dbe 93 DigitalOut LCD_RS,LCD_RW,LCD_EN;
rlanghbv 3:d2f70de20dbe 94 DigitalOut LCD_D4,LCD_D5,LCD_D6,LCD_D7;
rlanghbv 1:8902f6be12a5 95 };
rlanghbv 1:8902f6be12a5 96
rlanghbv 1:8902f6be12a5 97 #endif /* LCD_H_ */