#include<reg52.h>
#include<stdlib.h>
#define uint unsigned int
#define uchar unsigned char
const uchar hang3[] = {"吃到自己得分为"};
const uchar hang4[] = {"撞到墙面得分为"};
sbit RS = P3^0;
sbit RW = P3^1;
sbit EN = P3^5;
/*游戏的初始化值*/
uchar gamestatus=0;
void keychuli();
uchar keyscan();
uchar flag=1; //折点个数标志
uchar a[]={20,0,0,0,0,0,0,0};
uchar b[]={32,32,0,0,0,0,0,0};
uchar c[]={0,0,0,0,0,0,0,0};
uchar x=54,y=32,pointstatus,allpoints;
//uchar tt;
uchar timestatus; //中断标志
void delay(uchar i)
{
for(;i>0;i--);
}
void delayms( uint i)
{ uint j;
for(;i>0;i--)
{ for(j=1000;j>0;j--);}
}
uchar readstatus()
{ uchar i;
P0=0xff;
RW=1;
RS=0;
EN=0;
delay(2);
EN=1;
delay(5);
i=P0;
delay(5);
EN=0;
return(i);
}
void writecmd(uchar cmd)//写指令
{
while((readstatus() & 0x80)!= 0x00);
P0=0x00;
RW=0;
RS=0;
EN=0;
P0=cmd;
delay(2);
EN=1;
delay(5);
EN=0;
}
void writedate(uchar date)
{
while((readstatus() &0x80 )!=0x00);
P0=0x00;
RW=0;
RS=1;
EN=0;
P0=date;
delay(2);
EN=1;
delay(5);
EN=0;
}
uchar readdate()
{
uchar i;
while((readstatus() &0x80 )!=0x00);
RW=1;
RS=1;
EN=0;
delay(2);
EN=1;
delay(5);
i=P0;
delay(5);
EN=0;
return i;
}
/*******************************************
函数名称:LCD_init
功 能: 初始化LCD
参 数:无
返回值 :无
********************************************/
void LCD_init()
{
writecmd(0x30);
delayms(1);
writecmd(0x30);
delayms(1);
writecmd(0x0c);
delayms(1);
writecmd(0x01);
delayms(1);
writecmd(0x06);
delayms(1);
}
/*******************************************
函数名称:Disp_HZ
功 能:指定地址输入指定个数的字
参 数:无
返回值 :无
********************************************/
void Disp_HZ(uchar addr,const uchar * pt,uchar num)
{
uchar i;
writecmd(addr);
for(i = 0;i < (num*2);i++)
{
writedate(*(pt++));
delayms(1);
}
}
void write_sfm(uchar x,uchar y,uchar shu)
{
uchar d1,d2,add,ah;
d1=shu/10;
d2=shu%10;
if(x==0)
ah=0x80;
else if(x==1)
ah=0x90;
else if(x==2)
ah=0x88;
else ah=0x98;
add=ah+y; //相当于ah+al
writecmd(add);
writedate( d1+'0');
writedate( d2+'0');
}