1、引脚:
引脚 | 符号 | 说明 |
---|---|---|
1 | VSS | 接地 |
2 | VDD | 5V正极 |
3 | V0 | 对比度调整端,接正电源时对比度最弱,接地电源时对比度最高 |
4 | RS | 寄存器选择,高电平时选择数据寄存器、低电平时选择指令寄存器 |
5 | RW | 读写信号线,高电平时进行读操作,低电平时进行写操作 |
6 | E | 使能端,高电平读取信息,负跳变执行指令 |
7~14 | D0~D7 | 8位双向数据线 |
15 | A | 背光电源正极 |
16 | K | 背光电源负极 |
注:
- V0接10kOhm电位器;
- RS低RW低:写入指令/显示地址;RS低RW高:读busy信号;RS高RW低:写入数据。
2、LiquidCrystal库
使用:
#include
const int rs=13,en=12,d4=11,d5=9,d6=7,d7=4;
LiquidCrystal LCD(rs, en, d4, d5, d6, d7);
LCD.begin(16,2);
LCD.setCursor(0,0);
LCD.print(“…”);
其他函数:
.clear() //清屏
.autoscroll() //自动滚屏
#include <LiquidCrystal.h>
#include<TimerOne.h>
const int rs=13,en=12,d4=11,d5=8,d6=7,d7=4,button=3;
int flag=0;
int finaltime=0;
int count=1;
LiquidCrystal LCD(rs, en, d4, d5, d6, d7); //定义LCD对象
void setup()
{
pinMode(button,INPUT_PULLUP);
LCD.begin(16,2);
LCD.clear();
LCD.setCursor(0,0);
LCD.print("Start!");
delay(1000);
Timer1.initialize(100000);
Timer1.attachInterrupt(Isr1);
attachInterrupt(0,Isr2,FALLING);
flag=0;
count=1;
}
void loop()
{
if(flag==1)
{
LCD.clear();
LCD.setCursor(0,0);
LCD.print(finaltime);
delay(1000);
}
}
void Isr1()
{
LCD.clear();
LCD.setCursor(0,0);
LCD.print(count);
count++;
}
void Isr2()
{
Timer1.detachInterrupt();
flag=1;
finaltime=count;
}
#include <LiquidCrystal.h>
const int rs = 13, en = 12, d4 = 11, d5 = 8, d6 = 7,d7 = 4;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
//设置LCD要显示的列数、行数,即2行16列
lcd.begin(16, 2);
//输出Hello World
lcd.print("Timer!");
}
void loop() {
//设置光标定位到第0列,第1行(从0开始)
lcd.setCursor(0, 1);
//打印从重置后的秒数
lcd.print( millis() / 1000);
}