本人是单片机初学者,刚刚写了一个简单的1602lcd右移程序,但是错误的,求大神告知,谢谢!???? ?
时间:10-02
整理:3721RD
点击:
本人是单片机初学者,刚刚写了一个简单的1602lcd右移程序,但是错误的,想知道为什么这样编译无法执行,求大神告知,谢谢! 错误的点应该是在while(1)这里和中断
#include<reg51.h> //编译程序在单片机上没有显示。问题在下面有标识
unsigned char THOR=0;
unsigned char TLOR=0;
#define Lcd P0
sbit LcdRS=P2^6;
sbit LcdRW=P2^5;
sbit LcdE=P2^7;
unsigned char run;
unsigned char str[]="Fighting";
void Dingshi(unsigned char ms);
void Chushihua();
void Weizhixianshi(unsigned char x,unsigned char y,unsigned char *str);
void main()
{
unsigned char a=0; //不加中断的话把主函数改为Chushihua(); Weizhixianshi(2,0,str); while(1);可以显示//
EA=1;
Dingshi(2);
Chushihua();
while(1) //有问题,把Chushihua()或者Weizhixianshi()放在
{
run=0;
Weizhixianshi(a++,0,str);
if(a==16)
{
a=0;
}
}
}
}
void Waittime()
{
unsigned char Duqu=0;
Lcd=0xff;
LcdRS=0;
LcdRW=1;
do
{ LcdE=1;
Duqu=Lcd;
LcdE=0;
}while(Duqu & 0x80);
}
void Writemingling(unsigned char Zhiling)
{
Waittime();
LcdRS =0;
LcdRW=0;
LcdE=1;
Lcd=Zhiling;
LcdE=0;
}
void Writeshuju(unsigned char Zifu)
{
Waittime();
LcdRS =1;
LcdRW=0;
LcdE=1;
Lcd=Zifu;
LcdE=0;
}
void Weizhi(unsigned char x,unsigned char y)
{
if(y==0)
{
Writemingling((0x00+x)|0x80);
}
else
Writemingling((0x40+x)|0x80);
}
void Weizhixianshi(unsigned char x,unsigned char y,unsigned char *str)
{
Weizhi(x,y);
while(*str!='\0')
{
Writeshuju(*str++);
}
}
void Chushihua()
{
Writemingling(0x38);
Writemingling(0x0c);
Writemingling(0x06);
Writemingling(0x01);
}
void Dingshi(unsigned char ms)
{
unsigned long tmp;
tmp=65536+18-12000000/12*ms/1000;
THOR=(unsigned char)(tmp>>8);
TLOR=(unsigned char)(tmp);
TMOD&=0xf0;
TMOD|=0x01;
TH0=THOR;
TL0=TLOR;
ET0=1;
TR0=1;
}
void zhongduan0() interrupt 1
{
unsigned char weimiao=0;
TH0=THOR;
TL0=TLOR;
weimiao++;
if(weimiao>=500)
{
weimiao=0;
run=1;
}
}
#include<reg51.h> //编译程序在单片机上没有显示。问题在下面有标识
unsigned char THOR=0;
unsigned char TLOR=0;
#define Lcd P0
sbit LcdRS=P2^6;
sbit LcdRW=P2^5;
sbit LcdE=P2^7;
unsigned char run;
unsigned char str[]="Fighting";
void Dingshi(unsigned char ms);
void Chushihua();
void Weizhixianshi(unsigned char x,unsigned char y,unsigned char *str);
void main()
{
unsigned char a=0; //不加中断的话把主函数改为Chushihua(); Weizhixianshi(2,0,str); while(1);可以显示//
EA=1;
Dingshi(2);
Chushihua();
while(1) //有问题,把Chushihua()或者Weizhixianshi()放在
// while()后面就出现问题,实现不了右移或者左移的效果,把初始化函数中的 0x06改为0x07也没反应。
{
{
run=0;
Weizhixianshi(a++,0,str);
if(a==16)
{
a=0;
}
}
}
}
void Waittime()
{
unsigned char Duqu=0;
Lcd=0xff;
LcdRS=0;
LcdRW=1;
do
{ LcdE=1;
Duqu=Lcd;
LcdE=0;
}while(Duqu & 0x80);
}
void Writemingling(unsigned char Zhiling)
{
Waittime();
LcdRS =0;
LcdRW=0;
LcdE=1;
Lcd=Zhiling;
LcdE=0;
}
void Writeshuju(unsigned char Zifu)
{
Waittime();
LcdRS =1;
LcdRW=0;
LcdE=1;
Lcd=Zifu;
LcdE=0;
}
void Weizhi(unsigned char x,unsigned char y)
{
if(y==0)
{
Writemingling((0x00+x)|0x80);
}
else
Writemingling((0x40+x)|0x80);
}
void Weizhixianshi(unsigned char x,unsigned char y,unsigned char *str)
{
Weizhi(x,y);
while(*str!='\0')
{
Writeshuju(*str++);
}
}
void Chushihua()
{
Writemingling(0x38);
Writemingling(0x0c);
Writemingling(0x06);
Writemingling(0x01);
}
void Dingshi(unsigned char ms)
{
unsigned long tmp;
tmp=65536+18-12000000/12*ms/1000;
THOR=(unsigned char)(tmp>>8);
TLOR=(unsigned char)(tmp);
TMOD&=0xf0;
TMOD|=0x01;
TH0=THOR;
TL0=TLOR;
ET0=1;
TR0=1;
}
void zhongduan0() interrupt 1
{
unsigned char weimiao=0;
TH0=THOR;
TL0=TLOR;
weimiao++;
if(weimiao>=500)
{
weimiao=0;
run=1;
}
}
你最好把编译的错误信息也贴上。你这样说实在让人费解。
实际程序就是上面的吗?注释双斜杠位置不对吧
你先看看你的程序能不能进入中断