红外线遥控的贪吃蛇基于stm32
单片机源程序如下:
- #include "led.h"
- #include "delay.h"
- #include "key.h"
- #include "sys.h"
- #include "lcd.h"
- #include "usart.h"
- #include "remote.h"
- #include "snake.h"
- int main(void)
- {
- u8 key;
- u8 t=0;
- u8 *str=0;
- delay_init(); //延时函数初始化
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置中断优先级分组为组2:2位抢占优先级,2位响应优先级
- uart_init(115200); //串口初始化为115200
- LED_Init(); //LED端口初始化
- LCD_Init();
- KEY_Init();
- Remote_Init(); //红外接收初始化
-
- POINT_COLOR=RED; //设置字体为红色
- LCD_ShowString(30,50,200,16,16,"SNAKE_LJ");
- LCD_ShowString(30,130,200,16,16,"KEYVAL:");
- while(Remote_Scan()==2);//等待开始
- LCD_Clear(BLACK);
- Init_SNAKE(); //贪吃蛇初始化
- while(1)
- {
- /*
- key=Remote_Scan();
- if(key)
- {
- LCD_ShowNum(86,130,key,3,16); //显示键值
- switch(key)
- {
- case 98:str="UP";break;
- case 194:str="RIGHT";break;
- case 34:str="LEFT";break;
- case 168:str="DOWN";break;
- }
- LCD_Fill(86,170,116+8*8,170+16,WHITE); //清楚之前的显示
-
- }else delay_ms(10);
- t++;
- if(t==20)
- {
- t=0;
- LED0=!LED0;
- }
- */
- Run_SNAKE();
- Key_Value=Remote_Scan();//键扫描
- }
- }
复制代码
所有资料51hei提供下载:
贪吃蛇.rar
(333.49 KB, 下载次数: 21)
|