想用C控制LCD1602,但是它没反应,用的是普中科技的51单片机学习板,程序如下,求大神解围
#include<reg52.h>#defineucharunsignedcharucharcodetable0[]="01234567";ucharcodetable1...
#include<reg52.h>
#define uchar unsigned char
uchar code table0[]="01234567";
uchar code table1[]="abcdefg";
uchar xms,a,yi,er;
sbit E=P2^7;
sbit RS=P3^7;
sbit RW=P2^5;
void delay(xms) //延时
{
for(xms;xms>0;xms--)
{
for(a=110;a>0;a--);
}
}
void write_com(uchar com) //写命令
{
E=0;
RS=0;
RW=0;
P0=com;
delay(5);
E=1;
delay(5);
E=0;
}
void write_data(uchar date) //写数据
{
E=0;
RS=1;
RW=0;
P0=date;
delay(5);
E=1;
delay(5);
E=0;
}
void init() //初始化
{
E=0;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
}
void main()
{
init();
write_com(0x80);
for(yi=0;yi<9;yi++)
{
write_data(table0[yi]);
delay(5);
}
write_com(0x80+0x40);
for(er=0;er<8;er++)
{
write_data(table1[er]);
delay(5);
}
while(1);
}
要是能顺便拜个师就更好了 展开
#define uchar unsigned char
uchar code table0[]="01234567";
uchar code table1[]="abcdefg";
uchar xms,a,yi,er;
sbit E=P2^7;
sbit RS=P3^7;
sbit RW=P2^5;
void delay(xms) //延时
{
for(xms;xms>0;xms--)
{
for(a=110;a>0;a--);
}
}
void write_com(uchar com) //写命令
{
E=0;
RS=0;
RW=0;
P0=com;
delay(5);
E=1;
delay(5);
E=0;
}
void write_data(uchar date) //写数据
{
E=0;
RS=1;
RW=0;
P0=date;
delay(5);
E=1;
delay(5);
E=0;
}
void init() //初始化
{
E=0;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
}
void main()
{
init();
write_com(0x80);
for(yi=0;yi<9;yi++)
{
write_data(table0[yi]);
delay(5);
}
write_com(0x80+0x40);
for(er=0;er<8;er++)
{
write_data(table1[er]);
delay(5);
}
while(1);
}
要是能顺便拜个师就更好了 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询