LPC1114 + I2c Lcd Mbed

LPC1114 + I2c Lcd Mbed. Use LPC1114 microcontroller and I2C Lcd module .

Fig.1 LPC1114 microcontroller
Fig.2 I2c Lcd module 
Connect Ldc module Vdd to 3.3V (MCU),GND(LCD) to GND(MPU), SDA(LCD) to dp5(MPU) ,SCL(LCD) to dp27(MCU).
 
Code
 
#include “mbed.h”

#define lcd_add ((uint8_t) 0x3E<<1)
I2C i2c(dp5, dp27);
void write_lcd(uint8_t reg_adr, uint8_t val){
    char cmd[2];
    cmd[0] = reg_adr;
    cmd[1] = val;
    i2c.write(lcd_add, cmd, 2); 
    wait_us(50);
}    
int main() {
    i2c.frequency(100000);
//lcd init
   write_lcd(0x00,0b00111000);
   wait(0.01);
   write_lcd(0x00,0b00111001);
   wait(0.01);
   write_lcd(0x00,0b00010100);
   wait(0.01);
   write_lcd(0x00,0b01111101);
   wait(0.01);
   write_lcd(0x00,0b01010110);
   wait(0.01);
   write_lcd(0x00,0b01101100);
   wait(0.01);
   write_lcd(0x00,0b00001100);
   wait(0.01);
   write_lcd(0x00,0b00000001);
   wait(0.01);
   int i,j=0;
    while(1){
        char buf[40]=”Hello, Welcome to www.ngolongtech.net”;
        for(i=j;i<=strlen(buf);i++){
            write_lcd(0x41,buf[i]);
        }
        j++;
        if(j==(strlen(buf)-10)){
            j=0;
        }
        write_lcd(0x00,0b00000010);
        wait(0.8);
    }
}
 

Sponsored Links: