#include<reg51.h>
#define LCD P0
sbit EN=P2^7;
sbit RW=P2^5;
sbit RS=P2^6;
void DINGSHIQI() //定时器设置
{
TMOD=0x01;
EA=1;
ET0=1;
TR0=1;
}
void delay(char H,char L)//延时函数
{
TF0=0;TH0=H;TL0=L;
}
void lcdwritecom(char com)
{
RW=0;
RS=0;
EN=1;
delay(0xf4,0x48);//延时
LCD=com;
delay(0xf4,0x48);
EN=0;
}
void lcdwritedata(char dat)
{
RW=0;
RS=1;
EN=1;
delay(0xf4,0x48);
LCD=dat;
delay(0xf4,0x48);
EN=0;
}
void lcdchushihua()//1602初始化
{
lcdwritecom(0x01);
lcdwritecom(0x06);
lcdwritecom(0x0f);
lcdwritecom(0x14);
lcdwritecom(0x80);
}
/*-------------------------------------*/
void main()
{
char T[]="STARBUCKS";
int i;
lcdchushihua();
for(i=0;i<9;i++)
{
lcdwritedata(T[i]);
}
while(1)
{
}
}
他就是显示不了任何东西,真的很郁闷,我是新手,才刚开始学1602,之前写过一个类似的显示的还好,这个就不知道哪出问题了,调不出来。
PS:程序不够标准,望误喷。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
#include<reg51.h>
#define LCD P0
sbit EN=P2^7;
sbit RW=P2^5;
sbit RS=P2^6;
void DINGSHIQI() //定时器设置
{
TMOD=0x01;
EA=1;
ET0=1;
TR0=1;
}
void delay(char H,char L)//延时函数
{
TF0=0;TH0=H;TL0=L;
}
void lcdwritecom(char com)
{
RW=0;
RS=0;
EN=0;
LCD=com;
delay(0xf4,0x48);//延时
EN = 1;
delay(0xf4,0x48);
EN=0;
}
void lcdwritedata(char dat)
{
RW=0;
RS=1;
EN=0;
delay(0xf4,0x48);
LCD=dat;
delay(0xf4,0x48);
EN = 1;
delay(0xf4,0x48);
EN=0;
}
void lcdchushihua()//1602初始化
{
lcdwritecom(0x38);
lcdwritecom(0x0C);
lcdwritecom(0x06);
lcdwritecom(0x01);
lcdwritecom(0x80);
}
/*-------------------------------------*/
void main()
{
char T[]=" STARBUCKS";
int i;
lcdchushihua();
for(i=0;i<10;i++)
{
lcdwritedata(T[i]);
}
while(1)
{
}
}
一周热门 更多>