700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 仿真软件proteus构建LCD1602显示字符串实验

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

时间:2022-01-07 03:56:21

相关推荐

仿真软件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 * 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 heredelay(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 setwritecmd(0x0c); //display setwritecmd(0x06); //display modewritecmd(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器件,可能会接上一个排阻,然后与单片机相连。在仿真实验中,为了提高效率,快速看到实验效果,这一步省掉了。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。