仿真软件proteus构建LCD1602显示字符串实验

    LCD1602模块的显示需要注意几点:

    1、显示两行,第一行的起始地址是0x80,第二行的地址是0x80+0x40 = 0xC0。

    2、RS,RW,EN接线没有说一定要接到P1,P2,P3上,只要给对应的管脚高低电平即可,但是必须要接线。

     3、LCD1602 VSS VEE管脚要连在一起并接地,在实际电路板上,这个地方也是需要注意的。

    这里使用仿真软件Proteus同样的,只需要在Proteus工具中设计电路图,编写原代码,编译,仿真即可,无需Keil工具,但是系统需要安装Keil工具,因为编写代码需要用到Keil for 8051编译器。

    proteus构建硬件工程,选择8051单片机类型,编译器选择Keil for 8051。这样,工程中会显示电路设计图视图,pcb设计图视图,源代码视图。

    源代码中main.c代码:

/* Main.c file generated by New Project wizard
 *
 * Created:   周一 12月 13 2021
 * Processor: 80C52
 * Compiler:  Keil for 8051
 */

#include <reg52.h>
#include <intrins.h>
#include <stdio.h>
#include <string.h>

#define uchar unsigned char 
#define uint unsigned int 

sbit RS = P3^5;
sbit EN = P3^4;
sbit RW = P3^6;

uchar code table1[] = {"hello,world!"};
uchar code table2[] = {"0123456789"};

void delay(uint time);
void init_1602(void);
void writecmd(uint cmd);
void writedata(uchar dat);
void display(uchar len,uchar* table);

void main(void)
 { 
   // Write your code here
  delay(10);
  init_1602();
  delay(5);	 
  writecmd(0x80);
  //delay(5);
  display(strlen(table1),table1);
  writecmd(0x80+0x40);
  display(strlen(table2),table2);
  while (1)
     ;
 }
 
 void delay(uint time)
 {
  unsigned char a,b,i;
  for(i=time;i!=0;i--)
  {
	for(b=199;b>0;b--)
	{
	  for(a=1;a>0;a--);	
	}		
  }  
}

void init_1602(void){
  delay(15);
  writecmd(0x38); //mode set
  writecmd(0x0c); //display set
  writecmd(0x06);  //display mode
  writecmd(0x01); //clear display
}

void writecmd(uint cmd){
	RS = 0;
	RW = 0;
	P1 = cmd;
	EN = 1;
	delay(1);
	EN = 0;
}

void writedata(uchar dat)
{
  RS = 1;
  RW = 0;
  P1 = dat;
  EN = 1;
  delay(1);
  EN = 0;	
}

void display(uchar len,uchar* table){
	uchar i;
	for(i=0;i<len;i++)
	{
	  writedata(table[i]);	
	}
	delay(5);
}

仿真电路图:

运行效果:

LCD1602显示实验,在实际开发中,为了保护LCD1602器件,可能会接上一个排阻,然后与单片机相连。在仿真实验中,为了提高效率,快速看到实验效果,这一步省掉了。

  • 8
    点赞
  • 68
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

luffy5459

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值