51单片机1602液晶显示代码在keil中没有错误,但在proteus中运行无结果?
#include<reg52.h>#defineucharunsignedchar#defineuintunsignedintsbitrs=P0^5;sbitrw=P0^...
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit rs=P0^5;
sbit rw=P0^6;
sbit e=P0^7;
uchar table1[]="qqqqqqqqq";
uchar table2[]="qqqqqqqqq";
void delay_50us(uint t)//延迟函数;
{
uchar j;
for(;t>0;t--)
for(j=6245;j>0;j--);
}
void write_com(uchar com)
{
e=0;
rs=0;
rw=0;
P2=com;
delay_50us(10);
e=1;
delay_50us(20);
e=0;
}
void write_data(uchar dat)
{
e=0;
rs=1;
rw=0;
P2=dat;
delay_50us(10);
e=1;
delay_50us(20);
e=0;
}
void init(void)
{
delay_50us(300);
write_com(0x38);
delay_50us(100);
write_com(0x38);
delay_50us(100);
write_com(0x38);
write_com(0x38);
write_com(0x08);
write_com(0x01);
write_com(0x06);
write_com(0x0c);
}
void main()
{
uchar j;
init();
write_com(0x80);
for(j=0;j<16;j++)
{
write_data(table1[j]);
delay_50us(10);
}
write_com(0x80+0x40);
for(j=0;j<16;j++)
{
write_data(table2[j]);
delay_50us(10);
}
} 展开
#define uchar unsigned char
#define uint unsigned int
sbit rs=P0^5;
sbit rw=P0^6;
sbit e=P0^7;
uchar table1[]="qqqqqqqqq";
uchar table2[]="qqqqqqqqq";
void delay_50us(uint t)//延迟函数;
{
uchar j;
for(;t>0;t--)
for(j=6245;j>0;j--);
}
void write_com(uchar com)
{
e=0;
rs=0;
rw=0;
P2=com;
delay_50us(10);
e=1;
delay_50us(20);
e=0;
}
void write_data(uchar dat)
{
e=0;
rs=1;
rw=0;
P2=dat;
delay_50us(10);
e=1;
delay_50us(20);
e=0;
}
void init(void)
{
delay_50us(300);
write_com(0x38);
delay_50us(100);
write_com(0x38);
delay_50us(100);
write_com(0x38);
write_com(0x38);
write_com(0x08);
write_com(0x01);
write_com(0x06);
write_com(0x0c);
}
void main()
{
uchar j;
init();
write_com(0x80);
for(j=0;j<16;j++)
{
write_data(table1[j]);
delay_50us(10);
}
write_com(0x80+0x40);
for(j=0;j<16;j++)
{
write_data(table2[j]);
delay_50us(10);
}
} 展开
3个回答
展开全部
这是你要的效果吧,程序帮你修改了,你对比看一下,满意请采纳
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit rs=P2^0; //根据你实际修改
sbit rw=P2^1; //根据你实际修改
sbit e=P2^2; //根据你实际修改
uchar table1[]="qqqqqqqqq";
uchar table2[]="qqqqqqqqq";
void delay_50us(uint t)//延迟函数;
{
uchar j;
for(;t>0;t--)
for(j=6245;j>0;j--);
}
void write_com(uchar com)
{
e=0;
rs=0;
rw=0;
P0=com; //根据你实际修改
delay_50us(10);
e=1;
delay_50us(20);
e=0;
}
void write_data(uchar dat)
{
e=0;
rs=1;
rw=0; //根据你实际修改
P0=dat;
delay_50us(10);
e=1;
delay_50us(20);
e=0;
}
void init(void)
{
delay_50us(300);
write_com(0x38);
delay_50us(100);
write_com(0x38);
delay_50us(100);
write_com(0x38);
write_com(0x38);
write_com(0x08);
write_com(0x01);
write_com(0x06);
write_com(0x0c);
}
void main()
{
uchar j;
init();
write_com(0x80);
for(j=0;j<9;j++)
{
write_data(table1[j]);
delay_50us(10);
}
write_com(0x80+0x40); //根据你实际字符写屏
for(j=0;j<9;j++)
{
write_data(table2[j]); //根据你实际字符写屏
delay_50us(10);
}
while(1) //你原来没有的
{
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询