Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: LCD.cpp
- Revision:
- 2:e3d3eaa27040
- Parent:
- 1:707fccd6c949
- Child:
- 3:a65abeda9231
--- a/LCD.cpp Tue Mar 02 03:32:43 2021 +0000 +++ b/LCD.cpp Mon Mar 08 14:33:47 2021 +0000 @@ -5,13 +5,15 @@ //Code for Newhaven NHD‐0216K3Z‐FL‐GBW LCD interfaced to FRDM-K64F via I2C LCD::LCD() : i2c(PIN_SCL, PIN_SDA){ LCD_init(); + clearLCD(); + wait_us(LCD_DELAY); //wait for stabilization } void LCD::LCD_init(void) { //LCD Initiations--------------------------------------- - i2c.frequency(LCD_FREQ); //Corresponds to 50KHz + i2c.frequency(LCD_FREQ); char cmd[3]; @@ -50,16 +52,18 @@ void LCD::LCD_display(string topLine, string bottomLine) { - char cmd[] = " "; //Long enough to send a complete line of text + int i; + + char cmd[16]; //Long enough to send a complete line of text + for(i = 0; i < 16; i++) + cmd[i] = ' '; clearLCD(); //Clear before display wait_us(LCD_DELAY); //Short Delay - - int i; - for(i=0;(i<16 && i < topLine.length());i++) { //Display top line + for(i=0;i < topLine.length();i++) { //Display top line cmd[i]=topLine[i]; } i2c.write(addr,cmd,16); @@ -70,8 +74,10 @@ i2c.write(addr, cmd, 3); wait_us(LCD_DELAY); //Delay between writing lines - - for(i=0;(i<16 && i < topLine.length());i++) { //Display bottom line + + for(i = 0; i < 16; i++) + cmd[i] = ' '; + for(i=0;i < bottomLine.length();i++) { //Display bottom line cmd[i]=bottomLine[i]; } i2c.write(addr,cmd,16);