#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit E=P2^7;
sbit RW=P2^6;
sbit RS=P2^5;
void delay()
{
—nop—();
—nop—();
—nop—();
—nop—();
—nop— ();
}
void Delay(uint i)
{
uint x,j;
for(j=0;j<i;j++);
for(x=0;x<=148;x++);
}
bit Busy(void)
{
bit busy_flag=0;
RS=0;
RW=1;
E=1;
delay();
busy_flag=(bit)(P0&0x80);
E=0;
return busy_flag;
}
void wcmd(uchar del)
{
while(Busy());
RS=0;
RW=0;
E=0;
delay();
P0=del;
delay();
E=1;
delay();
E=0;
}
void wdata(uchar del)
{
while(Busy());
RS=1;
RW=0;
E=0;
delay();
P0=del;
delay();
EA=1;
delay();
EA=0;
}
void L1602_init(void)
{
wcmd(0x38);
Delay(5);
wcmd(0x38);
Delay(5);
wcmd(0x38);
Delay(5);
wcmd(0x38);
wcmd(0x08);
wcmd(0x0c);
wcmd(0x04);
wcmd(0x01);
}
void L1602_char(uchar hang,uchar lie,char sign)
{
uchar a;
if(hang == 1)a=0x80;
if(hang == 2)a=0xc0;
a=a+lie-1;
wcmd(a);
wdata(sign);
}
void L1602_string(uchar hang,uchar lie,uchar*p)
{
uchar a,b=0;
if(hang == 1)a=0x80;
if(hang == 2)a=0xc0;
a=a+lie-1;
while(1) {
wcmd(a++);
if((p==’\0’)||(b==16))break;
b++;
wdata(p);
p++;
}
}
void Main()
{
Delay(30);
L1602_init();
L1602_string(1,1," lalala “); L1602_string(2,1,” lalala ");
L1602_char(1,1,’
’);
L1602_char(1,16,’
’);
while(1);
}
有没有大佬帮忙看看,我想知道为什么仿真没结果

相关文章: