Arduino LCD 液晶顯示器教程
什么是LCD1602液晶顯示器??
LCD的全稱是Liquid Crystal Display,液晶顯示器。它的特點(diǎn)是利用點(diǎn)陣來(lái)顯示字符, 比如英文字母、阿拉伯?dāng)?shù)字、簡(jiǎn)單的漢字和一般性符號(hào)。因?yàn)槊總€(gè)字節(jié)的點(diǎn)陣數(shù)太少, 所以復(fù)雜的漢字很難顯示清晰。
LCD1602每行有16個(gè)字格,共有2行。每個(gè)字格有40個(gè)像素, 可組成5列*8行的LCD矩陣。每個(gè)像素可用二進(jìn)制表示, 1為亮燈, 0為滅燈。詳情見(jiàn)圖一。

LCD1602總共有16個(gè)引腳。每個(gè)引腳的作用如下。

如何連接電路
材料清單:
Arduino Uno 開(kāi)發(fā)板 x1
USB接線 x1
面包板 x1
LCD液晶顯示器1602 x1
電位器 x1 (可用電阻器替代)
雙公頭面包線若干(長(zhǎng)黃線x4, 長(zhǎng)橘線x1, 長(zhǎng)藍(lán)線x1, 短綠線x1, 短黑線x5, 短紅線x4)
裝有Arduino IDE程序的電腦 x1
面包線的顏色僅供參考,方便于理解下面的教程。黑線一般作為接地線,紅線作為電源線。
電路圖:?



接線步驟:


步驟三: 把面包板上所有的紅線接正極/電源(面包板第二行),黑線接負(fù)極/地(面包板第一行)。

步驟五:把面包板上的黃線從D4接到引腳4, D5到5, D6到6, D7到7。把橘線從RS接到引腳1, 藍(lán)線從E到引腳2。
步驟六:把開(kāi)發(fā)板用usb連接到電腦。
步驟七: 根據(jù)視頻內(nèi)容上傳代碼。【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
? 自創(chuàng)字符
*/
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
? 初始設(shè)置
*/
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
? 循環(huán)
*/
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);
}