基于51单片机(STC32G12K128)和8X8彩色点阵屏(WS2812B驱动)的小游戏《贪吃蛇》

news2025/1/8 0:15:09

目录

  • 系列文章目录
  • 前言
  • 一、效果展示
  • 二、原理分析
  • 三、各模块代码
    • 1、定时器0
    • 2、矩阵按键模块
    • 3、8X8彩色点阵屏
  • 四、主函数
  • 总结

系列文章目录


前言

《贪吃蛇》,一款经典的、怀旧的小游戏,单片机入门必写程序。

以《贪吃蛇》为载体,熟悉各种屏幕的使用。

所用单片机:STC32G12K128-Beta。

有两个版本:自制独立按键版本和矩阵按键模块版本。

本文代码对应的是矩阵按键模块版本。

效果查看/操作演示:B站搜索“甘腾胜”或“gantengsheng”查看。
源代码下载:B站对应视频的简介有工程文件下载链接。

一、效果展示

(1)自制独立按键版本
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

(2)矩阵按键模块版本

在这里插入图片描述

二、原理分析

游戏原理可以参考以下这篇文章:
基于51单片机和8X8LED点阵屏(板载74HC595驱动)的普中开发板矩阵按键控制的小游戏《贪吃蛇》

这里主要说一下8X8彩色点阵屏(WS2812B)的显示问题。

一个灯(图片中白色正方形)里面有三个LED,分别是红、绿、蓝,白色正方形中其实也集成了WS2812B芯片,一个芯片可以存储3个字节(Byte)的数据,接收到3个字节的数据后,会把后面接收到的数据传给下一个灯的WS2812B芯片。一个字节控制一种颜色的LED,即一个灯需要用24位(Bit)控制,所以一个灯的颜色变化种类有224=16777216‬种。

如何发送0和1呢?类似DS18B20的数据发送,通过高电平的时长来确定发送的是0还是1,“0”的高电平时长较短,“1”的高电平时长较长,具体的时序图可以参考一下其他博主的文章。经过测试,高低电平的时长要求不算严格,但是需要注意的是,如果不注意定时器中断函数打断的影响,屏幕会出现“花屏”的情况,即一个字节才发送一半就被定时器中断函数打断的话,原来要发送的数据就改变了。如果以一个字节为单位,发送一个字节前关闭总中断(EA=0),发送完一个字节后再开启中断(EA=1),这样显示就不会出现问题,这样即不影响显示,也不影响定时器的运行,但是要注意,定时器中断函数代码的执行时间不能太长,太长的话相当于发送了重置(RESET)指令给WS2812B芯片,屏幕会乱闪。

三、各模块代码

1、定时器0

h文件

#ifndef __TIMER0_H__
#define __TIMER0_H__

void Timer0_Init(void);

#endif

c文件

#include <STC32G.H>

/**
  * @brief	定时器0初始化
  * @param  无
  * @retval 无
  */
void Timer0_Init(void)
{	
	AUXR|=0x80;	//定时器时钟1T模式
	TMOD&=0xF0;	//设置定时器模式(16位不自动重载)(高四位不变,低四位清零)
	TMOD|=0x01;	//设置定时器模式(16位不自动重载)(通过低四位设为“定时器0工作方式1”的模式)
	TL0=0x40;	//设置定时初值,定时1ms,1T@24.000MHz
	TH0=0xA2;	//设置定时初值,定时1ms,1T@24.000MHz
	TF0=0;	//清除TF0标志
	TR0=1;	//定时器0开始计时
	ET0=1;	//打开定时器0中断允许
	EA=1;	//打开总中断
	PT0=0;	//当PT0=0时,定时器0为低优先级,当PT0=1时,定时器0为高优先级
}

/*定时器中断函数模板
void Timer0_Routine() interrupt 1	//定时器0中断函数
{
	static unsigned int T0Count;	//定义静态变量
	TL0=0x40;	//设置定时初值,定时1ms,1T@24.000MHz
	TH0=0xA2;	//设置定时初值,定时1ms,1T@24.000MHz
	T0Count++;
	if(T0Count>=1000)
	{
		T0Count=0;
		
	}
}
*/

2、矩阵按键模块

h文件

#ifndef __MATRIXKEYSCAN_H__
#define __MATRIXKEYSCAN_H__

unsigned char Key(void);
void Key_Tick(void);

#endif

c文件

#include <STC32G.H>
#include <INTRINS.H>	//需要用空操作_nop_();来延时

#define Matrix_Port P2	//矩阵按键接口

unsigned char KeyNumber;

/**
  * @brief  获取矩阵按键键码,扫描周期内第二次获取键码值,会返回0
  * @param  无
  * @retval 按下按键的键码,范围:0~48,0表示无按键按下
  */
unsigned char Key(void)
{
	unsigned char KeyTemp=0;
	KeyTemp=KeyNumber;
	KeyNumber=0;
	return KeyTemp;
}

/**
  * @brief  检测当前按下按键的状态,无消抖及松手检测
  * @param  无
  * @retval 按下按键的键值,范围:0~16,无按键按下时返回值为0
  */
unsigned char Key_GetState()
{
	unsigned char KeyValue=0;

	Matrix_Port=0x0F;	//给所有行赋值0,列全为1
	_nop_();_nop_();	//适当延时(若不加延时,就不能正确检测按键)

	if(Matrix_Port!=0x0F)
	{
		Matrix_Port=0x0F;	//测试列
		_nop_();_nop_();
		switch(Matrix_Port)	//保存行为0时,按键按下后的列值
		{
			case 0x07:KeyValue=1;break;
			case 0x0B:KeyValue=2;break;
			case 0x0D:KeyValue=3;break;
			case 0x0E:KeyValue=4;break;
			default:break;
		}
		Matrix_Port=0xF0;	//测试行
		_nop_();_nop_();
		switch(Matrix_Port)	//保存列为0时,按键按下后的键值
		{
			case 0x70:KeyValue=KeyValue;break;
			case 0xB0:KeyValue=KeyValue+4;break;
			case 0xD0:KeyValue=KeyValue+8;break;
			case 0xE0:KeyValue=KeyValue+12;break;
			default:break;
		}
	}
	else
	{
		KeyValue=0;
	}

	return KeyValue;
}

/**
  * @brief  矩阵按键驱动函数,在中断中调用
  * @param  无
  * @retval 无
  */
void Key_Tick(void)
{
	static unsigned char NowState,LastState;
	LastState=NowState;	//按键状态更新
	NowState=Key_GetState();	//获取当前按键状态

	//如果上个时间点按键未按下,这个时间点按键按下,则是按下瞬间
	if(LastState==0)
	{
		switch(NowState)
		{
			case 1:KeyNumber=1;break;
			case 2:KeyNumber=2;break;
			case 3:KeyNumber=3;break;
			case 4:KeyNumber=4;break;
			case 5:KeyNumber=5;break;
			case 6:KeyNumber=6;break;
			case 7:KeyNumber=7;break;
			case 8:KeyNumber=8;break;
			case 9:KeyNumber=9;break;
			case 10:KeyNumber=10;break;
			case 11:KeyNumber=11;break;
			case 12:KeyNumber=12;break;
			case 13:KeyNumber=13;break;
			case 14:KeyNumber=14;break;
			case 15:KeyNumber=15;break;
			case 16:KeyNumber=16;break;
			default:break;
		}
	}
	
	//如果上个时间点按键按下,这个时间点按键还是按下,则是长按
	if(LastState && NowState)
	{
		if(LastState==1 && NowState==1){KeyNumber=17;}
		if(LastState==2 && NowState==2){KeyNumber=18;}
		if(LastState==3 && NowState==3){KeyNumber=19;}
		if(LastState==4 && NowState==4){KeyNumber=20;}
		if(LastState==5 && NowState==5){KeyNumber=21;}
		if(LastState==6 && NowState==6){KeyNumber=22;}
		if(LastState==7 && NowState==7){KeyNumber=23;}
		if(LastState==8 && NowState==8){KeyNumber=24;}
		if(LastState==9 && NowState==9){KeyNumber=25;}
		if(LastState==10 && NowState==10){KeyNumber=26;}
		if(LastState==11 && NowState==11){KeyNumber=27;}
		if(LastState==12 && NowState==12){KeyNumber=28;}
		if(LastState==13 && NowState==13){KeyNumber=29;}
		if(LastState==14 && NowState==14){KeyNumber=30;}
		if(LastState==15 && NowState==15){KeyNumber=31;}
		if(LastState==16 && NowState==16){KeyNumber=32;}
	}

	//如果上个时间点按键按下,这个时间点按键未按下,则是松手瞬间
	if(NowState==0)
	{
		switch(LastState)
		{
			case 1:KeyNumber=33;break;
			case 2:KeyNumber=34;break;
			case 3:KeyNumber=35;break;
			case 4:KeyNumber=36;break;
			case 5:KeyNumber=37;break;
			case 6:KeyNumber=38;break;
			case 7:KeyNumber=39;break;
			case 8:KeyNumber=40;break;
			case 9:KeyNumber=41;break;
			case 10:KeyNumber=42;break;
			case 11:KeyNumber=43;break;
			case 12:KeyNumber=44;break;
			case 13:KeyNumber=45;break;
			case 14:KeyNumber=46;break;
			case 15:KeyNumber=47;break;
			case 16:KeyNumber=48;break;
			default:break;
		}
	}

}

3、8X8彩色点阵屏

h文件

#ifndef __WS2812B_H__
#define __WS2812B_H__

extern unsigned char ColorStyle;	//extern:外部可使用
extern unsigned char xdata WS2812B_Buffer[];
extern unsigned char code MyColor[];
void WS2812B_SetBuf(unsigned char Position,unsigned char R,unsigned char G,unsigned char B);
void WS2812B_WriteByte(unsigned char Byte);
void WS2812B_Clear(void);
void WS2812B_UpdateDisplay(void);
void WS2812B_MoveLeft(unsigned char *Array,unsigned char R,unsigned char G,unsigned char B,unsigned int Offset);
void WS2812B_MoveUp(unsigned char *Array,unsigned char R,unsigned char G,unsigned char B,unsigned int Offset);

#endif

c文件

#include <STC32G.H>
#include <INTRINS.H>	//需要用空操作_nop_();来延时

sbit WS2812B_DI=P5^4;

unsigned char ColorStyle;	//颜色类型

//用64*3=192个字节作为WS2812B彩色点阵屏的缓存,共有64个灯,每个灯需要写入24Bit(3个字节)控制显示的颜色
//每三个字节为一组,每一组分别对应彩色灯的G(绿)、R(红)、B(蓝)三原色
unsigned char xdata WS2812B_Buffer[192];

//预设颜色(数值设小一些是为了防止太刺眼)
unsigned char code MyColor[]={
16,0,0,		//红色
0,16,0,		//绿色
0,0,16,		//蓝色
8,8,0,		//黄色
8,0,8,		//紫色
0,8,8,		//青色
};

/**
  * @brief  WS2812B彩色点阵屏私有延时函数,1T@24.000MHz调用可延时约100us
  * @param  无
  * @retval 无
  */
void WS2812B_Delay100Us(void)
{
	unsigned long edata i;
	i=600UL;
	while(i){i--;}
}

/**
  * @brief  WS2812B彩色点阵屏设置一个点的缓存
  * @param  Position 要设置的位置,高四位(0~7)对应1~8列(从左到右),低四位(0~7)对应1~8行(从上到下)
  * @param  R 红(Red),范围:0~255
  * @param  G 绿(Green),范围:0~255
  * @param  B 蓝(Blue),范围:0~255
  * @retval 无
  */
/*
本函数适用于以下数据传输顺序的8X8彩色点阵屏,如果不是的话,需要修改函数
数据从第一列的B7开始,往上到B0,然后再到第二列的B7,再往上到第二列的B0,以此类推
每一个B对应一个灯。缓存数组SnakeBuffer的8个字节分别对应这8列,高位在下
B0	B0	B0	B0	B0	B0	B0	B0
B1	B1  B1	B1	B1	B1	B1	B1
B2	B2  B2	B2	B2	B2	B2	B2
B3	B3  B3	B3	B3	B3	B3	B3
B4	B4  B4	B4	B4	B4	B4	B4
B5	B5  B5	B5	B5	B5	B5	B5
B6	B6  B6	B6	B6	B6	B6	B6
B7	B7  B7	B7	B7	B7	B7	B7
*/
void WS2812B_SetBuf(unsigned char Position,unsigned char R,unsigned char G,unsigned char B)
{
	WS2812B_Buffer[Position/16*24+(21-Position%16*3)]=G;
	WS2812B_Buffer[Position/16*24+(22-Position%16*3)]=R;
	WS2812B_Buffer[Position/16*24+(23-Position%16*3)]=B;
}

/**
  * @brief  WS2812B彩色点阵屏写入一个字节
  * @brief  要求:1T@24.000MHz,频率如果不一样,需要调“_nop_();”的数量
  * @param  Byte 要写入的字节
  * @retval 无
  */
void WS2812B_WriteByte(unsigned char Byte)
{
	unsigned char i;
	
	EA=0;	//关闭总中断(时序要求严格,不能被打断),要求中断函数执行的时间不能太长,否则会“花屏”
	
	for(i=0;i<8;i++)
	{
		if(Byte&(0x80>>i))	//高位先发
		{	//写1
			WS2812B_DI=1;	//根据高电平的时长确定发送的是1还是0,跟DS18B20类似
			_nop_();_nop_();_nop_();_nop_();_nop_();	//用空操作进行延时
			_nop_();_nop_();_nop_();_nop_();_nop_();	//单片机使用不同的频率,“_nop_();”的数量就不一样
			WS2812B_DI=0;	//经测试,数据线拉低后可以不用延时
		}
		else
		{	//写0
			WS2812B_DI=1;
			_nop_();_nop_();_nop_();_nop_();_nop_();
			WS2812B_DI=0;
		}
	}
	
	EA=1;	//开启总中断
}

/**
  * @brief  WS2812B彩色点阵屏清空缓存
  * @param  无
  * @retval 无
  */
void WS2812B_Clear(void)
{
	unsigned char i;
	for(i=0;i<192;i++){WS2812B_Buffer[i]=0;}
}

/**
  * @brief  WS2812B彩色点阵屏更新屏幕显示,将缓存数组WS2812B_Buffer的192个字节写入64个灯的芯片内
  * @param  无
  * @retval 无
  */
void WS2812B_UpdateDisplay(void)
{
	unsigned char i;
	
	for(i=0;i<192;i++){WS2812B_WriteByte(WS2812B_Buffer[i]);}	//连续写入192个字节
	
	WS2812B_Delay100Us();	//Reset(重置)信号
}

/**
  * @brief  WS2812B彩色点阵屏向左滚动显示
  * @param  Array 传递过来的数组的指针(地址),数组名就是数组的首地址
  * @param  R 红(Red),范围:0~255
  * @param  G 绿(Green),范围:0~255
  * @param  B 蓝(Blue),范围:0~255
  * @param  Offset 偏移量,向左平移Offset个像素
  * @retval 无
  */
void WS2812B_MoveLeft(unsigned char *Array,unsigned char R,unsigned char G,unsigned char B,unsigned int Offset)
{
	unsigned char i,j;
	
	Array+=Offset;
	
	for(i=0;i<8;i++)	//每个亮点都写入相同的颜色
	{
		for(j=0;j<8;j++)
		{
			if(*(Array+i)&(0x80>>j))
			{
				WS2812B_Buffer[3*8*i+3*j]=G;	//调了一下顺序,数组WS2812B_Buffer中按
				WS2812B_Buffer[3*8*i+3*j+1]=R;	//GRB的顺序放置,因WS2812B芯片就是要求按
				WS2812B_Buffer[3*8*i+3*j+2]=B;	//GRB的顺序发送数据的,方便数据发送给芯片
			}
			else
			{
				WS2812B_Buffer[3*8*i+3*j]=0;
				WS2812B_Buffer[3*8*i+3*j+1]=0;
				WS2812B_Buffer[3*8*i+3*j+2]=0;
			}
		}
	}
}

/**
  * @brief  WS2812B彩色点阵屏向上滚动显示
  * @param  Array 传递过来的数组的指针(地址),数组名就是数组的首地址
  * @param  R 红(Red),范围:0~255
  * @param  G 绿(Green),范围:0~255
  * @param  B 蓝(Blue),范围:0~255
  * @param  Offset 偏移量,向上平移Offset个像素
  * @retval 无
  */
void WS2812B_MoveUp(unsigned char *Array,unsigned char R,unsigned char G,unsigned char B,unsigned int Offset)
{
	unsigned char i,j;
	unsigned char m,n;
	unsigned char Temp[8];
	
	m=Offset/8;
	n=Offset%8;
	Array+=8*m;
	
	for(i=0;i<8;i++)	//将偏移后的数据保存到缓存数组Temp中,一个Bit对应一个灯
	{
		Temp[i]=(*Array>>n) | (*(Array+8)<<(8-n));
		Array++;
	}
	
	for(i=0;i<8;i++)	//每个亮点都写入相同的颜色
	{
		for(j=0;j<8;j++)
		{
			if(Temp[i]&(0x80>>j))
			{
				WS2812B_Buffer[3*8*i+3*j]=G;
				WS2812B_Buffer[3*8*i+3*j+1]=R;
				WS2812B_Buffer[3*8*i+3*j+2]=B;
			}
			else
			{
				WS2812B_Buffer[3*8*i+3*j]=0;
				WS2812B_Buffer[3*8*i+3*j+1]=0;
				WS2812B_Buffer[3*8*i+3*j+2]=0;
			}
		}
	}
}

四、主函数

main.c

/*
by甘腾胜@20241225
效果查看/操作演示:可以在B站搜索“甘腾胜”或“gantengsheng”查看
开发环境:Keil C251
单片机:STC32G12K128-Beta
分频系数及频率:1T@24.000MHz
外设:4X4矩阵按键模块、8X8LED彩色点阵屏(WS2812B驱动)
原理分析:https://blog.csdn.net/gantengsheng/article/details/143581157
注意:驱动WS2812B彩色点阵屏需要用1T的单片机,传统的12T单片机无法驱动

操作说明:

(1)自制独立按键版本

		K7				K2				上:K7
                                        下:K6
	K8		K5		K4		K1          左:K8
                                        右:K5
		K6				K3              开始/暂停/继续:K1
                                        返回:K2

(2)普中开发板矩阵按键版本

	S1		S2		S3		S4			上:S10				
										下:S14		
	S5		S6		S7		S8      	左:S13
										右:S15
	S9		S10		S11		S12     	开始/暂停/继续:S16
										返回:S12
	S13		S14		S15		S16     


本代码适用于以下数据传输顺序的8X8彩色点阵屏,如果不是的话,需要修改函数
数据从第一列的B7(点阵屏左下角)开始,往上到B0,然后再到第二列的B7,再往上到第二列的B0,以此类推
每一个B对应一个灯。缓存数组SnakeBuffer的8个字节分别对应这8列,高位在下
B0	B0	B0	B0	B0	B0	B0	B0
B1	B1  B1	B1	B1	B1	B1	B1
B2	B2  B2	B2	B2	B2	B2	B2
B3	B3  B3	B3	B3	B3	B3	B3
B4	B4  B4	B4	B4	B4	B4	B4
B5	B5  B5	B5	B5	B5	B5	B5
B6	B6  B6	B6	B6	B6	B6	B6
B7	B7  B7	B7	B7	B7	B7	B7

*/

#include <STC32G.H>	//包含寄存器的定义
#include <STDLIB.H>	//包含随机函数的声明
#include "WS2812B.h"	//包含工程目录下的头文件,相当于把头文件内容插入此处
#include "MatrixKeyScan.h"
#include "Timer0.h"

unsigned char KeyNum;	//存储获得的键码值
unsigned char Mode;	//游戏模式,0:显示流水灯及呼吸灯,1:显示游戏名“<<SNAKE>>”,2:显示难度的英文“DIFFICULTY”,
					//3:难度选择界面,难度范围是1~5,4:游戏模式,5:游戏结束全屏闪烁,6:显示英文“SCORE”,
					//7:循环滚动显示二位数得分,8:循环滚动显示作者和编程日期
unsigned char Mode0;	//Mode=0下的子模式,0:拖尾流水灯显示数据传输顺序,1:六种颜色的从左到右的拖尾流水灯,2:六种颜色的呼吸灯
unsigned char MoveFlag;	//移动蛇身的标志,1:移动,0:不移动
unsigned char NowDirection=1;	//蛇头移动的方向,1:向右,2:向上,3:向左,4:向下,游戏开始时默认向右移动(此处可以不赋初值)
unsigned char LastDirection=1;	//蛇头上一次移动的方向,1:向右,2:向上,3:向左,4:向下,游戏开始时默认向右移动(此处可以不赋初值)
unsigned char Length=2;	//蛇的长度,初始值为2(此处可以不赋初值,因为每次游戏开始前会重新赋值一次)
unsigned char Head=1;	//保存整条蛇的数据的数组SnakeBody(共64个数据,数据索引为:0~63)中,蛇头对应的数据的索引,蛇的初始长度为2,
						//开始时只用了两个数据(数组的第1个数据和第2个数据),蛇头对应的是第2个数据(索引为1),Head的范围:0~63
unsigned char GameOverFlag;	//游戏结束的标志,1:游戏结束,0:游戏未结束
unsigned char FlashFlag;	//闪烁的标志,1:不显示,0:显示
unsigned char Food;	//保存创造出来的食物的位置,高四位(0~7)对应1~8列(从左到右),低四位(0~7)对应1~8行(从上到下)
unsigned int Offset1;	//偏移量,用来控制汉字或数字向左滚动显示(切换模式后清零)
unsigned int Offset2;	//偏移量,用来控制难度选择界面对应的数字上下滚动显示(切换模式后不清零)
unsigned char RollFlag;	//滚动的标志,1:滚动,0:不滚动
unsigned char RollUpFlag;	//难度选择界面,数字向上滚动的标志,1:滚动,0:不滚动
unsigned char RollDownFlag;	//难度选择界面,数字向下滚动的标志,1:滚动,0:不滚动
unsigned char RollCount;	//上下滚动的计次
unsigned char ExecuteOnceFlag;	//各模式中(切换到该模式后,切换为其他模式前)只执行一次的标志,1:执行,0:不执行
unsigned int SnakeMoveSpeed=1000;	//控制蛇移动的速度,值越小,速度越快
unsigned int T0Count0,T0Count1,T0Count2,T0Count3,T0Count4,T0Count5;	//定时器计数的变量
unsigned char PauseFlag;	//暂停的标志,1:暂停,0:不暂停
unsigned char SnakeBody[64];	//点阵屏是8*8=64个像素,需要用64个数据记录蛇身的数据
unsigned char SnakeBuffer[8];	//显示缓存,一个字节对应8个点,屏幕总共64个点,所以需要8个字节
								//阴码(亮点为1),逐列式取模,高位在下
								//此数组用来保存点阵屏哪些点亮,哪些点不亮
unsigned char Breath=1;	//用来实现呼吸灯的效果
unsigned char BreathInOrOut=1;	//用来控制呼吸灯变亮还是变暗
unsigned char BreathFlag;	//呼吸灯改变亮度的标志,定时器中每隔一段时间将此标志置1
unsigned char BreathCount;	//用来使呼吸灯熄灭后的时间长一点
unsigned char BreathColor;	//控制呼吸灯显示的颜色
unsigned char ExecuteOnceFlag0;	//子模式中只执行一次的标志,1:执行,0:不执行

unsigned char Score[]={	//用来滚动显示得分
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,	//无显示
0x00,0x00,0x00,0x00,0x00,0x00,	//游戏结束后将蛇身长度Length的十位的数字字模写入到这一行
0x00,0x00,0x00,0x00,0x00,0x00,	//游戏结束后将蛇身长度Length的个位的数字字模写入到这一行
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,	//无显示
};

unsigned char code FlowingWaterLight1[]={	//流水灯1(拖尾)
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

0,255,255,0,255,255,0,255,255,0,255,255,0,255,255,0,255,255,0,255,255,0,255,255,	//黄
0,127,127,0,127,127,0,127,127,0,127,127,0,127,127,0,127,127,0,127,127,0,127,127,
0,63,63,0,63,63,0,63,63,0,63,63,0,63,63,0,63,63,0,63,63,0,63,63,
0,31,31,0,31,31,0,31,31,0,31,31,0,31,31,0,31,31,0,31,31,0,31,31,
0,15,15,0,15,15,0,15,15,0,15,15,0,15,15,0,15,15,0,15,15,0,15,15,
0,7,7,0,7,7,0,7,7,0,7,7,0,7,7,0,7,7,0,7,7,0,7,7,
0,3,3,0,3,3,0,3,3,0,3,3,0,3,3,0,3,3,0,3,3,0,3,3,
0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,

0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

255,255,0,255,255,0,255,255,0,255,255,0,255,255,0,255,255,0,255,255,0,255,255,0,	//紫
127,127,0,127,127,0,127,127,0,127,127,0,127,127,0,127,127,0,127,127,0,127,127,0,
63,63,0,63,63,0,63,63,0,63,63,0,63,63,0,63,63,0,63,63,0,63,63,0,
31,31,0,31,31,0,31,31,0,31,31,0,31,31,0,31,31,0,31,31,0,31,31,0,
15,15,0,15,15,0,15,15,0,15,15,0,15,15,0,15,15,0,15,15,0,15,15,0,
7,7,0,7,7,0,7,7,0,7,7,0,7,7,0,7,7,0,7,7,0,7,7,0,
3,3,0,3,3,0,3,3,0,3,3,0,3,3,0,3,3,0,3,3,0,3,3,0,
1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,

0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

255,0,255,255,0,255,255,0,255,255,0,255,255,0,255,255,0,255,255,0,255,255,0,255,	//青
127,0,127,127,0,127,127,0,127,127,0,127,127,0,127,127,0,127,127,0,127,127,0,127,
63,0,63,63,0,63,63,0,63,63,0,63,63,0,63,63,0,63,63,0,63,63,0,63,
31,0,31,31,0,31,31,0,31,31,0,31,31,0,31,31,0,31,31,0,31,31,0,31,
15,0,15,15,0,15,15,0,15,15,0,15,15,0,15,15,0,15,15,0,15,15,0,15,
7,0,7,7,0,7,7,0,7,7,0,7,7,0,7,7,0,7,7,0,7,7,0,7,
3,0,3,3,0,3,3,0,3,3,0,3,3,0,3,3,0,3,3,0,3,3,0,3,
1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,

0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
};

//取模要求:阴码(亮点为1),逐列式取模,高位在下
//点阵屏摆放方向不同,取模要求也不同,很多函数也需要修改
unsigned char code Table1[]={	//“<<SNAKE>>”
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,	//无显示
0x00,0x08,0x14,0x22,0x49,0x14,0x22,0x41,	// <<	宽8高8
0x00,0x46,0x49,0x49,0x49,0x31,	// S 51	宽6高8
0x00,0x7F,0x04,0x08,0x10,0x7F,	// N 46
0x00,0x7C,0x12,0x11,0x12,0x7C,	// A 33
0x00,0x7F,0x08,0x14,0x22,0x41,	// K 43
0x00,0x7F,0x49,0x49,0x49,0x41,	// E 37
0x00,0x41,0x22,0x14,0x49,0x22,0x14,0x08,	// >>
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,	//无显示
};
unsigned char code Table2[]={	//“DIFFICULTY”,宽6高8
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,	//无显示
0x00,0x7F,0x41,0x41,0x22,0x1C,	// D 36
0x00,0x00,0x41,0x7F,0x41,0x00,	// I 41
0x00,0x7F,0x09,0x09,0x09,0x01,	// F 38
0x00,0x7F,0x09,0x09,0x09,0x01,	// F 38
0x00,0x00,0x41,0x7F,0x41,0x00,	// I 41
0x00,0x3E,0x41,0x41,0x41,0x22,	// C 35
0x00,0x3F,0x40,0x40,0x40,0x3F,	// U 53
0x00,0x7F,0x40,0x40,0x40,0x40,	// L 44
0x00,0x01,0x01,0x7F,0x01,0x01,	// T 52
0x00,0x07,0x08,0x70,0x08,0x07,	// Y 57
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,	//无显示
0x00,0x00,0x00,0x42,0x7F,0x40,0x00,0x00,	// 1 17 如果不按按键跳过,则在显示“1”后自动切换到下一个模式
};
unsigned char code Table3[]={	//“123451”,宽8高8
0x00,0x00,0x00,0x42,0x7F,0x40,0x00,0x00,	// 1 17
0x00,0x00,0x42,0x61,0x51,0x49,0x46,0x00,	// 2 18
0x00,0x00,0x21,0x41,0x45,0x4B,0x31,0x00,	// 3 19
0x00,0x00,0x18,0x14,0x12,0x7F,0x10,0x00,	// 4 20
0x00,0x00,0x27,0x45,0x45,0x45,0x39,0x00,	// 5 21
0x00,0x00,0x00,0x42,0x7F,0x40,0x00,0x00,	// 1 17
};
unsigned char code Table4[]={	//“SCORE”,宽6高8
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,	//无显示
0x00,0x46,0x49,0x49,0x49,0x31,	// S 51
0x00,0x3E,0x41,0x41,0x41,0x22,	// C 35
0x00,0x3E,0x41,0x41,0x41,0x3E,	// O 47
0x00,0x7F,0x09,0x19,0x29,0x46,	// R 50
0x00,0x7F,0x49,0x49,0x49,0x41,	// E 37
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,	//无显示
};
unsigned char code Table5[]={	//“0~9”,宽6高8
0x00,0x3E,0x51,0x49,0x45,0x3E,	// 0 16
0x00,0x00,0x42,0x7F,0x40,0x00,	// 1 17
0x00,0x42,0x61,0x51,0x49,0x46,	// 2 18
0x00,0x21,0x41,0x45,0x4B,0x31,	// 3 19
0x00,0x18,0x14,0x12,0x7F,0x10,	// 4 20
0x00,0x27,0x45,0x45,0x45,0x39,	// 5 21
0x00,0x3C,0x4A,0x49,0x49,0x30,	// 6 22
0x00,0x01,0x71,0x09,0x05,0x03,	// 7 23
0x00,0x36,0x49,0x49,0x49,0x36,	// 8 24
0x00,0x06,0x49,0x49,0x29,0x1E,	// 9 25
};
unsigned char code Table6[]={	//“by gantengsheng at 20241225”,宽6高8
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,	//无显示
0x00,0x7F,0x48,0x44,0x44,0x38,	// b 66
0x00,0x1C,0xA0,0xA0,0xA0,0x7C,	// y 89
0x00,0x00,0x00,0x00,0x00,0x00,	//   0
0x00,0x18,0xA4,0xA4,0xA4,0x7C,	// g 71
0x00,0x20,0x54,0x54,0x54,0x78,	// a 65
0x00,0x7C,0x08,0x04,0x04,0x78,	// n 78
0x00,0x04,0x3F,0x44,0x40,0x20,	// t 84
0x00,0x38,0x54,0x54,0x54,0x18,	// e 69
0x00,0x7C,0x08,0x04,0x04,0x78,	// n 78
0x00,0x18,0xA4,0xA4,0xA4,0x7C,	// g 71
0x00,0x48,0x54,0x54,0x54,0x20,	// s 83
0x00,0x7F,0x08,0x04,0x04,0x78,	// h 72
0x00,0x38,0x54,0x54,0x54,0x18,	// e 69
0x00,0x7C,0x08,0x04,0x04,0x78,	// n 78
0x00,0x18,0xA4,0xA4,0xA4,0x7C,	// g 71
0x00,0x00,0x00,0x00,0x00,0x00,	//   0
0x00,0x20,0x54,0x54,0x54,0x78,	// a 65
0x00,0x04,0x3F,0x44,0x40,0x20,	// t 84
0x00,0x00,0x00,0x00,0x00,0x00,	//   0
0x00,0x42,0x61,0x51,0x49,0x46,	// 2 18
0x00,0x3E,0x51,0x49,0x45,0x3E,	// 0 16
0x00,0x42,0x61,0x51,0x49,0x46,	// 2 18
0x00,0x18,0x14,0x12,0x7F,0x10,	// 4 20
0x00,0x00,0x42,0x7F,0x40,0x00,	// 1 17
0x00,0x42,0x61,0x51,0x49,0x46,	// 2 18
0x00,0x42,0x61,0x51,0x49,0x46,	// 2 18
0x00,0x27,0x45,0x45,0x45,0x39,	// 5 21
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,	//无显示
};

/**
  * @brief  创造出一个随机位置的食物
  * @param  无
  * @retval 创造出的食物位置的数据,高四位(0~7)对应1~8列(从左到右),低四位(0~7)对应1~8行(从上到下)
  */
unsigned char CreateFood(void)
{
	unsigned char FoodTemp;
	unsigned char i,j,m,n;
	m=rand()%8;	//产生一个0~7的随机数
	n=rand()%8;	//产生一个0~7的随机数
	for(i=0;i<8;i++)	//产生一个随机位置,判断该位置是否是蛇身
	{	//如果不是,就返回该位置所对应的数据,如果是蛇身的位置,则从该点向周围寻找不是蛇身的空位置
		for(j=0;j<8;j++)
		{
			if( ( SnakeBuffer[(m+i)%8] & (0x01<<((n+j)%8)) ) == 0 )
			{
				FoodTemp=(m+i)%8*16+(n+j)%8;
				break;	//找到了空位置就退出循环
			}
		}
	}
	return FoodTemp;
}

/**
  * @brief  改变缓存数组SnakeBuffer的数据
  * @param  Position 要设置的位置,高四位(0~7)对应1~8列(从左到右),低四位(0~7)对应1~8行(从上到下)
  * @param  State 要修改成的状态,范围:0~1,0:对应的那个Bit置0,1:对应的那个Bit置1
  * @retval 无
  */
void ChangeSnakeBuffer(unsigned char Position,unsigned char State)
{
	if(State)
	{
		SnakeBuffer[Position/16] |= (0x01<<(Position%16));
	}
	else
	{
		SnakeBuffer[Position/16] &= ~(0x01<<(Position%16));
	}
}

/**
  * @brief  控制蛇的移动
  * @param  无
  * @retval 无
  */
void MoveSnake(void)
{
	if(NowDirection==1)	//如果向右移动
	{
		//移动前判断一下移动后是否撞墙,如果是,则游戏结束,游戏结束的标志置1
		if(SnakeBody[Head]/16==7){GameOverFlag=1;}
		
		//(Head+1)%64,取余的目的是为了防止越界,SnakeBody数组的索引范围是:0~63,索引为63后再加1,就越界了
		//SnakeBody数组中索引为(Head+1)%64的数据(准蛇头)等于索引为Head的数据(现蛇头)加16(高四位加1),即蛇头移动到了右边这一列
		else{SnakeBody[(Head+1)%64]=SnakeBody[Head]+16;}
	}
	if(NowDirection==2)	//如果向上移动
	{
		if(SnakeBody[Head]%16==0){GameOverFlag=1;}
		
		//SnakeBody数组中索引为(Head+1)%64的数据(准蛇头)等于索引为Head的数据(现蛇头)减1(低四位减1),即蛇头移动到了上边这一行
		else{SnakeBody[(Head+1)%64]=SnakeBody[Head]-1;}
	}
	if(NowDirection==3)	//如果向左移动
	{
		if(SnakeBody[Head]/16==0){GameOverFlag=1;}
		
		//SnakeBody数组中索引为(Head+1)%64的数据(准蛇头)等于索引为Head的数据(现蛇头)减16(高四位减1),即蛇头移动到了左边这一列
		else{SnakeBody[(Head+1)%64]=SnakeBody[Head]-16;}
	}
	if(NowDirection==4)	//如果向下移动
	{
		if(SnakeBody[Head]%16==7){GameOverFlag=1;}
		
		//SnakeBody数组中索引为(Head+1)%64的数据(准蛇头)等于索引为Head的数据(现蛇头)加1(低四位减1),即蛇头移动到了下边这一行
		else{SnakeBody[(Head+1)%64]=SnakeBody[Head]+1;}
	}
	
	Head++;	//SnakeBody数组中,蛇头对应的数据的索引加1
	Head%=64;	//蛇头变量Head的范围是0~63
	
	if(GameOverFlag==0)	//如果没撞墙
	{
		if(SnakeBody[Head]==Food)	//判断蛇头移动后的位置是否是食物所在的位置
		{	//如果是
			Length++;	//蛇身长度加1
			ColorStyle++;	//蛇身和食物均切换为下一种颜色
			ColorStyle%=6;	//预设了6种颜色:红、绿、蓝、黄、紫、青
			ChangeSnakeBuffer(Food,1);	//更新缓存数组SnakeBody的数据
			if(Length<64)	//如果蛇身长度没有达到最大值64
			{
				Food=CreateFood();	//重新创造一个食物
			}
			else	//如果蛇身长度达到了最大值64
			{
				GameOverFlag=1;	//游戏结束
			}
			FlashFlag=0;	//创造出新的食物时,食物暂不闪烁
			T0Count4=0;	//定时器T0Count4重新计数
		}
		else if( SnakeBuffer[SnakeBody[Head]/16] & (0x01<<(SnakeBody[Head]%16)) )
		{	//如果蛇头移动后的位置不是食物,且撞在蛇身上,则游戏结束
			GameOverFlag=1;	//游戏结束的标志置1
		}
		else	//如果蛇头移动后的位置不是食物,也不是撞墙,也不是撞到蛇身的话
		{
			ChangeSnakeBuffer(SnakeBody[Head],1);
			ChangeSnakeBuffer(SnakeBody[(Head+64-Length)%64],0);
		}
	}

}

/**
  * @brief  IO口初始化,全部设置为上拉模式
  * @param  无
  * @retval 无
  */
void GPIO_Init(void)
{
	P0M1=0;P0M0=0;
	P1M1=0;P1M0=0;
	P2M1=0;P2M0=0;
	P3M1=0;P3M0=0;
	P4M1=0;P4M0=0;
	P5M1=0;P5M0=0;
	P6M1=0;P6M0=0;
	P7M1=0;P7M0=0;
}

void main()
{
	unsigned char i;
    WTST=0;	//不加这句,则延时不准确
	GPIO_Init();	//IO口初始化
	Timer0_Init();	//定时器初始化
	ExecuteOnceFlag=1;

	while(1)
	{
		KeyNum=Key();	//获取键码值

		if(KeyNum)	//如果有按键按下
		{
			srand(TL0);	//以定时器0的低八位数据作为随机数的种子,用来产生真随机的数据

			if(Mode==8)	//如果是显示作者和编程日期的界面
			{
				if(KeyNum==44)	//如果按下K12(松手瞬间)
				{
					Mode=3;	//返回难度选择界面
					ExecuteOnceFlag=1;	//各模式只执行一次代码的标志置1
				}
			}

			if(Mode==7)	//如果是滚动显示得分的界面
			{
				if(KeyNum==41)	//如果按下K9(松手瞬间)
				{
					Mode=8;	//切换到显示作者和编程日期的界面
					ExecuteOnceFlag=1;
				}
				if(KeyNum==44)	//如果按下K12(松手瞬间)
				{
					Mode=3;	//返回难度选择界面
					ExecuteOnceFlag=1;
				}
			}

			if(Mode==6)	//如果是滚动显示英文“SCORE”的界面
			{
				if(KeyNum!=9 && KeyNum!=25 && KeyNum!=41 && KeyNum!=12 && KeyNum!=28 && KeyNum!=44)
				{	//如果按下K9和K12以外的按键
					Mode=7;	//跳过英文显示,切换到滚动显示得分界面
					ExecuteOnceFlag=1;
				}
			}

			if(Mode==5)	//如果是游戏结束全屏闪烁界面
			{
				if(KeyNum==48)	//如果按下K16(松手瞬间)
				{
					Mode=6;	//切换到滚动显示英文“SCORE”的界面
					ExecuteOnceFlag=1;
				}
			}

			if(Mode==4)	//如果是游戏进行中
			{
				if(KeyNum==48)	//按下K16暂停或继续(松手瞬间)
				{
					PauseFlag=!PauseFlag;
					if(PauseFlag==0){T0Count3=0;}
				}
				if(PauseFlag==0)	//如果不是暂停
				{	//按下瞬间、长按、松手瞬间都进行检测,这样控制方向更有效,防止按键没检测出来导致没能改变方向
					if((KeyNum==13 || KeyNum==29 || KeyNum==45) && LastDirection!=1)
					{	//如果按了“左”键,且蛇头原来的移动方向不是向右
						NowDirection=3;	//则方向蛇头方向改为向左
					}
					if((KeyNum==10 || KeyNum==26 || KeyNum==42) && LastDirection!=4)
					{	//如果按了“上”键,且蛇头原来的移动方向不是向下
						NowDirection=2;	//则方向蛇头方向改为向上
					}
					if((KeyNum==14 || KeyNum==30 || KeyNum==46) && LastDirection!=2)
					{	//如果按了“下”键,且蛇头原来的移动方向不是向上
						NowDirection=4;	//则方向蛇头方向改为向左
					}
					if((KeyNum==15 || KeyNum==31 || KeyNum==47) && LastDirection!=3)
					{	//如果按了“右”键,且蛇头原来的移动方向不是向左
						NowDirection=1;	//则方向蛇头方向改为向左
					}
				}
			}

			if(Mode==3)	//如果是难度选择界面
			{
				if(KeyNum==42)	//如果按了“上”键K10(松手瞬间)
				{
					RollUpFlag=1;	//数字向上滚动的标志置1
				}
				if(KeyNum==46)	//如果按了“下”键K14(松手瞬间)
				{
					RollDownFlag=1;	//数字向下滚动的标志置1
				}
				if(KeyNum==48)	//如果按了开始键K16(松手瞬间)
				{
					Mode=4;	//切换到游戏模式
					ExecuteOnceFlag=1;
				}
			}

			if(Mode==2)	//如果是显示英文“DIFFICULTY”的界面
			{
				if(KeyNum>=33 && KeyNum<=48)	//如果按下任意按键(松手瞬间)
				{
					Mode=3;	//切换到难度选择界面
					ExecuteOnceFlag=1;
				}
			}

			if(Mode==1)	//如果是显示游戏名“<<SNAKE>>”的界面
			{
				if(KeyNum>=33 && KeyNum<=48)	//如果按下任意按键(松手瞬间)
				{
					Mode=2;	//切换到英文“DIFFICULTY”的显示界面
					ExecuteOnceFlag=1;
				}
			}

			if(Mode==0)	//如果是显示流水灯界面
			{
				if(KeyNum==42)	//如果按了“上”键K10(松手瞬间)
				{
					Mode0++;	//切换子模式
					Mode0%=3;	//共有三个子模式
					ExecuteOnceFlag0=1;
				}
				if(KeyNum==46)	//如果按了“下”键K14(松手瞬间)
				{
					if(Mode0==0){Mode0=2;}
					else{Mode0--;}
					ExecuteOnceFlag0=1;
				}
				if(KeyNum>=33 && KeyNum<=48 && KeyNum!=42 && KeyNum!=46)
				{	//如果按了K10和K14以外的按键(松手瞬间),切换为显示游戏名“<<SNAKE>>”的模式
					Mode=1;	//切换到游戏模式
					ExecuteOnceFlag=1;
				}
			}

		}

		if(Mode==0)	//如果是显示彩色流水灯的界面
		{
			if(ExecuteOnceFlag)	//切换模式前,此if的内容只执行一次
			{
				ExecuteOnceFlag=0;
				Offset1=0;	//偏移量清零
				for(i=0;i<8;i++)	//呼吸灯需要用到数组SnakeBuffer
				{
					SnakeBuffer[i]=0xFF;
				}
			}
			if(Mode0==0)	//拖尾流水灯(六种颜色:红、绿、蓝、黄、紫、青)显示数据传输顺序
			{
				if(ExecuteOnceFlag0)	//切换到Mode0==0后,切换为其他模式前,此if的代码只执行一次
				{
					ExecuteOnceFlag0=0;
					Offset1=0;	//偏移量清零
				}
				if(RollFlag)
				{
					RollFlag=0;
					for(i=0;i<192;i++)	//通过查表的方法显示流水灯
					{
						WS2812B_Buffer[i]=FlowingWaterLight1[191-i+3*Offset1];
					}
					WS2812B_UpdateDisplay();	//改变缓存WS2812B_Buffer后,更新到屏幕的显示
					Offset1++;
					Offset1%=400;
				}
			}
			if(Mode0==1)	//显示从左到右的六种颜色(红、绿、蓝、黄、紫、青)的拖尾流水灯
			{
				if(ExecuteOnceFlag0)
				{
					ExecuteOnceFlag0=0;
					Offset1=0;
				}				
				if(RollFlag)
				{
					RollFlag=0;
					for(i=0;i<192;i++)	//通过查表的方法显示流水灯
					{
						WS2812B_Buffer[i]=FlowingWaterLight2[191-i+24*Offset1];
					}
					WS2812B_UpdateDisplay();
					Offset1++;
					Offset1%=96;
				}
			}
			if(Mode0==2)	//六种颜色(红、绿、蓝、黄、紫、青)的呼吸灯
			{
				if(ExecuteOnceFlag0)
				{
					ExecuteOnceFlag0=0;
					Breath=1;
					BreathInOrOut=1;
					BreathColor=0;
				}
				if(BreathFlag)
				{
					BreathFlag=0;
					if(Breath==0 && BreathCount<15){BreathCount++;PauseFlag=1;}	//完全熄灭后延时一小段时间
					else{BreathCount=0;PauseFlag=0;}
					if(PauseFlag==0)
					{
						if(Breath==0){BreathInOrOut=1;BreathColor++;BreathColor%=6;}
						if(Breath==255){BreathInOrOut=0;}	//Breath的值决定亮度
						if(BreathInOrOut){Breath++;}	//变亮
						else{Breath--;}	//变暗
						switch(BreathColor)
						{
							case 0:WS2812B_MoveLeft(SnakeBuffer,Breath,0,0,0);break;	//红
							case 1:WS2812B_MoveLeft(SnakeBuffer,0,Breath,0,0);break;	//绿
							case 2:WS2812B_MoveLeft(SnakeBuffer,0,0,Breath,0);break;	//蓝
							case 3:WS2812B_MoveLeft(SnakeBuffer,(unsigned char)(Breath/2),(unsigned char)(Breath/2),0,0);break;	//黄
							case 4:WS2812B_MoveLeft(SnakeBuffer,(unsigned char)(Breath/2),0,(unsigned char)(Breath/2),0);break;	//紫
							case 5:WS2812B_MoveLeft(SnakeBuffer,0,(unsigned char)(Breath/2),(unsigned char)(Breath/2),0);break;	//青
							default:break;
						}
						WS2812B_UpdateDisplay();
					}
				}
			}
		}

		if(Mode==1)	//如果是显示游戏名称“<<SNAKE>>”的界面
		{
			if(ExecuteOnceFlag)
			{
				ExecuteOnceFlag=0;
				Offset1=0;
			}
			if(RollFlag)
			{
				RollFlag=0;
				WS2812B_MoveLeft(Table1,16,0,0,Offset1);	//红色
				WS2812B_UpdateDisplay();
				Offset1++;
				Offset1%=54;	//循环滚动显示
			}
		}

		if(Mode==2)	//如果是显示英文“DIFFICULTY”的界面
		{
			if(ExecuteOnceFlag)
			{
				ExecuteOnceFlag=0;
				Offset1=0;
			}
			if(RollFlag)	//只向左滚动显示一次,不循环滚动显示
			{
				if(Offset1<=68)	//只向左滚动显示一次,不循环滚动显示
				{
					RollFlag=0;
					WS2812B_MoveLeft(Table2,0,16,0,Offset1);	//绿色
					WS2812B_UpdateDisplay();
					Offset1++;
				}
				else if(Offset1<=76)	//只向左滚动显示一次,不循环滚动显示
				{
					RollFlag=0;
					WS2812B_MoveLeft(Table2,0,0,16,Offset1);	//蓝色
					WS2812B_UpdateDisplay();
					Offset1++;
				}
				else	//显示数字“1”之后,自动切换到难度选择界面
				{
					Mode=3;
					ExecuteOnceFlag=1;
				}
			}
		}

		if(Mode==3)	//如果是难度选择界面
		{
			if(ExecuteOnceFlag)
			{
				ExecuteOnceFlag=0;
				WS2812B_MoveUp(Table3,0,0,16,Offset2);	//蓝色
				WS2812B_UpdateDisplay();
			}
			if(RollFlag && RollUpFlag)	//如果滚动标志为1,且向上滚动的标志也为1
			{
				RollFlag=0;
				Offset2++;	//向上移动一个像素
				Offset2%=40;	//越界清零,总共5个数字,每个数字的高度是8,所以是5*8=40
				WS2812B_MoveUp(Table3,0,0,16,Offset2);
				WS2812B_UpdateDisplay();
				RollCount++;
				if(RollCount==8)	//移动了8个像素后停止移动
				{
					RollCount=0;
					RollUpFlag=0;
					Offset2=(Offset2/8)*8;	//防止移动到一半的时候按下“上”或“下”按键导致数字没有在点阵屏中间
											//Offset2的值必须是8的整数倍
					switch(Offset2/8)
					{
						case 0:SnakeMoveSpeed=1000;break;	//难度1,1s移动1次
						case 1:SnakeMoveSpeed=750;break;	//难度2,0.75s移动1次
						case 2:SnakeMoveSpeed=500;break;	//难度3,0.5s移动1次
						case 3:SnakeMoveSpeed=250;break;	//难度4,0.25s移动1次
						case 4:SnakeMoveSpeed=120;break;	//难度5,0.12s移动1次
						default:break;
					}
				}
			}
			if(RollFlag && RollDownFlag)	//如果滚动标志为1,且向下滚动的标志也为1
			{
				RollFlag=0;
				if(Offset2==0){Offset2=40;}
				Offset2--;
				WS2812B_MoveUp(Table3,0,0,16,Offset2);
				WS2812B_UpdateDisplay();
				RollCount++;
				if(RollCount==8)
				{
					RollCount=0;
					RollDownFlag=0;
					Offset2=(Offset2/8)*8;
					switch(Offset2/8)
					{
						case 0:SnakeMoveSpeed=1000;break;
						case 1:SnakeMoveSpeed=750;break;
						case 2:SnakeMoveSpeed=500;break;
						case 3:SnakeMoveSpeed=250;break;
						case 4:SnakeMoveSpeed=120;break;
						default:break;
					}
				}
			}
		}

		if(Mode==4)	//如果是游戏进行模式
		{
			if(ExecuteOnceFlag)	//游戏初始化
			{
				ExecuteOnceFlag=0;
				WS2812B_Clear();	//清除WS2812B显示缓存
				ColorStyle=rand()%6;	//从预设的六种颜色中随机选一种作为蛇的起始颜色
				GameOverFlag=0;	//游戏结束标志清零
				PauseFlag=0;	//游戏暂停标志清零
				NowDirection=1;	//蛇头默认向右移动
				LastDirection=1;	//上一次蛇头默认向右移动
				Length=2;	//蛇的初始长度为2
				Head=1;	//蛇头对应数组中的第2个数据(索引为1)
				for(i=0;i<8;i++){SnakeBuffer[i]=0;}	//SnakeBuffer显示缓存全部清零
				SnakeBody[0]=1*16+1;	//蛇身数据全部清零后,写入蛇身初始的两个数据
				SnakeBody[1]=2*16+1;
				ChangeSnakeBuffer(SnakeBody[0],1);
				ChangeSnakeBuffer(SnakeBody[1],1);
				WS2812B_SetBuf(SnakeBody[0],MyColor[ColorStyle%6*3],MyColor[ColorStyle%6*3+1],MyColor[ColorStyle%6*3+2]);
				WS2812B_SetBuf(SnakeBody[1],MyColor[ColorStyle%6*3],MyColor[ColorStyle%6*3+1],MyColor[ColorStyle%6*3+2]);
				Food=CreateFood();	//开始游戏前,先创造出一个食物
				WS2812B_SetBuf(Food,MyColor[(ColorStyle+1)%6*3],MyColor[(ColorStyle+1)%6*3+1],MyColor[(ColorStyle+1)%6*3+2]);
				WS2812B_UpdateDisplay();	//更改缓存后,更新屏幕的显示
				MoveFlag=0;	//蛇移动的标志清零
				T0Count3=0;	//定时器计数变量T0Count3清零,重新计数
			}
			if(GameOverFlag==0)	//如果游戏没结束
			{
				if(MoveFlag && PauseFlag==0)
				{
					MoveFlag=0;	//移动标志清零
					MoveSnake();	//移动一次
					LastDirection=NowDirection;	//保存上一次移动的方向,用于按键的判断(蛇不能往后移动)
					WS2812B_MoveLeft(SnakeBuffer,MyColor[ColorStyle%6*3],MyColor[ColorStyle%6*3+1],MyColor[ColorStyle%6*3+2],0);
				}
				if(PauseFlag)	//如果暂停了
				{	//(ColorStyle+1)%6:食物的颜色是预设模式中,蛇的颜色的下一种颜色,预设颜色:红绿蓝黄紫青
					WS2812B_SetBuf(Food,MyColor[(ColorStyle+1)%6*3],MyColor[(ColorStyle+1)%6*3+1],MyColor[(ColorStyle+1)%6*3+2]);	//食物不闪烁,一直显示
				}			
				else if(FlashFlag)	//如果不暂停,且闪烁标志为1
				{
					WS2812B_SetBuf(Food,0,0,0);	//不显示食物
				}
				else	//如果不暂停,且闪烁标志为0
				{
					WS2812B_SetBuf(Food,MyColor[(ColorStyle+1)%6*3],MyColor[(ColorStyle+1)%6*3+1],MyColor[(ColorStyle+1)%6*3+2]);	//显示食物
				}
				WS2812B_UpdateDisplay();
			}
			else	//如果游戏结束
			{
				Mode=5;	//切换到全屏闪烁模式
				ExecuteOnceFlag=1;			
			}				
		}
		
		if(Mode==5)	//全屏闪烁
		{
			if(FlashFlag)	//不显示
			{
				WS2812B_Clear();
				WS2812B_UpdateDisplay();
			}
			else	//显示
			{
				WS2812B_MoveLeft(SnakeBuffer,MyColor[ColorStyle%6*3],MyColor[ColorStyle%6*3+1],MyColor[ColorStyle%6*3+2],0);
				if(Length<64)	//防止长度为64时有一个点的颜色(食物的颜色)跟其它的不一样
				{
					WS2812B_SetBuf(Food,MyColor[(ColorStyle+1)%6*3],MyColor[(ColorStyle+1)%6*3+1],MyColor[(ColorStyle+1)%6*3+2]);
				}
				WS2812B_UpdateDisplay();				
			}
		}

		if(Mode==6)	//如果是显示英文“SCROE”的界面
		{
			if(ExecuteOnceFlag)
			{
				ExecuteOnceFlag=0;
				Offset1=0;
			}
			if(RollFlag)
			{
				if(Offset1<=38)	//只滚动显示一次英文“SCORE”
				{
					RollFlag=0;
					WS2812B_MoveLeft(Table4,8,8,0,Offset1);	//黄色
					WS2812B_UpdateDisplay();
					Offset1++;
				}
				else //滚动结束后,自动切换到循环显示得分的模式
				{
					Mode=7;
					ExecuteOnceFlag=1;
				}	
			}
		}

		if(Mode==7)	//如果是滚动显示得分界面
		{
			if(ExecuteOnceFlag)
			{
				ExecuteOnceFlag=0;
				for(i=0;i<6;i++)	//将得分(即蛇身的长度)的十位和个位的字模写入数组ScoreShow中
				{
					Score[8+i]=Table5[(Length/10)*6+i];
				}
				for(i=0;i<6;i++)
				{
					Score[14+i]=Table5[(Length%10)*6+i];
				}
				Offset1=0;
			}
			if(RollFlag)	//如果滚动的标志为1
			{
				RollFlag=0;
				WS2812B_MoveLeft(Score,8,0,8,Offset1);	//紫色
				WS2812B_UpdateDisplay();
				Offset1++;
				Offset1%=20;	//循环滚动
			}
		}

		if(Mode==8)	//如果是显示作者和编程日期的界面
		{
			if(ExecuteOnceFlag)
			{
				ExecuteOnceFlag=0;
				Offset1=0;
			}
			if(RollFlag)	//如果滚动的标志为1
			{
				RollFlag=0;
				WS2812B_MoveLeft(Table6,0,8,8,Offset1);	//青色
				WS2812B_UpdateDisplay();
				Offset1++;
				Offset1%=170;	//循环滚动
			}
		}

	}
}

void Timer0_Routine() interrupt 1	//定时器0中断函数
{
	TL0=0x80;	//设置定时初值,定时2ms,1T@24.000MHz
	TH0=0x44;	//设置定时初值,定时2ms,1T@24.000MHz
	T0Count1++;
	T0Count2++;
	if(PauseFlag==0){T0Count3++;}	//不暂停时,T0Count3才计数
	else{T0Count3=0;}	//暂停后继续游戏时,T0Count3重新计数
	T0Count4++;
	T0Count5++;
	if(T0Count1>=10)	//每隔20ms检测一次按键
	{
		T0Count1=0;
		Key_Tick();
	}
	if(T0Count2>=50)	//每隔100ms滚动一次
	{
		T0Count2=0;
		RollFlag=1;
	}
	if(T0Count3>=SnakeMoveSpeed/2)	//控制蛇的移动速度
	{
		T0Count3=0;
		MoveFlag=1;
	}
	if(T0Count4>=125)	//每隔250ms改变FlashFlag的值
	{
		T0Count4=0;
		FlashFlag=!FlashFlag;
	}
	if(T0Count5>=3)	//每隔6ms呼吸灯的亮度改变一次
	{
		T0Count5=0;
		BreathFlag=1;
	}
}

总结

用彩色点阵屏玩《贪吃蛇》更有趣了,可以显示不同的颜色,弄出很多花样。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2272304.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【开源】创建自动签到系统—QD框架

1. 介绍 QD是一个 基于 HAR 编辑器和 Tornado 服务端的 HTTP 定时任务自动执行 Web 框架。 主要通过抓包获取到HAR来制作任务模板&#xff0c;从而实现异步响应和发起HTTP请求 2. 需要环境 2.1 硬件需求 CPU&#xff1a;至少1核 内存&#xff1a;推荐 ≥ 1G 硬盘&#xff1a;推…

【区块链】零知识证明基础概念详解

&#x1f308;个人主页: 鑫宝Code &#x1f525;热门专栏: 闲话杂谈&#xff5c; 炫酷HTML | JavaScript基础 ​&#x1f4ab;个人格言: "如无必要&#xff0c;勿增实体" 文章目录 零知识证明基础概念详解引言1. 零知识证明的定义与特性1.1 基本定义1.2 三个核心…

豆包ai 生成动态tree 增、删、改以及上移下移 html+jquery

[豆包ai 生成动态tree 增、删、改以及上移下移 htmljquery) 人工Ai 编程 推荐一Kimi https://kimi.moonshot.cn/ 推荐二 豆包https://www.doubao.com/ 实现效果图 html 代码 <!DOCTYPE html> <html lang"en"><head><meta charset"UTF…

Redis(一)基本特点和常用全局命令

目录 一、Redis 的基本特点 1、速度快&#xff08;但空间有限&#xff09; 2、储存键值对的“非关系型数据库” 3、 功能丰富 4、 支持集群 5、支持持久化 6、主从复制架构 二、Redis 的典型应用场景 1、作为存储热点数据的缓存 2、作为消息队列服务器 3、作为把数据…

SpringMVC(三)请求

目录 一、RequestMapping注解 1.RequestMapping的属性 实例 1.在这里创建文件&#xff0c;命名为Test: 2.复现-返回一个页面&#xff1a; 创建test界面&#xff08;随便写点什么&#xff09;&#xff1a; Test文件中编写&#xff1a; ​编辑 运行&#xff1a; 3.不返回…

K8s集群平滑升级(Smooth Upgrade of K8S Cluster)

简介&#xff1a; Kubernetes ‌ &#xff08;简称K8s&#xff09;是一个开源的容器编排和管理平台&#xff0c;由Google开发并维护。它最初是为了解决谷歌内部大规模容器管理的问题而设计的&#xff0c;后来在2014年开源&#xff0c;成为云原生技术的核心组成部分。‌‌1 K8…

NO.1 《机器学习期末复习篇》以题(问答题)促习(人学习),满满干huo,大胆学大胆补!

目录 一、新手初学&#xff1f;该如何区分[人工智能] [机器学习] [深度学习]&#xff1f; [1]浅谈一下我的理解 [2]深度交流一下 人工智能&#xff08;AI, Artificial Intelligence&#xff09; 机器学习&#xff08;ML, Machine Learning&#xff09; 深度学习&#xff0…

零基础也能建站: 使用 WordPress 和 US Domain Center 轻松五步创建网站 (无需编程)

创建一个网站可能听起来很复杂&#xff0c;但只要使用正确的工具&#xff0c;你可以通过五个简单步骤构建一个专业网站 — — 无需编写任何代码&#xff01;在本教程中&#xff0c;我们将使用 WordPress 和 US Domain Center 指导你完成整个过程。完成后&#xff0c;你将拥有一…

pdf预览 报:Failed to load module script

pdf 预览报&#xff1a; Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of “application/octet-stream”. Strict MIME type checking is enforced for module scripts per HTML spec. 报错原因&#xff1a…

【JVM】总结篇之对象内存布局 执行引擎

文章目录 对象内存布局对象的实例化对象的内存布局对象的方问定位 执行引擎 对象内存布局 对象的实例化 new对象流程&#xff1f;&#xff08;龙湖地产&#xff09; 对象创建方法&#xff0c;对象的内存分配。&#xff08;360安全&#xff09; 1.判断对象对应的类是否加载、链…

力扣hot100——动态规划 多维动态规划

前言&#xff1a;题太多了TAT&#xff0c;只贴了部分我觉得比较好的题 32. 最长有效括号 class Solution { public:int longestValidParentheses(string s) {int n s.size();s " " s;vector<int> dp(n 1, 0);int ans 0;for (int i 2; i < n; i) {if…

leecode1143.最长公共子序列

这道题目和最长重复子数组是一个类型的不同之处在于text1[i]!text2[j]时dp[i][j]时他的值是继承上一行或上一列的最大值&#xff0c;二者dp数组的含义也不一样&#xff0c;这里的dp[i][j]表示的是以text[i]和text2[j]为结尾的子序列最大长度&#xff0c;这也是导致两种问题当判…

Multisim更新:振幅调制器+解调器(含仿真程序+文档+原理图+PCB)

前言 继3年前设计的&#xff1a;Multisim&#xff1a;振幅调制器的设计&#xff08;含仿真程序文档原理图PCB&#xff09;&#xff0c;有读者表示已经不能满足新需求&#xff0c;需要加上新的解调器功能&#x1f602;&#x1f602;&#x1f602;&#xff0c;鸽了很久这里便安排…

计算机网络复习(zcmu考试系统练习题)

温馨提示&#xff0c;Ctrl &#xff0b;F搜索关键词 练习网址&#xff1a;https://xxks.zcmu.edu.cn 术语辨析 数据链路层 该层在两个通信实体之间传送以帧为单位的数据&#xff0c;通过差错控制方法,使有差错的物理线路变成无差错数据链路。 网络层 负责使分组以适当的路径…

计算机网络——期末复习(5)期末考试样例1(含答案)

考试题型&#xff1b; 概念辨析&#xff15;个、计算与分析&#xff13;个、综合题&#xff13;&#xff0d;&#xff14;个 必考知识点&#xff1a; 概述&#xff1a;协议 体系结构 物理层&#xff1b;本次考核较少 链路层&#xff1a;CSMA/CD 退避二进制算法 &#xff0…

「Mac畅玩鸿蒙与硬件51」UI互动应用篇28 - 模拟记账应用

本篇教程将介绍如何创建一个模拟记账应用&#xff0c;通过账单输入、动态列表展示和实时统计功能&#xff0c;学习接口定义和组件间的数据交互。 关键词 UI互动应用接口定义动态列表实时统计数据交互 一、功能说明 模拟记账应用包含以下功能&#xff1a; 账单输入&#xff1…

Vue3 + ElementPlus动态合并数据相同的单元格(超级详细版)

最近的新项目有个需求需要合并单元列表。ElementPlus 的 Table 提供了合并行或列的方法&#xff0c;可以参考一下https://element-plus.org/zh-CN/component/table.html 但项目中&#xff0c;后台数据返回格式和指定合并是动态且没有规律的&#xff0c;Element 的示例过于简单&…

Uniapp Android 本地离线打包(详细流程)

一、简介 App 离线 SDK 暂时不支持 Kotlin&#xff0c;未来不清楚。 uniapp 提供了 云打包 与 本地打包 两种方案&#xff0c;云打包 需要排队且还有次数限制&#xff0c;本地打包 则就没有这些限制&#xff0c;而且会 本地打包 对开发 原生插件 有很大的帮助。 细节&#x…

党员学习交流平台

本文结尾处获取源码。 本文结尾处获取源码。 本文结尾处获取源码。 一、相关技术 后端&#xff1a;Java、JavaWeb / Springboot。前端&#xff1a;Vue、HTML / CSS / Javascript 等。数据库&#xff1a;MySQL 二、相关软件&#xff08;列出的软件其一均可运行&#xff09; I…

Gitee图形界面上传(详细步骤)

目录 1.软件安装 2.安装顺序 3.创建仓库 4.克隆远程仓库到本地电脑 提交代码的三板斧 1.软件安装 Git - Downloads (git-scm.com) Download – TortoiseGit – Windows Shell Interface to Git 2.安装顺序 1. 首先安装git-2.33.1-64-bit.exe&#xff0c;顺序不能搞错2. …