Arduino LCD 液晶显示器教程
什么是LCD1602液晶显示器?
LCD的全称是Liquid Crystal Display,液晶显示器。它的特点是利用点阵来显示字符, 比如英文字母、阿拉伯数字、简单的汉字和一般性符号。因为每个字节的点阵数太少, 所以复杂的汉字很难显示清晰。
LCD1602每行有16个字格,共有2行。每个字格有40个像素, 可组成5列*8行的LCD矩阵。每个像素可用二进制表示, 1为亮灯, 0为灭灯。详情见图一。

LCD1602总共有16个引脚。每个引脚的作用如下。

如何连接电路
材料清单:
Arduino Uno 开发板 x1
USB接线 x1
面包板 x1
LCD液晶显示器1602 x1
电位器 x1 (可用电阻器替代)
双公头面包线若干(长黄线x4, 长橘线x1, 长蓝线x1, 短绿线x1, 短黑线x5, 短红线x4)
装有Arduino IDE程序的电脑 x1
面包线的颜色仅供参考,方便于理解下面的教程。黑线一般作为接地线,红线作为电源线。
电路图:



接线步骤:


步骤三: 把面包板上所有的红线接正极/电源(面包板第二行),黑线接负极/地(面包板第一行)。

步骤五:把面包板上的黄线从D4接到引脚4, D5到5, D6到6, D7到7。把橘线从RS接到引脚1, 蓝线从E到引脚2。
步骤六:把开发板用usb连接到电脑。
步骤七: 根据视频内容上传代码。【Arduino LCD 液晶显示器教程】
代码
#include <LiquidCrystal.h> // includes the LiquidCrystal Library
LiquidCrystal lcd(1, 2, 4, 5, 6, 7); // Creates an LCD object. Parameters: (rs, enable, d4, d5, d6, d7)
/**
Create customised characters / symbols
自创字符
*/
byte heart[8] = { // Each character comprises of 40 pixels (8 rows and 5 columns)
B00000, // B stands for binary formatter and the five numbers are the pixels
B01010, // Use 1 to light up the pixel, 0 does nothing
B11111,
B11111,
B01110,
B00100,
B00000,
B00000
};
byte smile[8] = {
B00000,
B00000,
B01010,
B00000,
B10001,
B01110,
B00000,
B00000
};
/**
Initial setup
初始设置
*/
void setup() {
lcd.begin(16,2); // Initialise the interface to the LCD screen, and specifies the dimensions (width and height) of the display
lcd.createChar(0, heart); // Create a custom character heart
lcd.createChar(1, smile); // Create a custom character smile
}
/**
Loop
循环
*/
void loop() {
lcd.setCursor(0,0); // Move cursor to 1st column, 1st row
lcd.print("Hello!"); // Print on the LCD
lcd.setCursor(7,0); // Move cursor to 8th column, 1st row
lcd.write(byte(0)); // Display custom character 0, the heart
lcd.setCursor(2,1); // Move cursor to 3rd column, 2nd row
lcd.print("LCD Tutorial"); // Print on the LCD
lcd.setCursor(15,1); // Move cursor to 16th column, 2nd row
lcd.write(byte(1)); // Display custom character 1, the smile
delay(5000); //Wait for 5 seconds
lcd.clear(); // Clear the display
lcd.setCursor(0,0); // Move cursor to 1st column, 1st row
lcd.blink(); //Display the blinking LCD cursor
delay(3000); //Display for 5 seconds
lcd.setCursor(0,0); // Move cursor to 1st column, 1st row
lcd.noBlink(); // Turn off the blinking LCD cursor
lcd.cursor(); // Display an underscore at on the specified cell (0,0)
delay(3000); // Wait for 5 seconds
lcd.noCursor(); // Hide the LCD cursor
delay(3000); // Wait for 5 seconds
lcd.clear(); // Clear the display
/** Scroll text to the left **/
for (int i = 16; i >= 1; i--) {
lcd.setCursor(i, 0);
lcd.print("LCD");
lcd.setCursor(i, 1);
lcd.print("Tutorial");
delay(1000);
lcd.clear();
}
delay(1000);
}