电子发烧友App

硬声App

0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示
电子发烧友网>电子资料下载>单片机>arduino1602显示屏例程

arduino1602显示屏例程

2018-01-09 | rar | 23KB | 次下载 | 1积分

资料介绍

初学者可以参考的1602显示屏程序:

  1602LCD主要技术参数

  显示容量为16×2个字符;

  芯片工作电压为4.5~5.5V;

  工作电流为2.0mA(5.0V);

  模块最佳工作电压为5.0V;

  字符尺寸为2.95×4.35(W×H)mm。

  arduino1602显示屏例程

代码如下

  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);

  }

  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);

  }

下载该资料的人也在下载 下载该资料的人还在阅读
更多 >

评论

查看更多

下载排行

本周

  1. 1TC358743XBG评估板参考手册
  2. 1.36 MB  |  330次下载  |  免费
  3. 2开关电源基础知识
  4. 5.73 MB  |  6次下载  |  免费
  5. 3100W短波放大电路图
  6. 0.05 MB  |  4次下载  |  3 积分
  7. 4嵌入式linux-聊天程序设计
  8. 0.60 MB  |  3次下载  |  免费
  9. 5基于FPGA的光纤通信系统的设计与实现
  10. 0.61 MB  |  2次下载  |  免费
  11. 651单片机窗帘控制器仿真程序
  12. 1.93 MB  |  2次下载  |  免费
  13. 751单片机大棚环境控制器仿真程序
  14. 1.10 MB  |  2次下载  |  免费
  15. 8基于51单片机的RGB调色灯程序仿真
  16. 0.86 MB  |  2次下载  |  免费

本月

  1. 1OrCAD10.5下载OrCAD10.5中文版软件
  2. 0.00 MB  |  234315次下载  |  免费
  3. 2555集成电路应用800例(新编版)
  4. 0.00 MB  |  33564次下载  |  免费
  5. 3接口电路图大全
  6. 未知  |  30323次下载  |  免费
  7. 4开关电源设计实例指南
  8. 未知  |  21549次下载  |  免费
  9. 5电气工程师手册免费下载(新编第二版pdf电子书)
  10. 0.00 MB  |  15349次下载  |  免费
  11. 6数字电路基础pdf(下载)
  12. 未知  |  13750次下载  |  免费
  13. 7电子制作实例集锦 下载
  14. 未知  |  8113次下载  |  免费
  15. 8《LED驱动电路设计》 温德尔著
  16. 0.00 MB  |  6653次下载  |  免费

总榜

  1. 1matlab软件下载入口
  2. 未知  |  935054次下载  |  免费
  3. 2protel99se软件下载(可英文版转中文版)
  4. 78.1 MB  |  537796次下载  |  免费
  5. 3MATLAB 7.1 下载 (含软件介绍)
  6. 未知  |  420026次下载  |  免费
  7. 4OrCAD10.5下载OrCAD10.5中文版软件
  8. 0.00 MB  |  234315次下载  |  免费
  9. 5Altium DXP2002下载入口
  10. 未知  |  233046次下载  |  免费
  11. 6电路仿真软件multisim 10.0免费下载
  12. 340992  |  191185次下载  |  免费
  13. 7十天学会AVR单片机与C语言视频教程 下载
  14. 158M  |  183279次下载  |  免费
  15. 8proe5.0野火版下载(中文版免费下载)
  16. 未知  |  138040次下载  |  免费