1、引脚:

    引脚 符号 说明
    1 VSS 接地
    2 VDD 5V正极
    3 V0 对比度调整端,接正电源时对比度最弱,接地电源时对比度最高
    4 RS 寄存器选择,高电平时选择数据寄存器、低电平时选择指令寄存器
    5 RW 读写信号线,高电平时进行读操作,低电平时进行写操作
    6 E 使能端,高电平读取信息,负跳变执行指令
    7~14 D0~D7 8位双向数据线
    15 A 背光电源正极
    16 K 背光电源负极

    注:

    1. V0接10kOhm电位器;
    2. 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() //自动滚屏

    1. #include <LiquidCrystal.h>
    2. #include<TimerOne.h>
    3. const int rs=13,en=12,d4=11,d5=8,d6=7,d7=4,button=3;
    4. int flag=0;
    5. int finaltime=0;
    6. int count=1;
    7. LiquidCrystal LCD(rs, en, d4, d5, d6, d7); //定义LCD对象
    8. void setup()
    9. {
    10. pinMode(button,INPUT_PULLUP);
    11. LCD.begin(16,2);
    12. LCD.clear();
    13. LCD.setCursor(0,0);
    14. LCD.print("Start!");
    15. delay(1000);
    16. Timer1.initialize(100000);
    17. Timer1.attachInterrupt(Isr1);
    18. attachInterrupt(0,Isr2,FALLING);
    19. flag=0;
    20. count=1;
    21. }
    22. void loop()
    23. {
    24. if(flag==1)
    25. {
    26. LCD.clear();
    27. LCD.setCursor(0,0);
    28. LCD.print(finaltime);
    29. delay(1000);
    30. }
    31. }
    32. void Isr1()
    33. {
    34. LCD.clear();
    35. LCD.setCursor(0,0);
    36. LCD.print(count);
    37. count++;
    38. }
    39. void Isr2()
    40. {
    41. Timer1.detachInterrupt();
    42. flag=1;
    43. finaltime=count;
    44. }
    1. #include <LiquidCrystal.h>
    2. const int rs = 13, en = 12, d4 = 11, d5 = 8, d6 = 7,d7 = 4;
    3. LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
    4. void setup() {
    5. //设置LCD要显示的列数、行数,即2行16列
    6. lcd.begin(16, 2);
    7. //输出Hello World
    8. lcd.print("Timer!");
    9. }
    10. void loop() {
    11. //设置光标定位到第0列,第1行(从0开始)
    12. lcd.setCursor(0, 1);
    13. //打印从重置后的秒数
    14. lcd.print( millis() / 1000);
    15. }