arduino due lcd 8602液晶显示程序

本文介绍了一位新手玩家通过Arduino控制1602液晶显示器的过程,包括初始化代码、显示文本等基本操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近开始玩Arduino了,tlx210@163.com块drduino due,感觉还不错,第一个程序,1602液晶显示程序


nt 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);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值