基于STC89C52单片机贪吃蛇做法(2)

2020-02-21 15:19

#include #include \

/*游戏的初始化值*/

uchar gamestatus=0; uchar flag=1; //折点个数标志

uchar a[]={20,0,0,0,0,0,0,0}; //其中(a[0],b[0])为初始蛇头坐标,(a[1],b[1])为初始蛇尾坐标,之后蛇尾坐标为(a[flag],b[flag])。 uchar b[]={32,32,0,0,0,0,0,0}; //后面(a[i],b[i])记录拐点坐标,其中(a[flag-1],b[flag-1])为第一个拐点的坐标

uchar c[]={0,0,0,0,0,0,0,0}; //c[i]记录方向,其中a[0]为当前方向 uchar x=54,y=32,pointstatus,allpoints;

/*--------------------------------------------------------------------------------- 延时函数

---------------------------------------------------------------------------------*/ void Delayus(unsigned char i) { int j; for(j=2;j>0;j--) for(;i>0;i--); }

void Delayms(unsigned int i) { unsigned int j; for(;i>0;i--) for(j=110;j>0;j--); }

/*--------------------------------------------------------------------------------- 检测忙位

---------------------------------------------------------------------------------*/ void Check_Busy() {

E=0;

RS=0; RW=1; E=1; DataPort=0xff; while((DataPort&0x80)==0x80); //忙则等待,忙标志检测BF,可以将BF读到DB7进行检测 E=0; }

/*--------------------------------------------------------------------------------- 写命令

---------------------------------------------------------------------------------*/ void Write_Cmd(unsigned char Cmd) { Check_Busy(); RS=0; RW=0; DataPort=Cmd; Delayus(2); E=1; Delayus(5); E=0; }

/*--------------------------------------------------------------------------------- 写数据

---------------------------------------------------------------------------------*/ void Write_Data(unsigned char Data) { Check_Busy(); RS=1; RW=0; E=1; DataPort=Data; Delayus(2); E=0; Delayus(5); }

/*--------------------------------------------------------------------------------- 读状态

---------------------------------------------------------------------------------*/ /*uchar Read_Status()

{ uchar i;

DataPort=0xff; RW=1; RS=0; E=0;

Delayus(2); E=1;

Delayus(5); i=DataPort; Delayus(5); E=0; return(i); } */

/*--------------------------------------------------------------------------------- 读数据

---------------------------------------------------------------------------------*/ uchar Read_Data() { uchar i;

//while((Read_Status() & 0x80 )!=0x00); //忙检测 Check_Busy(); RW=1; RS=1; E=0;

Delayus(2); E=1;

Delayus(5); i=DataPort; Delayus(5); E=0; return i; }

/*--------------------------------------------------------------------------------- 计算并显示得分

---------------------------------------------------------------------------------*/ void Write_Score(uchar x,uchar y,uchar shu) {

uchar d1,d2,add,ah; d1=shu/10;

d2=shu; if(x==0) ah=0x80; else if(x==1) ah=0x90; else if(x==2) ah=0x88; else ah=0x98;

add=ah+y; //某一行显示分数 Write_Cmd(add); Write_Data( d1+'0'); Write_Data( d2+'0'); }

/*--------------------------------------------------------------------------------- IO口初始化

---------------------------------------------------------------------------------*/ void Init_IO() { Led4=1; Led5=1; Led6=1; Led7=1; }

/*--------------------------------------------------------------------------------- 液晶屏初始化

---------------------------------------------------------------------------------*/ void Init_12864() { //WELA=0; //DULA=1; Delayms(1); PSB=1; Delayms(1); Write_Cmd(0x30); Delayms(1); Write_Cmd(0x30); Delayms(1); Write_Cmd(0x0f); Delayms(1); Write_Cmd(0x01);

Delayms(1); //Write_Cmd(0x06); //DelayVs2x(50); }

/*void disp() { unsigned char i; unsigned char a=0x10; Write_Cmd(0x80); for(i=0;i<16;i++) { Write_Data(a); a++; Delayms(2); } } */

/*--------------------------------------------------------------------------------- 用户自定义字符

---------------------------------------------------------------------------------*/ /*void CGRAM() { int i; Write_Cmd(0x30); Write_Cmd(0x40); for(i=0;i<16;i++) { Write_Data(0x10); Write_Data(0x10); } } */

/*--------------------------------------------------------------------------------- 显示字符 x:横坐标值,范围0-8 y:纵坐标值,范围1-4

---------------------------------------------------------------------------------*/

void LCD_PutString(unsigned char x,unsigned char y,unsigned char code *s) { switch(y)


基于STC89C52单片机贪吃蛇做法(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:萧的入门

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: