求高手帮忙看下这个用独立键盘控制点阵的程序,谢谢了
时间:10-02
整理:3721RD
点击:
能不能帮我看下这个程序,为什么按下s1后没有反应呢
#include<reg52.h>
#include<intrins.h>
#include <stdlib.h>
#define uint unsigned int
#define uchar unsigned char
sbit RCK=P3^4;
sbit SCK=P3^5;
sbit SIN=P3^3;
sbit s1=P3^2;
uchar i,keycode,k,aa,temp;
uchar row[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0x00};
uchar column[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0xff};
uchar row1[]={0xff};
uchar column1[]={0x00};
uchar getkey();
void delay(int z)//延时函数
{
int x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
struct Snake//蛇的结构体
{
uchar x[10];
uchar y[10];
uchar length;
uchar direction;
// uchar live;
}snake;
void display(uchar x,uchar y)//显示蛇的函数
{
uchar i,temp,temp1,temp2;
temp=row[x];
for(i=0;i<8;i++)
{
temp1=temp&0x80;
if(temp1==0x80)
SIN=1;
else
SIN=0;
temp<<=1;
SCK=0;
_nop_();
SCK=1;
}
temp=column[y];
for(i=0;i<8;i++)
{
temp2=temp&0x80;
if(temp2==0x80)
SIN=1;
else
SIN=0;
temp<<=1;
SCK=0;
_nop_();
SCK=1;
}
RCK=0;
_nop_();
_nop_();
RCK=1;
}
void init()//初始化
{
snake.x[0]=3;
snake.y[0]=0;
snake.x[1]=3;
snake.y[1]=1;
snake.length=2;
snake.direction=4;
TMOD=11;
EA=1;
ET0=1;
TR0=1;
TH0=(65535-1000)/256;
TL0=(65535-1000)%256;
ET1=1;
TR1=1;
TH1=(65535-5000)/256;
TL1=(65535-5000)%256;
}
void playgame()//移动蛇的函数
{
for(k=0;k<snake.length-1;k++)
{
snake.x[k]=snake.x[k+1];
snake.y[k]=snake.y[k+1];
}
// snake.direction=getkey();//判断按下那个键
switch(snake.direction)
{
case 1:snake.x[1]+=1;break;
case 2:snake.x[1]-=1;break;
case 3:snake.y[1]-=1;break;
case 4:snake.y[1]+=1;break;
}
delay(5);
}
uchar getkey()
{
s1=0;
if(!s1)
{
delay(5);
if(!s1)
return 1;
}
else return snake.direction;
}
void drawsnake()
{
for(k=0;k<(36*5);k++)
{
for(i=0;i<=snake.length-1;i++)
{
display(snake.x[i],snake.y[i]);
delay(1);
}
}
}
void main()
{
init();
while(1)
{
drawsnake();
snake.direction=getkey();
playgame();
}
}
/*void timer0() interrupt 1
{
TH0=(65535-1000)/256;
TL0=(65535-1000)%256;
for(i=0;i<=snake.length-1;i++)
{
display(snake.x[i],snake.y[i]);
delay(1);
}
// undisplay(0,0);
}*/
/*void timer1() interrupt 3
{
TH1=(65535-5000)/256;
TL1=(65535-5000)%256;
}*/
#include<reg52.h>
#include<intrins.h>
#include <stdlib.h>
#define uint unsigned int
#define uchar unsigned char
sbit RCK=P3^4;
sbit SCK=P3^5;
sbit SIN=P3^3;
sbit s1=P3^2;
uchar i,keycode,k,aa,temp;
uchar row[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0x00};
uchar column[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0xff};
uchar row1[]={0xff};
uchar column1[]={0x00};
uchar getkey();
void delay(int z)//延时函数
{
int x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
struct Snake//蛇的结构体
{
uchar x[10];
uchar y[10];
uchar length;
uchar direction;
// uchar live;
}snake;
void display(uchar x,uchar y)//显示蛇的函数
{
uchar i,temp,temp1,temp2;
temp=row[x];
for(i=0;i<8;i++)
{
temp1=temp&0x80;
if(temp1==0x80)
SIN=1;
else
SIN=0;
temp<<=1;
SCK=0;
_nop_();
SCK=1;
}
temp=column[y];
for(i=0;i<8;i++)
{
temp2=temp&0x80;
if(temp2==0x80)
SIN=1;
else
SIN=0;
temp<<=1;
SCK=0;
_nop_();
SCK=1;
}
RCK=0;
_nop_();
_nop_();
RCK=1;
}
void init()//初始化
{
snake.x[0]=3;
snake.y[0]=0;
snake.x[1]=3;
snake.y[1]=1;
snake.length=2;
snake.direction=4;
TMOD=11;
EA=1;
ET0=1;
TR0=1;
TH0=(65535-1000)/256;
TL0=(65535-1000)%256;
ET1=1;
TR1=1;
TH1=(65535-5000)/256;
TL1=(65535-5000)%256;
}
void playgame()//移动蛇的函数
{
for(k=0;k<snake.length-1;k++)
{
snake.x[k]=snake.x[k+1];
snake.y[k]=snake.y[k+1];
}
// snake.direction=getkey();//判断按下那个键
switch(snake.direction)
{
case 1:snake.x[1]+=1;break;
case 2:snake.x[1]-=1;break;
case 3:snake.y[1]-=1;break;
case 4:snake.y[1]+=1;break;
}
delay(5);
}
uchar getkey()
{
s1=0;
if(!s1)
{
delay(5);
if(!s1)
return 1;
}
else return snake.direction;
}
void drawsnake()
{
for(k=0;k<(36*5);k++)
{
for(i=0;i<=snake.length-1;i++)
{
display(snake.x[i],snake.y[i]);
delay(1);
}
}
}
void main()
{
init();
while(1)
{
drawsnake();
snake.direction=getkey();
playgame();
}
}
/*void timer0() interrupt 1
{
TH0=(65535-1000)/256;
TL0=(65535-1000)%256;
for(i=0;i<=snake.length-1;i++)
{
display(snake.x[i],snake.y[i]);
delay(1);
}
// undisplay(0,0);
}*/
/*void timer1() interrupt 3
{
TH1=(65535-5000)/256;
TL1=(65535-5000)%256;
}*/