论坛» 活动中心» 板卡试用

3、在mbed中使用LCD1602

助工
2018-12-13 13:17 1楼

1. 使用mbed控制lcd的代码和arduino非常相似。

下面是arduino的代码。


// include the library code:

#include


// initialize the library by associating any needed LCD interface pin

// with the arduino pin number it is connected to

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;

//LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);


void setup() {

// set up the LCD's number of columns and rows:

lcd.begin(16, 2);

// Print a message to the LCD.

lcd.print("hello, world!");

}


void loop() {

// set the cursor to column 0, line 1

// (note: line 1 is the second row, since counting begins with 0):

lcd.setCursor(0, 1);

// print the number of seconds since reset:

lcd.print(millis() / 1000);

}


2. 同时如下为mbed的代码。

#include "mbed.h"

#include "TextLCD.h"


Serial pc(SERIAL_TX, SERIAL_RX);

AnalogIn button(A0); // Init button (SELECT, LEFT, UP, DOWN, RIGHT)

// LCD (RS, E, D4, D5, D6, D7);

//TextLCD lcd(D8, D9, D4, D5, D6, D7);

TextLCD lcd(D8, D9, D4, D5, D6, D7);

PwmOut backlight(D10); // Backlight LCD

DigitalOut led(LED1);


int main() {

// Set backlight period and duty cycle

backlight.period(0.002);

backlight = 1;

while(1) {

lcd.cls(); // Clear LCD

lcd.locate(1,0); // Set locate (1 row, 2 column)

lcd.printf("LCD Key Shield");

wait(1);

}


}

编译后的文件


Downloads.rar

3. 代码编辑如图,

捕获.JPG

4. 引脚的连接方式是,其中lcd偏置电阻在1k-5k之间,调整VL的电压。背光电源A-K也要连接对正反方向。


1012524fyzbwzbr4awy1yb.jpg

显示后效果如下,

1212663268.jpg





625952348.jpg


因为背光调整原因,显示还有些问题,继续调整。





高工
2018-12-14 09:22 2楼

谢谢楼主分享

共2条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册]