arduino lcd 连接方案、代码实现

arduino lcd1602连接方案、代码实现及技术说明

本文分为三部分

  • 连接方案
  • 代码实现
    - 技术说明

1.连接方案
材料:

  • arduino uno *1
  • lcd1602 *1
  • 电位器 *1
  • 面包板 *1

引脚说明:在这里插入图片描述

  • VL为液晶显示器对比度调整端,接正电源时对比度最弱,接地时对比度最高,对比度过高时会产生“鬼影”现象,使用时可以通过一个10kQ的电位器调整其对比度。
  • 引脚15:背光源正极。
  • 引脚16:背光源负极。

接线示意图:

符号 说明
VSS 接gnd
VDD 接5V
VO 接电位器滑片端
RS 接pin12
RW 接gnd
E 接pin11
D0~D7 D4-7分别接5~2
A 接3.3V
K 接gnd

在这里插入图片描述
连接完成后可以打开IDEliquidcrystal示例验证

代码实现
加载库:
arduino IDE >项目>加载库>管理库>搜索安装
在这里插入图片描述
查看函数:
library
arduino官网处在这里插入图片描述
hello world示例:

/*
  LiquidCrystal Library - Hello World

 Demonstrates the use a 16x2 LCD display.  The LiquidCrystal
 library works with all LCD displays that are compatible with the
 Hitachi HD44780 driver. There are many of them out there, and you
 can usually tell them by the 16-pin interface.

 This sketch prints "Hello World!" to the LCD
 and shows the time.

  The circuit:
 * LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * LCD R/W pin to ground
 * LCD VSS pin to ground
 * LCD VCC pin to 5V
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)

 Library originally added 18 Apr 2008
 by David A. Mellis
 library modified 5 Jul 2009
 by Limor Fried (http://www.ladyada.net)
 example added 9 Jul 2009
 by Tom Igoe
 modified 22 Nov 2010
 by Tom Igoe
 modified 7 Nov 2016
 by Arturo Guadalupi

 This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/LiquidCrystalHelloWorld

*/

// include the library code:
#include <LiquidCrystal.h>

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
    
    
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop() {
    
    
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis() / 1000);
}

技术说明(水平限制)

lcd1602的接线方法在此时的学习环境中算是复杂的了,所以搞明白它的接线问题意义不小。

百度上写lcd1602怎样接线有很多,但是不知道为什么我还是用了2天的时间才搞明白,后来想来其实问题无非是出在帖子太多太乱太杂,各路大神的接线和代码也不尽相同,这对于想入门的我来说简直是一团乱麻,毫无头绪。

所以为了下一位同学不至于和我一样,我决定写下一套完整的lcd1602相关博客,并以此致敬无数不知姓名而为我引路的前人。

猜你喜欢

转载自blog.csdn.net/weixin_43322322/article/details/107891170
LCD
今日推荐