main.c
上传用户:zfj3589
上传日期:2022-07-13
资源大小:635k
文件大小:20k
- /****************************************Copyright (c)**************************************************
- ** Guangzou ZLG-MCU Development Co.,LTD.
- ** graduate school
- ** http://www.zlgmcu.com
- **
- **--------------File Info-------------------------------------------------------------------------------
- ** File name: main.c
- ** Last modified Date: 2004-09-16
- ** Last Version: 1.0
- ** Descriptions: The main() function example template
- **
- **------------------------------------------------------------------------------------------------------
- ** Created by: Chenmingji
- ** Created date: 2004-09-16
- ** Version: 1.0
- ** Descriptions: The original version
- **
- **------------------------------------------------------------------------------------------------------
- ** Modified by:
- ** Modified date:
- ** Version:
- ** Descriptions:
- **
- ********************************************************************************************************/
- #include "config.h"
- #include "stdlib.h"
- #include <math.h>
- #define LEFT 1
- #define RIGHT 2
- #define DOWN 3
- #define UP 4
- #define ESC 5
- #define N 30
- #define LED1 (1<<22) //灯的定义
- #define LED2 (1<<29)
- #define LED3 (1<<30)
- #define KEY_UP (1<<24) //按键的定义
- #define KEY_DOWN (1<<28)
- #define KEY_LIFT (1<<23)
- #define KEY_RIGHT (1<<25)
- #define TaskStkLengh 130 //Define the Task0 stack length 定义用户任务0的堆栈长度
- #define TASK_STK_SIZE 100
- OS_STK TaskStk[TaskStkLengh]; //Define the Task0 stack 定义用户任务0的堆栈
- OS_STK TaskLed1Stk[TASK_STK_SIZE];
- OS_STK TaskLed2Stk[TASK_STK_SIZE];
- OS_STK TaskLed3Stk[TASK_STK_SIZE];
- void Task0(void *pdata); //Task0 任务0
- static void TaskLed1(void *data);
- static void TaskLed2(void *data);
- static void TaskLed3(void *data);
- void PrintScore(uint32 x, uint32 y, uint32 data);
- void DrawBeanSnake(uint32 x, uint32 y);
- void ClearSnake(uint32 x, uint32 y);
- void IniGamePicture(void);
- void GameOver(void);
- void GamePlay(void);
- /* @tan 贪(16x16,V)@ [suki software]*/
- uint8 const tan0[]=
- {
- 0x01,0x00,0x02,0x80,0x04,0x40,0x0A,0x30,0x31,0x0E,0xCF,0xE4,0x00,0x40,0x1F,0xF0,
- 0x10,0x10,0x11,0x10,0x11,0x10,0x11,0x10,0x12,0x90,0x04,0x60,0x08,0x30,0x30,0x10,
- };
- uint8 const chi0[]=
- {
- /* @chi0 吃(16x16,V)@ [suki software]*/
- 0x01,0x00,0x01,0x80,0x79,0x00,0x4B,0xFE,0x4A,0x00,0x4C,0x00,0x4B,0xF0,0x48,0x10,
- 0x48,0x20,0x78,0x40,0x48,0x80,0x41,0x00,0x02,0x02,0x02,0x02,0x01,0xFE,0x00,0x00,
- };
- uint8 const she0[]=
- {
- /* @she0 蛇(16x16,V)@ [suki software]*/
- 0x10,0x40,0x10,0x30,0x10,0x20,0x11,0xFE,0x7D,0x04,0x56,0x88,0x54,0x80,0x54,0x88,
- 0x7C,0xB0,0x54,0xC0,0x10,0x80,0x14,0x84,0x1E,0x84,0xE4,0x84,0x00,0x78,0x00,0x00,
- };
- /* @you0 游(16x16,V)@ [suki software]*/
- unsigned char you0[]={
- 0x44,0x20,0x22,0x20,0x22,0x20,0x0F,0xBE,0x84,0x40,0x54,0xBC,0x57,0x08,0x25,0x10,
- 0x25,0x10,0x25,0x7E,0xC5,0x10,0x49,0x10,0x49,0x10,0x49,0x10,0x55,0x50,0x42,0x20
- };
- /* @xi0 戏(16x16,V)@ [suki software]*/
- unsigned char xi0[]={
- 0x00,0x40,0x00,0x50,0x7E,0x48,0x02,0x48,0x44,0x40,0x25,0xFE,0x18,0x40,0x08,0x44,
- 0x0C,0x28,0x14,0x30,0x12,0x20,0x22,0x50,0x41,0x92,0x06,0x0A,0x00,0x06,0x00,0x02
- };
- /* @jie0 结(16x16,V)@ [suki software]*/
- unsigned char jie0[]={
- 0x10,0x20,0x10,0x20,0x20,0x20,0x23,0xFE,0x48,0x20,0xF0,0x20,0x11,0xFC,0x20,0x00,
- 0x40,0x00,0xF9,0xFC,0x01,0x04,0x01,0x04,0x19,0x04,0xE1,0xFC,0x01,0x04,0x00,0x00,
- };
- /* @shu0 束(16x16,V)@ [suki software]*/
- unsigned char shu0[]={
- 0x01,0x00,0x01,0x00,0xFF,0xFE,0x01,0x00,0x3F,0xF8,0x21,0x08,0x21,0x08,0x3F,0xF8,
- 0x23,0x08,0x05,0x80,0x05,0x40,0x09,0x30,0x31,0x0E,0xC1,0x04,0x01,0x00,0x01,0x00,
- };
- /* @tui0 退(16x16,V)@ [suki software]*/
- unsigned char tui0[]={
- 0x40,0x00,0x27,0xF0,0x24,0x10,0x07,0xF0,0x04,0x10,0x04,0x10,0xE7,0xF0,0x24,0x88,
- 0x24,0x50,0x24,0x20,0x25,0x10,0x26,0x18,0x24,0x08,0x50,0x00,0x8F,0xFE,0x00,0x00,
- };
- /* @chu0 出(16x16,V)@ [suki software]*/
- unsigned char chu0[]={
- 0x01,0x00,0x01,0x00,0x21,0x04,0x21,0x04,0x21,0x04,0x21,0x04,0x3F,0xFC,0x21,0x04,
- 0x01,0x00,0x21,0x04,0x21,0x04,0x21,0x04,0x21,0x04,0x3F,0xFC,0x20,0x04,0x00,0x00,
- };
- /* @kai0 开(16x16,V)@ [suki software]*/
- unsigned char kai0[]={
- 0x00,0x00,0x7F,0xFE,0x04,0x20,0x04,0x20,0x04,0x20,0x04,0x20,0xFF,0xFE,0x04,0x20,
- 0x04,0x20,0x04,0x20,0x08,0x20,0x08,0x20,0x10,0x20,0x20,0x20,0x40,0x20,0x00,0x00,
- };
- /* @shi0 始(16x16,V)@ [suki software]*/
- unsigned char shi3[]={
- 0x10,0x20,0x18,0x30,0x10,0x20,0x10,0x48,0xFC,0x84,0x25,0xFE,0x24,0x84,0x44,0x00,
- 0x44,0xFC,0x28,0x84,0x18,0x84,0x14,0x84,0x22,0x84,0x42,0xFC,0x80,0x84,0x00,0x00,
- };
- /* @de0 得(16x16,V)@ [suki software]*/
- unsigned char de0[]={
- 0x13,0xF8,0x1A,0x08,0x23,0xF8,0x4A,0x08,0x8B,0xF8,0x10,0x00,0x13,0xFE,0x30,0x10,
- 0x50,0x10,0x97,0xFE,0x10,0x10,0x11,0x10,0x11,0x10,0x11,0x10,0x10,0x50,0x10,0x20,
- };
- /* @fen0 分(16x16,V)@ [suki software]*/
- unsigned char fen0[]={
- 0x08,0x80,0x0C,0x80,0x08,0x40,0x10,0x20,0x10,0x30,0x20,0x18,0x40,0x0E,0x9F,0xE4,
- 0x04,0x20,0x04,0x20,0x04,0x20,0x04,0x20,0x08,0x20,0x10,0xA0,0x20,0x40,0x40,0x00,
- };
- /* @she0 设(16x16,V)@ [suki software]*/
- unsigned char she4[]={
- 0x40,0x00,0x21,0xF0,0x31,0x10,0x21,0x10,0x01,0x10,0x01,0x10,0xE2,0x0E,0x25,0xF8,
- 0x21,0x08,0x21,0x08,0x20,0x90,0x20,0x90,0x28,0x60,0x30,0x90,0x23,0x0E,0x0C,0x04,
- };
- /* @ji0 计(16x16,V)@ [suki software]*/
- unsigned char ji0[]={
- 0x40,0x20,0x20,0x20,0x30,0x20,0x20,0x20,0x00,0x20,0xF3,0xFE,0x10,0x20,0x10,0x20,
- 0x10,0x20,0x10,0x20,0x10,0x20,0x12,0x20,0x14,0x20,0x18,0x20,0x10,0x20,0x00,0x20,
- };
- /* @zhe0 者(16x16,V)@ [suki software]*/
- unsigned char zhe0[]={
- 0x01,0x00,0x01,0x08,0x3F,0xEC,0x01,0x10,0x01,0x20,0x7F,0xFE,0x00,0x80,0x03,0x00,
- 0x07,0xF8,0x1C,0x08,0xE4,0x08,0x07,0xF8,0x04,0x08,0x04,0x08,0x07,0xF8,0x04,0x08,
- };
- /* @zhou0 周(16x16,V)@ [suki software]*/
- unsigned char zhou0[]={
- 0x00,0x00,0x1F,0xFC,0x10,0x84,0x13,0xE4,0x10,0x84,0x10,0x84,0x17,0xF4,0x10,0x04,
- 0x13,0xE4,0x12,0x24,0x12,0x24,0x13,0xE4,0x22,0x24,0x20,0x04,0x40,0x14,0x80,0x08,
- };
- /* @yi0 义(16x16,V)@ [suki software]*/
- unsigned char yi0[]={
- 0x00,0x00,0x04,0x20,0x22,0x30,0x21,0x20,0x11,0x20,0x10,0x40,0x08,0x40,0x04,0x80,
- 0x02,0x80,0x01,0x00,0x02,0x80,0x04,0x40,0x08,0x30,0x30,0x0E,0xC0,0x04,0x00,0x00,
- };
- /* @huang0 黄(16x16,V)@ [suki software]*/
- unsigned char huang0[]={
- 0x04,0x40,0x04,0x40,0x7F,0xFC,0x04,0x40,0x04,0x40,0xFF,0xFE,0x01,0x00,0x1F,0xF0,
- 0x11,0x10,0x1F,0xF0,0x11,0x10,0x11,0x10,0x1F,0xF0,0x08,0x20,0x10,0x18,0x60,0x08,
- };
- /* @shi0 石(16x16,V)@ [suki software]*/
- unsigned char shi0[]={
- 0x00,0x00,0xFF,0xFE,0x02,0x00,0x02,0x00,0x04,0x00,0x04,0x00,0x07,0xF8,0x0C,0x08,
- 0x0C,0x08,0x14,0x08,0x24,0x08,0x44,0x08,0x84,0x08,0x07,0xF8,0x04,0x08,0x00,0x00,
- };
- /* @li0 理(16x16,V)@ [suki software]*/
- unsigned char li0[]={
- 0x00,0x00,0x03,0xFC,0xFA,0x44,0x22,0x44,0x23,0xFC,0x22,0x44,0xFA,0x44,0x23,0xFC,
- 0x22,0x44,0x20,0x40,0x23,0xFC,0x38,0x40,0xC0,0x40,0x00,0x40,0x0F,0xFE,0x00,0x00,
- };
- /* @gong0 工(16x16,V)@ [suki software]*/
- unsigned char gong0[]={
- 0x00,0x00,0x3F,0xFC,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,
- 0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0xFF,0xFE,0x00,0x00,0x00,0x00,
- };
- /* @xue0 学(16x16,V)@ [suki software]*/
- unsigned char xue0[]={
- 0x01,0x08,0x10,0x8C,0x0C,0xC8,0x08,0x90,0x7F,0xFE,0x40,0x04,0x8F,0xE8,0x00,0x40,
- 0x00,0x80,0x7F,0xFE,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x02,0x80,0x01,0x00,
- };
- /* @yuan0 院(16x16,V)@ [suki software]*/
- unsigned char yuan0[]={
- 0x00,0x80,0xF8,0x40,0x8F,0xFE,0x94,0x04,0xA0,0x00,0xA3,0xF8,0x90,0x00,0x88,0x00,
- 0x8F,0xFE,0xA9,0x20,0x91,0x20,0x81,0x20,0x82,0x22,0x82,0x22,0x84,0x22,0x88,0x1E,
- };
- unsigned char BeanLocate[][2]={{3,2},
- };
- struct Snake
- {
- uint32 x[N];
- uint32 y[N];
- uint32 node;
- uint32 direction;
- uint32 life;
- }snake;
- struct Food
- {
- uint32 x;
- uint32 y;
- uint32 yes;
- }food;
- typedef struct
- {
- uint32 Message;
- uint32 WParam;
- uint32 LParam;
- }OSMSG,*POSMSG;
-
- uint32 GameSpeed = 10;
- uint32 score = 0 ;
- /****************************************************************************
- * 名称:DrawBeanSnake()
- * 功能:贪吃蛇专用,蛇和屏幕的位置坐标范围为(0,0)到(110/5=21,60/5=11)
- * 画蛇和豆子
- * 入口参数:x 蛇的x坐标值
- * y 蛇的y坐标值
- * 出口参数:无
- * 说明:操作失败原因是指定地址超出有效范围。
- ****************************************************************************/
- void DrawBeanSnake(uint32 x, uint32 y)
- {
- uint32 x0, y0, x1, y1;
- x0=x*6+1; //偏移一个1为偏移的边框线,乘5是一个蛇节象素的大小
- y0=y*6+1;
- x1=x*6+6;
- y1=y*6+6;
- GUI_HLine(x0, y0, x1, 1);
- GUI_HLine(x0, y1, x1, 1);
- GUI_RLine(x0, y0, y1, 1);
- GUI_RLine(x1, y0, y1, 1);
- }
- /****************************************************************************
- * 名称:ClearSnake()
- * 功能:贪吃蛇专用 蛇和屏幕的位置坐标范围为(0,0)到(110/5-21/5=17,60/5-11/5=9)
- * 清除蛇的尾部
- * 入口参数:x 蛇的x坐标值
- * y 蛇的y坐标值
- *
- * 出口参数:无
- * 说明:
- ****************************************************************************/
- void ClearSnake(uint32 x, uint32 y)
- {
- uint32 x0, y0, x1, y1;
- x0=x*6+1; //偏移一个1为偏移的边框线,乘5是一个蛇节象素的大小
- y0=y*6+1;
- x1=x*6+6;
- y1=y*6+6;
- GUI_HLine(x0, y0, x1-1, 0); //减1为防止把前面蛇的一个边框点给清掉
- GUI_HLine(x0, y1, x1-1, 0);
- GUI_RLine(x0, y0, y1, 0);
- GUI_RLine(x1, y0, y1, 0);
- }
- /****************************************************************************
- * 名称:GameOvere()
- * 功能:游戏结束时清屏,并显示"游戏结束"
- *
- * 入口参数:无
- * 出口参数:无
- * 说明:无
- ****************************************************************************/
- void GameOver(void)
- {
- GUI_FillSCR(0x00);
- GUI_PutHZ(32, 25, (uint8 *)you0, 16, 16); //中间显示"游戏结束"
- GUI_PutHZ(32+16, 25, (uint8 *)xi0, 16, 16);
- GUI_PutHZ(32+16+16, 25, (uint8 *)jie0, 16, 16);
- GUI_PutHZ(32+16+16+16, 25, (uint8 *)shu0, 16, 16);
- }
- /****************************************************************************
- * 名称:PrintScore()
- * 功能:在坐标(x,y)的屏幕上显示一个数
- *
- * 入口参数:x 数的x坐标值
- * y 数的y坐标值
- * data 要显示的数
- * 出口参数:无
- * 说明:数的大小不能超过100
- ****************************************************************************/
- void PrintScore(uint32 x, uint32 y, uint32 data)
- {
- uint32 i,j,x0,y0;
- x0=x;
- y0=y;
- i=data/10;
- j=data%10;
- switch(i)
- {
- //case 0:GUI_PutChar8_8(125-12, 54, '0');break;
- case 0:GUI_PutChar8_8(x0, y0, '0');break;
- case 1:GUI_PutChar8_8(x0, y0, '1');break;
- case 2:GUI_PutChar8_8(x0, y0, '2');break;
- case 3:GUI_PutChar8_8(x0, y0, '3');break;
- case 4:GUI_PutChar8_8(x0, y0, '4');break;
- case 5:GUI_PutChar8_8(x0, y0, '5');break;
- case 6:GUI_PutChar8_8(x0, y0, '6');break;
- case 7:GUI_PutChar8_8(x0, y0, '7');break;
- case 8:GUI_PutChar8_8(x0, y0, '8');break;
- case 9:GUI_PutChar8_8(x0, y0, '9');break;
- }
- switch(j)
- {
- //case 0:GUI_PutChar8_8(125-5, 54, '0');break;
- case 0:GUI_PutChar8_8(x0+8, y0, '0');break;
- case 1:GUI_PutChar8_8(x0+8, y0, '1');break;
- case 2:GUI_PutChar8_8(x0+8, y0, '2');break;
- case 3:GUI_PutChar8_8(x0+8, y0, '3');break;
- case 4:GUI_PutChar8_8(x0+8, y0, '4');break;
- case 5:GUI_PutChar8_8(x0+8, y0, '5');break;
- case 6:GUI_PutChar8_8(x0+8, y0, '6');break;
- case 7:GUI_PutChar8_8(x0+8, y0, '7');break;
- case 8:GUI_PutChar8_8(x0+8, y0, '8');break;
- case 9:GUI_PutChar8_8(x0+8, y0, '9');break;
- }
-
-
- }
-
- void GamePlay(void)
- {
- uint32 i;
- snake.life=0;
- snake.direction=1;
- snake.x[0]=0;snake.y[0]=6; //蛇头
- snake.x[1]=1;snake.y[1]=6;
- snake.node=2; //节数
- food.x=7;
- food.y=6;
- DrawBeanSnake(food.x,food.y);
- food.yes=1;
- PrintScore(112,54,score);
- while(1)
- {
- if(food.yes==0)
- {
- food.x=food.x+3;
- food.y++;
- if(food.x>17)
- food.x=0;
- if(food.y>9)
- food.y=0;
- DrawBeanSnake(food.x,food.y);
- food.yes=1;
- }
- if(food.yes==1)//避免豆子显示在蛇身上而使豆子被清掉
- {
- DrawBeanSnake(food.x,food.y);
- }
- for(i=snake.node-1;i>0;i--)
- {
- snake.x[i]=snake.x[i-1];
- snake.y[i]=snake.y[i-1];
- }
- switch(snake.direction)
- {
- case 1:snake.x[0]+=1;break;
- case 2:snake.x[0]-=1;break;
- case 3:snake.y[0]-=1;break;
- case 4:snake.y[0]+=1;break;
- }
- for(i=3;i<snake.node;i++) //从蛇的第四节开始判断是否撞到自己,因为蛇头为两节,第三节不可能拐过来
- {
- if(snake.x[i]==snake.x[0]&&snake.y[i]==snake.y[0])
- {
- GameOver();
- snake.life=1;
- break;
- }
- }
- if(snake.x[0]>17||snake.y[0]>9) //判断蛇是否撞到墙
- {
- GameOver();
- snake.life=1;
- }
- if(snake.life==1) //如果蛇死就跳出循环,重新开始
- break;
- for(i=0;i<snake.node;i++) //画蛇
- DrawBeanSnake(snake.x[i], snake.y[i]);
- OSTimeDly(GameSpeed);
- if(snake.x[0]==food.x&&snake.y[0]==food.y) //吃到食物后
- {
- food.yes=0;
- snake.node++;
- score+=1;
- PrintScore(112,54,score);
- }
- ClearSnake(snake.x[snake.node-1], snake.y[snake.node-1]); //清除蛇的最后一节
- /*if(key==ESC)
- break;
- else if(key==UP&&snake.direction!=4) //判断是否往相反的方向移动
- snake.direction=3;
- else if(key==RIGHT&&snake.direction!=2)
- snake.direction=1;
- else if(key==LIFT&&snake.direction!=1)
- snake.direction=2;
- else if(key==DOWN&&snake.direction!=3)
- snake.direction=4;*/
- }//END while
- }
- /****************************************************************************
- * 名称:IniPicture()
- * 功能:游戏开始时屏幕的边框初始化
- *
- * 入口参数:无
- * 出口参数:无
- * 说明:无
- ****************************************************************************/
- void IniGamePicture(void)
- {
- GUI_Initialize();
- GUI_PutHZ(125-12, 0, (uint8 *)tan0, 16, 16); //边上显示"贪吃蛇"
- GUI_PutHZ(125-12, 16, (uint8 *)chi0, 16, 16);
- GUI_PutHZ(125-12, 32, (uint8 *)she0, 16, 16);
- GUI_Rectangle(0,0,125-13,63,2); //画边界框
- DrawBeanSnake(0,6);
- DrawBeanSnake(1,6);
- }
- /****************************************************************************
- * 名称:IniDesignInformation()
- * 功能: 显示设计者信息
- *
- * 入口参数:无
- * 出口参数:无
- * 说明:无
- ****************************************************************************/
- void IniDesignInformation(void)
- {
- uint32 i=1;
- GUI_PutHZ(i*18, 0, (uint8 *)huang0,16, 16); //黄石理工学院 设计者 周义
- i++;
- GUI_PutHZ(i*18, 0, (uint8 *)shi0, 16, 16);
- i++;
- GUI_PutHZ(i*18, 0, (uint8 *)li0, 16, 16);
- i++;
- GUI_PutHZ(i*18, 0, (uint8 *)gong0, 16, 16);
- i++;
- GUI_PutHZ(i*18, 0, (uint8 *)xue0, 16, 16);
- i++;
- GUI_PutHZ(i*18, 0, (uint8 *)yuan0, 16, 16);
-
- i=2;
- GUI_PutHZ(i*18, 18, (uint8 *)she4, 16, 16);
- i++;
- GUI_PutHZ(i*18, 18, (uint8 *)ji0, 16, 16);
- i++;
- GUI_PutHZ(i*18, 18, (uint8 *)zhe0, 16, 16);
-
- i=3;
- GUI_PutHZ(i*18, 36, (uint8 *)zhou0, 16, 16);
- i++;
- GUI_PutHZ(i*18, 36, (uint8 *)yi0, 16, 16);
- OSTimeDlyHMSM(0,0,0,50);
- }
- /****************************************************************************
- * 名称:GUI_PutHZ_Gai()
- * 功能: GUI_PutHZ修改版,坐标(0,0)到(8,4)
- *
- * 入口参数:x
- * y
- * dat
- * 出口参数:无
- * 说明:无
- ****************************************************************************/
- void GUI_PutHZ_Gai(uint32 x, uint32 y, uint8 *dat)
- {
- //GUI_PutHZ(x*16, y*16, *dat, 16, 16);
- }
- /****************************************************************************
- * 名称:LedInit()
- * 功能: Led口的输入输出定义
- *
- * 入口参数:无
- * 出口参数:无
- * 说明:无
- ****************************************************************************/
- void LedInit(void)
- {
- PINSEL0=0x00000000;
- PINSEL1=0x00000000;
- IODIR=0xffffffff;
- IOSET=LED1;
- IOSET=LED2;
- IOSET=LED3;
- }
- /****************************************************************************
- * 名称:LedInit()
- * 功能: Led口的输入输出定义
- *
- * 入口参数:无
- * 出口参数:无
- * 说明:无
- ****************************************************************************/
- void KeyInit(void)
- {
- PINSEL0=0x00000000;
- PINSEL1=0x00000000;
- IODIR =0xe83fffff;
- }
- /****************************************************************************
- * 名称: main()
- * 功能: 初始化uC/OS-II操作系统,建立第一个任务,然后启动系统。
- ****************************************************************************/
- int main(void)
- {
- OSInit ();
- OSTaskCreate(Task0, (void *)0, &TaskStk[TaskStkLengh - 1], 10);
- OSTaskCreate(TaskLed1, (void *)0, &TaskLed1Stk[TASK_STK_SIZE - 1], 30);
- OSTaskCreate(TaskLed2, (void *)0, &TaskLed2Stk[TASK_STK_SIZE - 1], 35);
- OSTaskCreate(TaskLed3, (void *)0, &TaskLed3Stk[TASK_STK_SIZE - 1], 31);
- OSStart ();
- return 0;
- }
- /*********************************************************************************************************
- ** Task0 任务0
- ** 功能:主任务,游戏的显示任务
- ********************************************************************************************************/
- void Task0(void *pdata)
- {
-
- pdata = pdata;
- TargetInit ();
- LedInit();
- GUI_Initialize(); // 初始化LCM
- GUI_SetColor(1, 0); // 设置前景色和背景色
- OSTimeDly(10);
- IniDesignInformation();
- OSTimeDly(10);
- IniGamePicture();
- GamePlay();
-
- while (1)
- {
- OSTimeDly(10);
- }
- }
- /*********************************************************************************************************
- ** TaskLed1 任务1
- ** 功能:LED闪烁任务,显示操作系统的运行状况
- ********************************************************************************************************/
- void TaskLed1(void *pdata)
- {
-
- pdata=pdata;
- TargetInit();
- LedInit();
- while(1)
- {
- IOSET=LED2;
- OSTimeDlyHMSM(0,0,0,50);
- IOCLR=LED2;
- //OSTaskSuspend(5);
- OSTimeDlyHMSM(0,0,0,50);
- }
- while(1);
- }
- /*********************************************************************************************************
- ** TaskLed2 任务2
- ** 功能:键盘扫描任务
- ********************************************************************************************************/
- void TaskLed2(void *pdata)
- {
- //POSMSG pMsg;
- pdata=pdata;
- TargetInit();
- KeyInit();
- while(1)
- {
- if((IO0PIN&KEY_UP)==0)
- {
- OSTimeDlyHMSM(0,0,0,5);
- if((IO0PIN&KEY_UP)==0)
- {
- snake.direction=3;
- IOSET=LED2;
- while((IO0PIN&KEY_UP)==0);
- }
- }
- if((IO0PIN&KEY_DOWN)==0)
- {
- OSTimeDlyHMSM(0,0,0,5);
- if((IO0PIN&KEY_DOWN)==0)
- {
- snake.direction=4;
- IOCLR=LED2;
- while((IO0PIN&KEY_DOWN)==0);
- }
- }
- if((IO0PIN&KEY_LIFT)==0)
- {
- OSTimeDlyHMSM(0,0,0,5);
- if((IO0PIN&KEY_LIFT)==0)
- {
- snake.direction=2;
- while((IO0PIN&KEY_LIFT)==0);
- }
- }
- if((IO0PIN&KEY_RIGHT)==0)
- {
- OSTimeDlyHMSM(0,0,0,5);
- if((IO0PIN&KEY_RIGHT)==0)
- {
- snake.direction=1;
- while((IO0PIN&KEY_RIGHT)==0);
- }
- }
- //pMsg=OSCreateMessage(0,(snake.direction+1),snake.direction>>16);
- //if(pMsg)
- // SendMessage(pMsg);
- OSTimeDlyHMSM(0,0,0,5);
- }//end while
-
- while(1);
- }
- /*********************************************************************************************************
- ** TaskLed3 任务3
- ** 功能:LED闪烁任务,显示操作系统的运行状况
- ********************************************************************************************************/
- void TaskLed3(void *pdata)
- {
- //uint8 txmsg;
- uint32 j;
- //txmsg = 'A';
- pdata=pdata;
- TargetInit();
- LedInit();
- while(1)
- {
-
- for(j=0;j<=2;j++)
- {
- IOSET=LED3;
- OSTimeDlyHMSM(0,0,0,50);
- IOCLR=LED3;
- OSTimeDlyHMSM(0,0,0,50);
- }
- //OSMboxPost(TxMbox,(void *)&txmsg);
- }
- while(1);
- }
- /*********************************************************************************************************
- ** End Of File
- ********************************************************************************************************/