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 17:08:38 2015 +0000
Revision:
12:296a9b15ecd1
Parent:
11:0af18f5aa473
Child:
13:76853cda9655
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 6:c80d81c3be4d 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 6:c80d81c3be4d 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 6:c80d81c3be4d 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 12:296a9b15ecd1 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 6:c80d81c3be4d 46 class TextLCD : public Stream
rlanghbv 1:8902f6be12a5 47 {
rlanghbv 1:8902f6be12a5 48 public:
rlanghbv 1:8902f6be12a5 49
rlanghbv 4:264d9b06bf60 50
rlanghbv 6:c80d81c3be4d 51 /** Create a TextLCD interface and initiated 16x2 char mode
rlanghbv 6:c80d81c3be4d 52 *
rlanghbv 6:c80d81c3be4d 53 * @param rs Instruction/data control line
rlanghbv 6:c80d81c3be4d 54 * @param rw Read/Write (is forced to '1')
rlanghbv 6:c80d81c3be4d 55 * @param e Enable line (clock)
rlanghbv 6:c80d81c3be4d 56 * @param d4-d7 Data lines for using as a 4-bit interface
rlanghbv 9:9529e943259c 57 * @param name I/O stream name (Optional)
rlanghbv 11:0af18f5aa473 58 * Stream example:
rlanghbv 9:9529e943259c 59 * @code
rlanghbv 9:9529e943259c 60 * #include "mbed.h"
rlanghbv 9:9529e943259c 61 * #include "TextLCD.h"
rlanghbv 9:9529e943259c 62 *
rlanghbv 9:9529e943259c 63 * TextLCD lcd(D11,D10,D9,D5,D4,D3,D2,"lcdOut");
rlanghbv 9:9529e943259c 64 * int main()
rlanghbv 9:9529e943259c 65 * {
rlanghbv 9:9529e943259c 66 * freopen("/lcdOut", "w", stdout);
rlanghbv 9:9529e943259c 67 * printf("Hello World");
rlanghbv 9:9529e943259c 68 * while(1) {
rlanghbv 9:9529e943259c 69 * wait_ms(300);
rlanghbv 9:9529e943259c 70 * }
rlanghbv 9:9529e943259c 71 * }
rlanghbv 11:0af18f5aa473 72 * @endcode
rlanghbv 6:c80d81c3be4d 73 */
rlanghbv 6:c80d81c3be4d 74 TextLCD(PinName rs,PinName rw, PinName e, PinName d4, PinName d5,
rlanghbv 9:9529e943259c 75 PinName d6, PinName d7,const char* name) ;
rlanghbv 6:c80d81c3be4d 76
rlanghbv 6:c80d81c3be4d 77 //
rlanghbv 6:c80d81c3be4d 78
rlanghbv 6:c80d81c3be4d 79 /** Writes the low nible of data to the LCD-module
rlanghbv 6:c80d81c3be4d 80 *
rlanghbv 6:c80d81c3be4d 81 * @param data Writes the low-nible to the LCD data pins D4 to D7
rlanghbv 6:c80d81c3be4d 82 */
rlanghbv 6:c80d81c3be4d 83 void writeLcdBitD4toD7(char data);
rlanghbv 6:c80d81c3be4d 84
rlanghbv 6:c80d81c3be4d 85 /** Writes a Command to the LCD-module
rlanghbv 4:264d9b06bf60 86 *
rlanghbv 6:c80d81c3be4d 87 * @param cmd command to be sendt to the LCD-Controller
rlanghbv 4:264d9b06bf60 88 */
rlanghbv 6:c80d81c3be4d 89 void lcdComand(unsigned char cmd);
rlanghbv 6:c80d81c3be4d 90
rlanghbv 6:c80d81c3be4d 91
rlanghbv 6:c80d81c3be4d 92 /** Writes charecters to the LCD display
rlanghbv 6:c80d81c3be4d 93 *
rlanghbv 6:c80d81c3be4d 94 * @param data char to be sendt to the LCD-Controller
rlanghbv 6:c80d81c3be4d 95 */
rlanghbv 6:c80d81c3be4d 96 void lcdData(unsigned char data);
rlanghbv 6:c80d81c3be4d 97
rlanghbv 4:264d9b06bf60 98 /** moves text cursor to a screen column and row
rlanghbv 4:264d9b06bf60 99 *
rlanghbv 4:264d9b06bf60 100 * @param column The horizontal position from the left, indexed from 0
rlanghbv 4:264d9b06bf60 101 * @param row The vertical position from the top, indexed from 0
rlanghbv 4:264d9b06bf60 102 */
rlanghbv 4:264d9b06bf60 103 void gotoxy(int , int );
rlanghbv 6:c80d81c3be4d 104 #if DOXYGEN_ONLY
rlanghbv 6:c80d81c3be4d 105 /** Write a character to the LCD
rlanghbv 6:c80d81c3be4d 106 *
rlanghbv 6:c80d81c3be4d 107 * @param c The character to write to the display
rlanghbv 6:c80d81c3be4d 108 */
rlanghbv 6:c80d81c3be4d 109 int putc(int c);
rlanghbv 6:c80d81c3be4d 110
rlanghbv 6:c80d81c3be4d 111 /** Write a formatted string to the LCD
rlanghbv 6:c80d81c3be4d 112 *
rlanghbv 6:c80d81c3be4d 113 * @param format A printf-style format string, followed by the
rlanghbv 6:c80d81c3be4d 114 * variables to use in formatting the string.
rlanghbv 6:c80d81c3be4d 115 */
rlanghbv 6:c80d81c3be4d 116 int printf(const char* format, ...);
rlanghbv 6:c80d81c3be4d 117 #endif
rlanghbv 4:264d9b06bf60 118 protected:
rlanghbv 4:264d9b06bf60 119 // EN = 1 for L-to-H /
rlanghbv 4:264d9b06bf60 120 // EN = 0 for H-to-L
rlanghbv 4:264d9b06bf60 121 // Causes the LCD-module to read the data on the data input pins
rlanghbv 4:264d9b06bf60 122 void pulseEn();
rlanghbv 1:8902f6be12a5 123 //Enable 4 bit mode From KS0066U Documentation
rlanghbv 1:8902f6be12a5 124 void init_4BitMode2LinesDisplayOn();
rlanghbv 6:c80d81c3be4d 125
rlanghbv 1:8902f6be12a5 126 // Stream implementation functions
rlanghbv 1:8902f6be12a5 127 virtual int _putc(int value);
rlanghbv 1:8902f6be12a5 128 virtual int _getc();
rlanghbv 6:c80d81c3be4d 129
rlanghbv 3:d2f70de20dbe 130 DigitalOut LCD_RS,LCD_RW,LCD_EN;
rlanghbv 8:b12188ddd403 131 BusOut LCD_D4to7;
rlanghbv 1:8902f6be12a5 132 };
rlanghbv 1:8902f6be12a5 133
rlanghbv 1:8902f6be12a5 134 #endif /* LCD_H_ */