关于LCD屏
LCD屏一共有16个引脚(含背光)或14个引脚(不含背光)
一般来说最后两个A K则表示背光的阳极和阴极
对于LCD屏幕从D0-D7的八个引脚如果全部使用可以提高性能,但并不明显,所以使用其中4个也可以正常控制,还可以节约Arduino上的引脚来控制其他硬件。
LCD屏连接
LCD引脚序号 | 功能 | Arduino引脚 |
1 | Gnd 0V Vss | Gnd |
2 | +5V Vdd | 5V |
3 | Vo 对比度 | |
4 | RS | 12 |
5 | RW | Gnd |
6 | E | 11 |
7 | D0 | |
8 | D1 | |
9 | D2 | |
10 | D3 | |
11 | D4 | 5 |
12 | D5 | 4 |
13 | D6 | 3 |
14 | D7 | 2 |
15 | A | 可选 如果需要则连接5V |
16 | K | 可选 如果需要则连接Gnd |
接线图
Code 基础使用
需要加载 LiquidCrystal 库
/*
LiquidCrystal Library - Hello World
Demonstrates the use a 16x2 LCD display. The LiquidCrystal
library works with all LCD displays that are compatible with the
Hitachi HD44780 driver. There are many of them out there, and you
can usually tell them by the 16-pin interface.
This sketch prints "Hello World!" to the LCD
and shows the time.
The circuit:
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* LCD VSS pin to ground
* LCD VCC pin to 5V
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
Library originally added 18 Apr 2008
by David A. Mellis
library modified 5 Jul 2009
by Limor Fried (http://www.ladyada.net)
example added 9 Jul 2009
by Tom Igoe
modified 22 Nov 2010
by Tom Igoe
modified 7 Nov 2016
by Arturo Guadalupi
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/LiquidCrystalHelloWorld
*/
// include the library code:
#include 《LiquidCrystal.h》
// LCD的行数和列数
const int numR = 2;
const int numC = 16;
// 使用界面引脚的编号初始化库
LiquidCrystal lcd(12,11,5,4,3,2);
void setup() {
// 设置LCD的列数和行数
lcd.begin(numR, numC);
// 将文字打印到屏幕
lcd.print("hello, world!");
}
void loop() {
// 光标移动到0列 1行 (1行实际是第二行。0表示第一行)
lcd.setCursor(0, 1);
// 打印开始一开的秒数
lcd.print(millis() / 1000);
}
Code 特定位置显示文本
setCursor(列,行)
/*
这段代码会倒计时到0,然后清楚屏幕内容
*/
// include the library code:
#include 《LiquidCrystal.h》
// LCD的行数和列数
const int numR = 2;
const int numC = 16;
// 使用界面引脚的编号初始化库
LiquidCrystal lcd(12,11,5,4,3,2);
void setup() {
// 设置LCD的列数和行数
lcd.begin(numR, numC);
// 将文字打印到屏幕
lcd.print("Starting in");
for(int i=9;i>0;i--){
lcd.setCursor(12,0); //光标移动到末尾
lcd.print(i); //从9倒数
delay(1000);
}
lcd.setCursor(12,0);
lcd.print(0);
delay(1000);
}
void loop() {
lcd.clear();
}
Code 光标和文字闪烁
// include the library code:
#include 《LiquidCrystal.h》
// LCD的行数和列数
const int numR = 2;
const int numC = 16;
int count;
// 使用界面引脚的编号初始化库
LiquidCrystal lcd(12,11,5,4,3,2);
void setup() {
// 设置LCD的列数和行数
lcd.begin(numR, numC);
// 将文字打印到屏幕
lcd.print("Hello World!");
}
void loop() {
lcd.setCursor(0,1);
lcd.print("Cursor blink");
lcd.blink();
delay(2500);
lcd.noBlink();
lcd.print("NoBlink");
delay(2500);
lcd.clear();
lcd.print("Display off ...");
delay(1000);
lcd.noDisplay();
delay(2000);
lcd.display(); //打开显示
lcd.setCursor(0,0);
lcd.print("display flash !");
displayBlink(2,250);//闪烁2次
displayBlink(2,500);//两倍时长闪烁两次
lcd.clear();
}
//整个闪烁使用displayBlink()函数,控制画面闪烁指定次数
//使用noDisplay() 与 lcd.display()来打开、关闭文本,而非清除
void displayBlink(int blinks, int duration){
while(blinks --){
lcd.noDisplay();
delay(duration);
lcd.display();
delay(duration);
}
}
正文完