求助!在校学生做课程设计C51接LCD1602的,有个错我真的找不出来。。。请各位前辈帮帮忙!
程序编译没错,但有两个警告。但是转成HEX放到Proteus里,那个LCD就是不显示,很气人。实在找不出来了,请各位前辈帮帮我吧!感谢!这是我的代码
#include <reg51.h>
#include <intrins.h>
#define uchar unsigned char
#define unit unsigned int
#define DelayNOPx(){_nop_();_nop_();_nop_();_nop_();}
sbit RS=P2^0;
sbit RW=P2^1;
sbit E=P2^2;
sbit BEEP=P1^0;
void DelayMS(unit ms);
bit LCD_Busy();
void LCD_Pos(uchar);
void LCD_Wcmd(uchar);
void LCD_Wdat(uchar);
char code Title_Text[]={"--phone code--"};
uchar code Key_Table[]={'1','2','3','4','5','6','7','8,''9','*','0','#'};
uchar Dial_Code_Str[]={" "};
uchar KeyNo=0xFF;
int tCount=0;
void DelayMS(uint x)
{
uchar i;
while(x--)for(i=0;i<120;i++);
}
void Display_String(uchar*str,uchar LineNo)
{
uchar k;
LCD_Pos(LineNo);
for(k=0;k<16;k++)LCD_Wdat(str[k]);
}
bit LCD_Busy()
{
bit result;
RS=0;RW=1;E=1;DelayNOPx();result=(bit)(P0&0x80);E=0;
return result;
}
void LCD_Wcmd(uchar cmd)
{
while(LCD_Busy());
RS=0;RW=0;E=0;_nop_();_nop_();P0=cmd;DelayNOPx();E=1;DelayNOPx();E=0;
}
void LCD_Wdat(uchar str)
{
while(LCD_Busy());
RS=1;RW=0;E=0;
P0=str;DelayNOPx();
E=1;DelayNOPx();E=0;
void LCD_Init()
{
LCD_Wcmd(0x38);DelayMS(1);
LCD_Wcmd(0x06);DelayMS(1);
LCD_Wcmd(0x01);DelayMS(1);
}
void LCD_Pos(uchar pos)
{
LCD_Wcmd(pos|0x80);
}
void T0_INT()interrupt 1
{
TH0=-600/256;
TL0=-600%256;
BEEP=~BEEP;
if(++tCount==200)
{
tCount=0;TR0=0;
}
}
uchar GetKey()
{
uchar i,j,k=0;
uchar KeyScanCode[]={0xEF,0xDF,0xBF,0x7F};
uchar KeyCodeTable[]=
{0xEE,0xED,0xEB,0xDE,0xDD,0xDB,0xBE,0xBD,0xBB,0x7E,0x7D,0x7B};
P3=0x0F;
if (P3!=0x0F) DelayMS(20);
if (P3!=0x0F)
{
for (i=0;i<4;i++)
{
P3=KeyScanCode[i];
for(j=0;j<3;j++)
{
k=i*3+j;
if(P3==KeyCodeTable[k]return k;
}
}
}else return 0xFF;
}
void main()
{
uchar i=-1,j;
P0=P2=P1=0xFF;
IE=0x82;
TMOD=0x01;
LCD_Init();
Display_String(Title_Text,0x00);
while(1)
{KeyNo=GetKey();
if(KeyNo==0xFF)continue;
i++;
if(KeyNo==9) {Dial_Code_Str[i-1]=' ';i=i-2;}
else {if(KeyNo==11) {for(i=0;i<16;i++)Dial_Code_Str[i]=' ';i=-1;}
else if(i==11)
{for(j=0;j<16;j++)Dial_Code_Str[j]=' ';i=0;}
Dial_Code_Str[i]=Key_Table[KeyNo];}
Display_String(Dial_Code_Str,0x40);
TR0=1;
while(GetKey()!=0xFF);
}
}
然后Proteus的运行报告里有一句这个:Controller received command whilst busy. [LCD0]
我用的是C51接LCD1602,但是运行程序LCD亮,但是不显示任何字符,麻烦大家帮帮我,真的很着急,也很无奈。