1. 使用mbed控制lcd的代码和arduino非常相似。
下面是arduino的代码。
// include the library code:
#include <LiquidCrystal.h>
// 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);
}
}
编译后的文件
3. 代码编辑如图,
4. 引脚的连接方式是,其中lcd偏置电阻在1k-5k之间,调整VL的电压。背光电源A-K也要连接对正反方向。
显示后效果如下,
因为背光调整原因,显示还有些问题,继续调整。