基于51单片机的点阵贪吃蛇,用普中科技的51开发板做的.
#include " reg51 . h "
#include
#include
typedef unsigned int u16;
typedef unsigned char u8;
sbit up = P3 ^ 0;
sbit down = P3 ^ 1;
sbit right = P3 ^ 2;
sbit left = P3 ^ 3;
sbit SRCLK = P3 ^ 6;
sbit RCLK = P3 ^ 5;
sbit SER = P3 ^ 4;
sbit LSA = P 2 ^ 2;
sbit LSB = P 2 ^ 3;
sbit LSC = P 2 ^ 4;
u8 X [ 20 ];
u8 Y [ 20 ]; / / 蛇身的行列坐标;
u8 k , n , i; / / 分别为死亡标志,蛇身长度,通用变量;
u16 s [ 7 ];
u8 addx , addy ; / / 行偏移量,列偏移量;
u8 ledduan [ ] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
/ / 列选码表;
u8 ledwei [ ] ={ 0x7f, 0xbf, 0xdf, 0xef, 0xf7, 0xfb, 0xfd, 0xfe};
/ / 行选码表;
u8 code smgduan [ 10 ] = { 0x3f , 0x06 , 0x5b , 0x4f , 0x66 ,
0x6d , 0x7d , 0x07 , 0x7f , 0x6f };
1