51单片机实现贪吃蛇游戏(直接代码)

废话少说,直接代码,我是用普中的板子搞得,用普中板子的同学可以直接复制拿走

#include
#include
#include
typedef unsigned int u16;
typedef unsigned char u8;
sbit SER=P3^4;
sbit RCLK=P3^5;
sbit SRCLK=P3^6;
sbit up=P3^1;
sbit down=P3^0;
sbit lt=P3^2;
sbit rt=P3^3;

u8	code Hc595_Coordx[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
u8	code Hc595_Coordy[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
u8	 foodx;
u8   foody;
u8   snake_x[20]={0};
u8   snake_y[20]={0};
u8 length;
u8 direction;
void initSnake();
void delay(u16 i);
void Hc595SendByte(u8 dat);
void move();
void Keypros();
void creatFood();
void snake_Grow(void);
void drawsnake();



void initSnake()
{
  	snake_x[0]=0;
	snake_y[0]=0;
	length=1;
	direction=2;
}
void delay(u16 i)
{
  while(i--);
}
void Hc595SendByte(u8 dat)
{
	u8 a;
	SRCLK=0;
	RCLK=0;
	for(a=0;a<8;a++)
	{
		SER=dat>>7;
		dat<<=1;

		SRCLK=1;
		_nop_();
		_nop_();
		SRCLK=0;	
	}

	RCLK=1;
	_nop_();
	_nop_();
	RCLK=0;
}



void mo

你可能感兴趣的:(51单片机)