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:
- 0:4fbfa76a5bdb
- Child:
- 1:707fccd6c949
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LCD.cpp Sun Feb 28 03:26:28 2021 +0000 @@ -0,0 +1,87 @@ +#include "mbed.h" +#include "LCD.h" +#include <string> + +//Code for Newhaven NHD‐0216K3Z‐FL‐GBW LCD interfaced to FRDM-K64F via I2C +LCD::LCD() : i2c(PIN_SCL, PIN_SDA){ + LCD_init(); +} + +void LCD::LCD_init(void) { + + //LCD Initiations--------------------------------------- + + i2c.frequency(LCD_FREQ); //Corresponds to 50KHz + + char cmd[3]; + + cmd[0] = 0xFE; //For all cases + + cmd[1] = 0x52; + cmd[2] = 40; //contrast 1 - 50 + i2c.write(addr, cmd, 3); + + cmd[1] = 0x53; + cmd[2] = 8; //Backlight 1-8 + i2c.write(addr, cmd, 3); + + cmd[1] = 0x48; + i2c.write(addr, cmd, 2); //Underline cursor off + + cmd[1] = 0x46; + i2c.write(addr, cmd, 2); //Cursor Home + +} //END LCD_init + + +void LCD::clearLCD(void) { + + char cmd[3]; + cmd[0] = 0xFE; + wait_us(100); + + cmd[1] = 0x51; + i2c.write(addr, cmd, 2); //clear current display + + cmd[1] = 0x46; + i2c.write(addr, cmd, 2); //Cursor Home + +} //END clearLCD + + +void LCD::LCD_display(string topLine, string bottomLine) { + + char cmd[] = " "; //Long enough to send a complete line of text + + + clearLCD(); //Clear before display + + wait_us(LCD_DELAY); //Short Delay + + int i; + + for(i=0;(i<16 && i < topLine.length());i++) { //Display top line + cmd[i]=topLine[i]; + } + i2c.write(addr,cmd,16); + + cmd[0] = 0xFE; //Since it was overwritten above + cmd[1] = 0x45; + cmd[2] = 0x40; //LCD Cursor to next line + 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 + cmd[i]=bottomLine[i]; + } + i2c.write(addr,cmd,16); + cmd[0] = 0xFE; //Since it was overwritten above + + } //END LCD_display + + + + + +