arduino连接lcd1602使用方法软件_arduino 6色液晶

arduino连接lcd1602使用方法软件_arduino 6色液晶接线图[captionid=”attachment_1183″align=”alignnone”width=”1108″]LCD1602A接线图(4位)[/caption]4位接线法[codesyntaxlang=”cpp”]/***VSS…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

  • 接线图

LCD1602A接线图(4位)
LCD1602A接线图(4位)

132950fbbbolz4q0qs1bbo

  • 4位接线法

[codesyntax lang=”cpp”]

/**
* VSS GND
* VDD 5V
* V0  GND
* RS  12
* RW  11
* E   10
* D4  9
* D5  8
* D6  7
* D7  6
* A  V5
* K  GND
* from http://surenpi.com
* created 2015/3/23
*/
int LCD1602_RS=12;
int LCD1602_RW=11;
int LCD1602_EN=10;
int DB[] = { 6, 7, 8, 9};

char str1[]="Welcome to";
char str2[]="surenpi";
char str3[]="find me";
char str4[]="surenpi.com";
 
void LCD_Command_Write(int command)
{
  int i,temp;
  digitalWrite( LCD1602_RS,LOW);
  digitalWrite( LCD1602_RW,LOW);
  digitalWrite( LCD1602_EN,LOW);
 
  temp=command & 0xf0;
  for (i=DB[0]; i <= 9; i++)
  {
     digitalWrite(i,temp & 0x80);
     temp <<= 1;
  }
   
  digitalWrite( LCD1602_EN,HIGH);
  delayMicroseconds(1);
  digitalWrite( LCD1602_EN,LOW);
   
  temp=(command & 0x0f)<<4;
  for (i=DB[0]; i <= 9; i++)
  {
     digitalWrite(i,temp & 0x80);
     temp <<= 1;
  }
   
  digitalWrite( LCD1602_EN,HIGH);
  delayMicroseconds(1);
  digitalWrite( LCD1602_EN,LOW);
}

void cleanScreen(int delayTime = 50)
{
   LCD_Command_Write(0x01);
      
   delay(delayTime);
}
 
void LCD_Data_Write(int dat)
{
  int i=0,temp;
  digitalWrite( LCD1602_RS,HIGH);
  digitalWrite( LCD1602_RW,LOW);
  digitalWrite( LCD1602_EN,LOW);
   
  temp=dat & 0xf0;
  for (i=DB[0]; i <= 9; i++)
  {
     digitalWrite(i,temp & 0x80);
     temp <<= 1;
  }
   
  digitalWrite( LCD1602_EN,HIGH);
  delayMicroseconds(1);
  digitalWrite( LCD1602_EN,LOW);
   
  temp=(dat & 0x0f)<<4;
  for (i=DB[0]; i <= 9; i++)
  {
     digitalWrite(i,temp & 0x80);
     temp <<= 1;
  }
   
  digitalWrite( LCD1602_EN,HIGH);
  delayMicroseconds(1);
  digitalWrite( LCD1602_EN,LOW);
}
 
void LCD_SET_XY( int x, int y )
{
  int address;
  if (y ==0)    address = 0x80 + x;
  else          address = 0xC0 + x;
  LCD_Command_Write(address);
}
 
void LCD_Write_Char( int x,int y,int dat)
{
  LCD_SET_XY( x, y );
  LCD_Data_Write(dat);
}
 
void LCD_Write_String(int x,int y,char *s, int delayTime = 50)
{
  LCD_SET_XY(x, y);    //设置地址
  
  int i = 0;
  while(*s && ++i <= 16)             //写字符串
  {
    LCD_Data_Write(*s);   
    s++;
  }
  
  delay(delayTime);
  
  if(*s)
  {
    cleanScreen();
    LCD_Write_String(x, y, s, delayTime);
  }
}
 
void setup (void)
{
  int i = 0;
  for(i = 6; i <= 12; i++)
  {
    pinMode(i,OUTPUT);
  }
  
  delay(100);
  LCD_Command_Write(0x28);//4线 2行 5x7
  delay(50);
  LCD_Command_Write(0x06);
  delay(50);
  LCD_Command_Write(0x0c);
  delay(50);
  LCD_Command_Write(0x80);
  delay(50);
  LCD_Command_Write(0x01);
  delay(50);
}
 
void loop (void)
{
  cleanScreen();
  LCD_Write_String(3,0,str1);//第1行,第4个地址起
  LCD_Write_String(0,1,str2, 3000);//第2行,第2个地址起
  
  cleanScreen();
  LCD_Write_String(0,0,str3);
  LCD_Write_String(0,1,str4, 3000);
}

[/codesyntax]

  •  8位接线法

[codesyntax lang=”cpp”]

/**
* 8 bit
* from http://surenpi.com
*/
int DI = 12;
int RW = 11;
int DB[] = {3, 4, 5, 6, 7, 8, 9, 10};//使用数组来定义总线需要的管脚
int Enable = 2;
 
void LcdCommandWrite(int value)
{
  // 定义所有引脚
  int i = 0;
  for (i=DB[0]; i <= DI; i++) //总线赋值
  {
     digitalWrite(i,value & 01);//因为1602液晶信号识别是D7-D0(不是D0-D7),这里是用来反转信号。
     value >>= 1;
  }
  digitalWrite(Enable,LOW);
  delayMicroseconds(1);
  digitalWrite(Enable,HIGH);
  delayMicroseconds(1);  // 延时1ms
  digitalWrite(Enable,LOW);
  delayMicroseconds(1);  // 延时1ms
}
 
void LcdDataWrite(int value)
{
  // 定义所有引脚
  int i = 0;
  digitalWrite(DI, HIGH);
  digitalWrite(RW, LOW);
  
  for (i=DB[0]; i <= DB[7]; i++)
  {
     digitalWrite(i,value & 01);
     value >>= 1;
  }
  
  digitalWrite(Enable,LOW);
  delayMicroseconds(1);
  digitalWrite(Enable,HIGH);
  delayMicroseconds(1);
  digitalWrite(Enable,LOW);
  delayMicroseconds(1);  // 延时1ms
}
 
void setup (void)
{
  int i = 0;
  for(i=Enable; i <= DI; i++)
  {
     pinMode(i,OUTPUT);
  }
  
  delay(100);
  // 短暂的停顿后初始化LCD
  // 用于LCD控制需要
  LcdCommandWrite(0x38);  // 设置为8-bit接口,2行显示,5x7文字大小                     
  delay(64);                     
  LcdCommandWrite(0x38);  // 设置为8-bit接口,2行显示,5x7文字大小                        
  delay(50);                     
  LcdCommandWrite(0x38);  // 设置为8-bit接口,2行显示,5x7文字大小                        
  delay(20);                     
  LcdCommandWrite(0x06);  // 输入方式设定
                           // 自动增量,没有显示移位
  delay(20);                     
  LcdCommandWrite(0x0E);  // 显示设置
                           // 开启显示屏,光标显示,无闪烁
  delay(20);                     
  LcdCommandWrite(0x01);  // 屏幕清空,光标位置归零  
  delay(100);                     
  LcdCommandWrite(0x80);  // 显示设置
                           // 开启显示屏,光标显示,无闪烁
  delay(20);                     
}
 
void loop (void)
{
  LcdCommandWrite(0x01);  // 屏幕清空,光标位置归零  
  delay(10);
  LcdCommandWrite(0x80+3);
  delay(10);                     
  // 写入欢迎信息
  LcdDataWrite('W');
  LcdDataWrite('e');
  LcdDataWrite('l');
  LcdDataWrite('c');
  LcdDataWrite('o');
  LcdDataWrite('m');
  LcdDataWrite('e');
  LcdDataWrite(' ');
  LcdDataWrite('t');
  LcdDataWrite('o');
  delay(10);
  LcdCommandWrite(0xc0+1);  // 定义光标位置为第二行第二个位置  
  delay(10);
  LcdDataWrite('g');
  LcdDataWrite('e');
  LcdDataWrite('e');
  LcdDataWrite('k');
  LcdDataWrite('-');
  LcdDataWrite('w');
  LcdDataWrite('o');
  LcdDataWrite('r');
  LcdDataWrite('k');
  LcdDataWrite('s');
  LcdDataWrite('h');
  LcdDataWrite('o');
  LcdDataWrite('p');
  delay(5000);
  LcdCommandWrite(0x01);  // 屏幕清空,光标位置归零  
  delay(10);
  LcdDataWrite('I');
  LcdDataWrite(' ');
  LcdDataWrite('a');
  LcdDataWrite('m');
  LcdDataWrite(' ');
  LcdDataWrite('h');
  LcdDataWrite('o');
  LcdDataWrite('n');
  LcdDataWrite('g');
  LcdDataWrite('y');
  LcdDataWrite('i');
  delay(3000);
  LcdCommandWrite(0x02); //设置模式为新文字替换老文字,无新文字的地方显示不变。
  delay(10);
  LcdCommandWrite(0x80+5); //定义光标位置为第一行第六个位置
  delay(10);  
  LcdDataWrite('t');
  LcdDataWrite('h');
  LcdDataWrite('e');
  LcdDataWrite(' ');
  LcdDataWrite('a');
  LcdDataWrite('d');
  LcdDataWrite('m');
  LcdDataWrite('i');
  LcdDataWrite('n');
  delay(5000);
}

[/codesyntax]

  • 使用LiquidCrystal库来连接

使用LiquidCrystal这个库的话,代码会简洁很多,而且还封装还一些常用函数。 [codesyntax lang=”cpp”]

/**
7 gpios demo

The circuit:
VSS GND
VDD 5V
V0 10K resistor or GND
RS 12
RW 11
EN 10
D4 9
D3 8
D2 7
D1 6

from www.surenpi.com
created 2015/3/25
*/
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 10, 9, 8, 7, 6);

void setup() {
  lcd.begin(16, 2);
  lcd.print("www.surenpi.com");
}

void loop() {  
  lcd.setCursor(0, 1);
  lcd.print(millis()/1000);
}

[/codesyntax] 注意:上面的代码中使用了7个GPIO接口,其实把RW接到GND上也行,这样的就可以节省一个GPIO。如果要把RW接GND话,就要使用另外一个构造函数:LiquidCrystal lcd(12, 10, 9, 8, 7, 6)

  • 参考

 树莓派上怎么连接LCD1602呢,请看这里。

转载于:https://my.oschina.net/surenpi/blog/604780

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/190509.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • python获取文件名后缀名_python获取文件名不含后缀名

    python获取文件名后缀名_python获取文件名不含后缀名importosfile_path=”/home/admin/Desktop/test.py”filepath,tempfilename=os.path.split(file_path)filename,extension=os.path.splitext(tempfilename)filepath文件目录filename文件名extension文件扩展名…

    2022年9月2日
    2
  • rsync远程同步文件_ssh远程登录

    rsync远程同步文件_ssh远程登录一、简介二、配置项三、远程同步测试免交互配置:四、实时同步1、在客户机上安装notify2、编写监控脚本五、rsync批量快速删除大量文件一、简介一款快速增量备份工具RemoteSync,远程同步支持本地复制,或者与其他SSH、rsync主机同步它名称里面的r指的是remote,rsync其实就是”远程同步”(remotesync)的意思。与其他文件传输工具(如FTP或scp)不同,rsync的最大特点是会检查发送方和接收方已有的文件,仅传输有变动的部分(默认规则是文件大小或修改.

    2022年10月13日
    0
  • Java基础之增强型for循环

    Java基础之增强型for循环目录增强型for循环语法:for(ElementTypeelement:arrayName){};增强for循环的原理增强型for循环注意事项增强型for循环语法:for(ElementTypeelement:arrayName){};举个例子:(1)int[]numArray={1,2,3,4,5,6};for(inti:numArray…

    2022年6月17日
    41
  • networkmanager配置文件在哪_需要运行networkmanager

    networkmanager配置文件在哪_需要运行networkmanager原文链接http://live.gnome.org/action/login/NetworkManagerConfiguration 本文对了解NetworkManager的使用和开发有很大帮助,澄清了一些NetworkManager中使用的概念,对阅读源代码和修改Bug有很大的帮助。 设置服务(SettingsServices)通过D-Bus服务提供配置给N

    2022年10月4日
    0
  • Android移动开发-Android数据加密与解密的实现「建议收藏」

    Android移动开发-Android数据加密与解密的实现「建议收藏」数据的安全是非常重要的,现在无论干什么都要账号和密码,一旦账号与密码泄露出去必将造成财产的损失,所以做好数据保密是非常重要的。Android加密算法有多种多样,常见的有MD5、RSA、AES、3DES四种。

    2022年5月16日
    48
  • Union和Union All的差别

    Union和Union All的差别

    2021年12月10日
    72

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号