|
液晶显示屏(LCD)通常用于在计算器、微波炉以及其他类似的电子设备中显示数据。您可以很容易地将液晶显示屏(LCD)与Arduino开发板连接,来提供一个用户界面。
在本篇文章中,我将主要介绍如何在Arduino开发板上使用LCD1602。本实验中使用的LCD1602液晶显示屏总共有16个引脚。如下表所示,其中有八个引脚是数据线(引脚7-14),两个引脚用于电源和接地(引脚1和16),三个引脚用于控制LCD的操作(引脚4-6),一个引脚用于调整LCD屏幕亮度(引脚3)。其余两个引脚(15和16)为背光供电。LCD引脚的详细信息如下: 引脚编号 | 引脚说明 | 1 | GND | 2 | + 5V | 3 | 电位器(用于亮度控制) | 4 | 寄存器选择(RS) | 5 | 读/写(RW) | 6 | 使能(EN) | 7 | DB0 | 8 | DB1 | 9 | DB2 | 10 | DB3 | 11 | DB4 | 12 | DB5 | 13 | DB6 | 14 | DB7 | 15 | 4.2-5V | 16 | GND |
实验1
在这个实验中,我们将16x2 LCD与Arduino Mega 2560连接,并在LCD上显示一些文本。
需要的硬件 ● LCD1602液晶显示屏 ● Arduino Mega2560开发板 ● 电位器 ● 连接导线
接线图 在该电路中,LCD引脚根据下表连接到Arduino开发板。将电位器的外侧两个端子连接到5V和地,将中间端子连接到LCD的引脚3。旋转电位器可控制LCD背光的亮度。 LCD背光引脚连接到5V和地,如下图所示:
DB4 -----> PIN4
DB5 -----> PIN5 DB6 -----> PIN6 DB7 -----> PIN7 RS -----> PIN8 EN -----> PIN9
代码 - #include "LiquidCrystal.h"
- // initialize the library by providing the nuber of pins to it
- LiquidCrystal lcd(8,9,4,5,6,7);
- void setup() {
- lcd.begin(16,2);
- // set cursor position to start of first line on the LCD
- lcd.setCursor(0,0);
- //text to print
- lcd.print(" 16x2 LCD");
- // set cusor position to start of next line
- lcd.setCursor(0,1);
- lcd.print(" DISPLAY");
- }
- void loop()
- {
- }
复制代码
实验2 在这个实验中,我们将在Arduino中显示计数器的值。 它将计算秒数,最大值为100。 需要的硬件 该实验所需的硬件与实验#1相同。 接线图 该实验的电路与实验#1相同。
代码
- #include "LiquidCrystal.h"
- // initialize the library by providing the nuber of pins to it
- LiquidCrystal lcd(8,9,4,5,6,7);
- void setup() {
- lcd.begin(16,2);
- // set cursor position to start of first line on the LCD
- lcd.setCursor(0,0);
- //text to print
- lcd.print(" COUNTER");
- delay(100);
- int a=0;
- lcd.setCursor(0,1);
- lcd.print(" ");
- lcd.print(a);
- while(a<=100)
- {
- a=a+1;
- delay(1000);
- lcd.setCursor(0,1);
- lcd.print(" ");
- lcd.print(a);
- }
- }
- void loop()
- {
- lcd.clear();
- }
复制代码 |