main.c
上传用户:zfj3589
上传日期:2022-07-13
资源大小:635k
文件大小:20k
源码类别:

微处理器开发

开发平台:

C/C++

  1. /****************************************Copyright (c)**************************************************
  2. **                               Guangzou ZLG-MCU Development Co.,LTD.
  3. **                                      graduate school
  4. **                                 http://www.zlgmcu.com
  5. **
  6. **--------------File Info-------------------------------------------------------------------------------
  7. ** File name: main.c
  8. ** Last modified Date:  2004-09-16
  9. ** Last Version: 1.0
  10. ** Descriptions: The main() function example template
  11. **
  12. **------------------------------------------------------------------------------------------------------
  13. ** Created by: Chenmingji
  14. ** Created date: 2004-09-16
  15. ** Version: 1.0
  16. ** Descriptions: The original version
  17. **
  18. **------------------------------------------------------------------------------------------------------
  19. ** Modified by:
  20. ** Modified date:
  21. ** Version:
  22. ** Descriptions:
  23. **
  24. ********************************************************************************************************/
  25. #include "config.h"
  26. #include "stdlib.h"
  27. #include <math.h>
  28. #define   LEFT   1
  29. #define   RIGHT  2
  30. #define   DOWN   3
  31. #define   UP     4
  32. #define   ESC    5
  33. #define   N  30
  34. #define LED1      (1<<22) //灯的定义
  35. #define LED2      (1<<29)
  36. #define LED3      (1<<30)
  37. #define KEY_UP      (1<<24) //按键的定义
  38. #define KEY_DOWN    (1<<28)
  39. #define KEY_LIFT    (1<<23)
  40. #define KEY_RIGHT   (1<<25)
  41. #define TaskStkLengh 130 //Define the Task0 stack length 定义用户任务0的堆栈长度
  42. #define  TASK_STK_SIZE  100
  43. OS_STK TaskStk[TaskStkLengh]; //Define the Task0 stack 定义用户任务0的堆栈
  44. OS_STK  TaskLed1Stk[TASK_STK_SIZE];
  45. OS_STK  TaskLed2Stk[TASK_STK_SIZE];
  46. OS_STK  TaskLed3Stk[TASK_STK_SIZE];
  47. void  Task0(void *pdata); //Task0 任务0
  48. static void  TaskLed1(void *data);
  49. static void  TaskLed2(void *data);
  50. static void  TaskLed3(void *data);
  51. void    PrintScore(uint32 x, uint32 y, uint32 data);
  52. void   DrawBeanSnake(uint32 x, uint32 y);
  53. void    ClearSnake(uint32 x, uint32 y);
  54. void  IniGamePicture(void);
  55. void  GameOver(void);
  56. void  GamePlay(void);
  57. /* @tan 贪(16x16,V)@ [suki software]*/
  58. uint8 const tan0[]=
  59. {
  60. 0x01,0x00,0x02,0x80,0x04,0x40,0x0A,0x30,0x31,0x0E,0xCF,0xE4,0x00,0x40,0x1F,0xF0,
  61. 0x10,0x10,0x11,0x10,0x11,0x10,0x11,0x10,0x12,0x90,0x04,0x60,0x08,0x30,0x30,0x10,
  62. };
  63. uint8 const chi0[]=
  64. {
  65. /* @chi0 吃(16x16,V)@ [suki software]*/
  66. 0x01,0x00,0x01,0x80,0x79,0x00,0x4B,0xFE,0x4A,0x00,0x4C,0x00,0x4B,0xF0,0x48,0x10,
  67. 0x48,0x20,0x78,0x40,0x48,0x80,0x41,0x00,0x02,0x02,0x02,0x02,0x01,0xFE,0x00,0x00,
  68. };
  69. uint8 const she0[]=
  70. {
  71. /* @she0 蛇(16x16,V)@ [suki software]*/
  72. 0x10,0x40,0x10,0x30,0x10,0x20,0x11,0xFE,0x7D,0x04,0x56,0x88,0x54,0x80,0x54,0x88,
  73. 0x7C,0xB0,0x54,0xC0,0x10,0x80,0x14,0x84,0x1E,0x84,0xE4,0x84,0x00,0x78,0x00,0x00, 
  74. };
  75. /* @you0 游(16x16,V)@ [suki software]*/
  76. unsigned char you0[]={
  77. 0x44,0x20,0x22,0x20,0x22,0x20,0x0F,0xBE,0x84,0x40,0x54,0xBC,0x57,0x08,0x25,0x10,
  78. 0x25,0x10,0x25,0x7E,0xC5,0x10,0x49,0x10,0x49,0x10,0x49,0x10,0x55,0x50,0x42,0x20
  79. };
  80. /* @xi0 戏(16x16,V)@ [suki software]*/
  81. unsigned char xi0[]={
  82. 0x00,0x40,0x00,0x50,0x7E,0x48,0x02,0x48,0x44,0x40,0x25,0xFE,0x18,0x40,0x08,0x44,
  83. 0x0C,0x28,0x14,0x30,0x12,0x20,0x22,0x50,0x41,0x92,0x06,0x0A,0x00,0x06,0x00,0x02
  84. };
  85. /* @jie0 结(16x16,V)@ [suki software]*/
  86. unsigned char jie0[]={
  87. 0x10,0x20,0x10,0x20,0x20,0x20,0x23,0xFE,0x48,0x20,0xF0,0x20,0x11,0xFC,0x20,0x00,
  88. 0x40,0x00,0xF9,0xFC,0x01,0x04,0x01,0x04,0x19,0x04,0xE1,0xFC,0x01,0x04,0x00,0x00,
  89. };
  90. /* @shu0 束(16x16,V)@ [suki software]*/
  91. unsigned char shu0[]={
  92. 0x01,0x00,0x01,0x00,0xFF,0xFE,0x01,0x00,0x3F,0xF8,0x21,0x08,0x21,0x08,0x3F,0xF8,
  93. 0x23,0x08,0x05,0x80,0x05,0x40,0x09,0x30,0x31,0x0E,0xC1,0x04,0x01,0x00,0x01,0x00,
  94. };
  95. /* @tui0 退(16x16,V)@ [suki software]*/
  96. unsigned char tui0[]={
  97. 0x40,0x00,0x27,0xF0,0x24,0x10,0x07,0xF0,0x04,0x10,0x04,0x10,0xE7,0xF0,0x24,0x88,
  98. 0x24,0x50,0x24,0x20,0x25,0x10,0x26,0x18,0x24,0x08,0x50,0x00,0x8F,0xFE,0x00,0x00,
  99. };
  100. /* @chu0 出(16x16,V)@ [suki software]*/
  101. unsigned char chu0[]={
  102. 0x01,0x00,0x01,0x00,0x21,0x04,0x21,0x04,0x21,0x04,0x21,0x04,0x3F,0xFC,0x21,0x04,
  103. 0x01,0x00,0x21,0x04,0x21,0x04,0x21,0x04,0x21,0x04,0x3F,0xFC,0x20,0x04,0x00,0x00,
  104. };
  105. /* @kai0 开(16x16,V)@ [suki software]*/
  106. unsigned char kai0[]={
  107. 0x00,0x00,0x7F,0xFE,0x04,0x20,0x04,0x20,0x04,0x20,0x04,0x20,0xFF,0xFE,0x04,0x20,
  108. 0x04,0x20,0x04,0x20,0x08,0x20,0x08,0x20,0x10,0x20,0x20,0x20,0x40,0x20,0x00,0x00,
  109. };
  110. /* @shi0 始(16x16,V)@ [suki software]*/
  111. unsigned char shi3[]={
  112. 0x10,0x20,0x18,0x30,0x10,0x20,0x10,0x48,0xFC,0x84,0x25,0xFE,0x24,0x84,0x44,0x00,
  113. 0x44,0xFC,0x28,0x84,0x18,0x84,0x14,0x84,0x22,0x84,0x42,0xFC,0x80,0x84,0x00,0x00,
  114. };
  115. /* @de0 得(16x16,V)@ [suki software]*/
  116. unsigned char de0[]={
  117. 0x13,0xF8,0x1A,0x08,0x23,0xF8,0x4A,0x08,0x8B,0xF8,0x10,0x00,0x13,0xFE,0x30,0x10,
  118. 0x50,0x10,0x97,0xFE,0x10,0x10,0x11,0x10,0x11,0x10,0x11,0x10,0x10,0x50,0x10,0x20,
  119. };
  120. /* @fen0 分(16x16,V)@ [suki software]*/
  121. unsigned char fen0[]={
  122. 0x08,0x80,0x0C,0x80,0x08,0x40,0x10,0x20,0x10,0x30,0x20,0x18,0x40,0x0E,0x9F,0xE4,
  123. 0x04,0x20,0x04,0x20,0x04,0x20,0x04,0x20,0x08,0x20,0x10,0xA0,0x20,0x40,0x40,0x00,
  124. };
  125. /* @she0 设(16x16,V)@ [suki software]*/
  126. unsigned char she4[]={
  127. 0x40,0x00,0x21,0xF0,0x31,0x10,0x21,0x10,0x01,0x10,0x01,0x10,0xE2,0x0E,0x25,0xF8,
  128. 0x21,0x08,0x21,0x08,0x20,0x90,0x20,0x90,0x28,0x60,0x30,0x90,0x23,0x0E,0x0C,0x04,
  129. };
  130. /* @ji0 计(16x16,V)@ [suki software]*/
  131. unsigned char ji0[]={
  132. 0x40,0x20,0x20,0x20,0x30,0x20,0x20,0x20,0x00,0x20,0xF3,0xFE,0x10,0x20,0x10,0x20,
  133. 0x10,0x20,0x10,0x20,0x10,0x20,0x12,0x20,0x14,0x20,0x18,0x20,0x10,0x20,0x00,0x20,
  134. };
  135. /* @zhe0 者(16x16,V)@ [suki software]*/
  136. unsigned char zhe0[]={
  137. 0x01,0x00,0x01,0x08,0x3F,0xEC,0x01,0x10,0x01,0x20,0x7F,0xFE,0x00,0x80,0x03,0x00,
  138. 0x07,0xF8,0x1C,0x08,0xE4,0x08,0x07,0xF8,0x04,0x08,0x04,0x08,0x07,0xF8,0x04,0x08,
  139. };
  140. /* @zhou0 周(16x16,V)@ [suki software]*/
  141. unsigned char zhou0[]={
  142. 0x00,0x00,0x1F,0xFC,0x10,0x84,0x13,0xE4,0x10,0x84,0x10,0x84,0x17,0xF4,0x10,0x04,
  143. 0x13,0xE4,0x12,0x24,0x12,0x24,0x13,0xE4,0x22,0x24,0x20,0x04,0x40,0x14,0x80,0x08,
  144. };
  145. /* @yi0 义(16x16,V)@ [suki software]*/
  146. unsigned char yi0[]={
  147. 0x00,0x00,0x04,0x20,0x22,0x30,0x21,0x20,0x11,0x20,0x10,0x40,0x08,0x40,0x04,0x80,
  148. 0x02,0x80,0x01,0x00,0x02,0x80,0x04,0x40,0x08,0x30,0x30,0x0E,0xC0,0x04,0x00,0x00,
  149. };
  150. /* @huang0 黄(16x16,V)@ [suki software]*/
  151. unsigned char huang0[]={
  152. 0x04,0x40,0x04,0x40,0x7F,0xFC,0x04,0x40,0x04,0x40,0xFF,0xFE,0x01,0x00,0x1F,0xF0,
  153. 0x11,0x10,0x1F,0xF0,0x11,0x10,0x11,0x10,0x1F,0xF0,0x08,0x20,0x10,0x18,0x60,0x08,
  154. };
  155. /* @shi0 石(16x16,V)@ [suki software]*/
  156. unsigned char shi0[]={
  157. 0x00,0x00,0xFF,0xFE,0x02,0x00,0x02,0x00,0x04,0x00,0x04,0x00,0x07,0xF8,0x0C,0x08,
  158. 0x0C,0x08,0x14,0x08,0x24,0x08,0x44,0x08,0x84,0x08,0x07,0xF8,0x04,0x08,0x00,0x00,
  159. };
  160. /* @li0 理(16x16,V)@ [suki software]*/
  161. unsigned char li0[]={
  162. 0x00,0x00,0x03,0xFC,0xFA,0x44,0x22,0x44,0x23,0xFC,0x22,0x44,0xFA,0x44,0x23,0xFC,
  163. 0x22,0x44,0x20,0x40,0x23,0xFC,0x38,0x40,0xC0,0x40,0x00,0x40,0x0F,0xFE,0x00,0x00,
  164. };
  165. /* @gong0 工(16x16,V)@ [suki software]*/
  166. unsigned char gong0[]={
  167. 0x00,0x00,0x3F,0xFC,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,
  168. 0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0xFF,0xFE,0x00,0x00,0x00,0x00,
  169. };
  170. /* @xue0 学(16x16,V)@ [suki software]*/
  171. unsigned char xue0[]={
  172. 0x01,0x08,0x10,0x8C,0x0C,0xC8,0x08,0x90,0x7F,0xFE,0x40,0x04,0x8F,0xE8,0x00,0x40,
  173. 0x00,0x80,0x7F,0xFE,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x02,0x80,0x01,0x00,
  174. };
  175. /* @yuan0 院(16x16,V)@ [suki software]*/
  176. unsigned char yuan0[]={
  177. 0x00,0x80,0xF8,0x40,0x8F,0xFE,0x94,0x04,0xA0,0x00,0xA3,0xF8,0x90,0x00,0x88,0x00,
  178. 0x8F,0xFE,0xA9,0x20,0x91,0x20,0x81,0x20,0x82,0x22,0x82,0x22,0x84,0x22,0x88,0x1E,
  179. };
  180. unsigned char BeanLocate[][2]={{3,2},
  181. };
  182. struct Snake
  183. {
  184. uint32 x[N];
  185. uint32 y[N];
  186. uint32 node;
  187. uint32 direction;
  188. uint32 life;
  189. }snake;
  190. struct Food
  191. {
  192. uint32 x;
  193. uint32 y;
  194. uint32 yes;
  195. }food;
  196. typedef struct
  197. {
  198. uint32 Message;
  199. uint32 WParam;
  200. uint32 LParam;
  201. }OSMSG,*POSMSG;
  202. uint32 GameSpeed = 10;
  203. uint32 score  = 0 ;
  204. /****************************************************************************
  205. * 名称:DrawBeanSnake()
  206. * 功能:贪吃蛇专用,蛇和屏幕的位置坐标范围为(0,0)到(110/5=21,60/5=11)
  207. * 画蛇和豆子
  208. * 入口参数:x 蛇的x坐标值
  209. *           y 蛇的y坐标值
  210. * 出口参数:无
  211. * 说明:操作失败原因是指定地址超出有效范围。
  212. ****************************************************************************/
  213. void  DrawBeanSnake(uint32 x, uint32 y)
  214. {  
  215. uint32 x0, y0, x1, y1;
  216.     x0=x*6+1; //偏移一个1为偏移的边框线,乘5是一个蛇节象素的大小
  217.     y0=y*6+1;
  218.     x1=x*6+6;
  219.     y1=y*6+6;
  220. GUI_HLine(x0, y0, x1, 1);
  221.     GUI_HLine(x0, y1, x1, 1);
  222.     GUI_RLine(x0, y0, y1, 1);
  223.     GUI_RLine(x1, y0, y1, 1);
  224. }
  225. /****************************************************************************
  226. * 名称:ClearSnake()
  227. * 功能:贪吃蛇专用 蛇和屏幕的位置坐标范围为(0,0)到(110/5-21/5=17,60/5-11/5=9)
  228. * 清除蛇的尾部
  229. * 入口参数:x 蛇的x坐标值
  230. *           y 蛇的y坐标值
  231. *
  232. * 出口参数:无
  233. * 说明:
  234. ****************************************************************************/
  235. void  ClearSnake(uint32 x, uint32 y)
  236. {  
  237.     uint32 x0, y0, x1, y1;
  238.     x0=x*6+1; //偏移一个1为偏移的边框线,乘5是一个蛇节象素的大小
  239.     y0=y*6+1;
  240.     x1=x*6+6;
  241.     y1=y*6+6;
  242.     GUI_HLine(x0, y0, x1-1, 0); //减1为防止把前面蛇的一个边框点给清掉
  243. GUI_HLine(x0, y1, x1-1, 0);
  244.     GUI_RLine(x0, y0, y1,   0);
  245.     GUI_RLine(x1, y0, y1, 0);
  246. }
  247. /****************************************************************************
  248. * 名称:GameOvere()
  249. * 功能:游戏结束时清屏,并显示"游戏结束"
  250. *
  251. * 入口参数:无
  252. * 出口参数:无
  253. * 说明:无
  254. ****************************************************************************/
  255. void GameOver(void)
  256. {
  257. GUI_FillSCR(0x00);
  258. GUI_PutHZ(32, 25,       (uint8 *)you0, 16, 16); //中间显示"游戏结束"
  259.     GUI_PutHZ(32+16, 25,    (uint8 *)xi0,  16, 16);
  260.     GUI_PutHZ(32+16+16, 25, (uint8 *)jie0, 16, 16);
  261.     GUI_PutHZ(32+16+16+16, 25, (uint8 *)shu0, 16, 16);
  262. }
  263. /****************************************************************************
  264. * 名称:PrintScore()
  265. * 功能:在坐标(x,y)的屏幕上显示一个数
  266. *
  267. * 入口参数:x 数的x坐标值
  268. *           y 数的y坐标值
  269. * data 要显示的数
  270. * 出口参数:无
  271. * 说明:数的大小不能超过100
  272. ****************************************************************************/
  273. void PrintScore(uint32 x, uint32 y, uint32 data)
  274. {
  275. uint32 i,j,x0,y0;
  276. x0=x;
  277. y0=y;
  278. i=data/10;
  279. j=data%10;
  280. switch(i)
  281. {
  282.  //case 0:GUI_PutChar8_8(125-12, 54, '0');break;
  283.  case 0:GUI_PutChar8_8(x0, y0, '0');break;
  284.  case 1:GUI_PutChar8_8(x0, y0, '1');break;
  285.  case 2:GUI_PutChar8_8(x0, y0, '2');break;
  286.  case 3:GUI_PutChar8_8(x0, y0, '3');break;
  287.  case 4:GUI_PutChar8_8(x0, y0, '4');break;
  288.  case 5:GUI_PutChar8_8(x0, y0, '5');break;
  289.  case 6:GUI_PutChar8_8(x0, y0, '6');break;
  290.  case 7:GUI_PutChar8_8(x0, y0, '7');break;
  291.  case 8:GUI_PutChar8_8(x0, y0, '8');break;
  292.  case 9:GUI_PutChar8_8(x0, y0, '9');break;
  293. switch(j)
  294. {
  295.  //case 0:GUI_PutChar8_8(125-5, 54, '0');break;
  296.  case 0:GUI_PutChar8_8(x0+8, y0, '0');break;
  297.  case 1:GUI_PutChar8_8(x0+8, y0, '1');break;
  298.  case 2:GUI_PutChar8_8(x0+8, y0, '2');break;
  299.  case 3:GUI_PutChar8_8(x0+8, y0, '3');break;
  300.  case 4:GUI_PutChar8_8(x0+8, y0, '4');break;
  301.  case 5:GUI_PutChar8_8(x0+8, y0, '5');break;
  302.  case 6:GUI_PutChar8_8(x0+8, y0, '6');break;
  303.  case 7:GUI_PutChar8_8(x0+8, y0, '7');break;
  304.  case 8:GUI_PutChar8_8(x0+8, y0, '8');break;
  305.  case 9:GUI_PutChar8_8(x0+8, y0, '9');break;
  306. }
  307. void GamePlay(void)
  308. {
  309. uint32 i;
  310. snake.life=0;
  311. snake.direction=1;
  312. snake.x[0]=0;snake.y[0]=6; //蛇头
  313. snake.x[1]=1;snake.y[1]=6;
  314. snake.node=2; //节数
  315. food.x=7;
  316. food.y=6;
  317. DrawBeanSnake(food.x,food.y);
  318. food.yes=1;
  319. PrintScore(112,54,score);
  320. while(1)
  321. {
  322. if(food.yes==0)
  323. {
  324. food.x=food.x+3;
  325. food.y++;
  326. if(food.x>17)
  327. food.x=0;
  328. if(food.y>9)
  329. food.y=0;
  330. DrawBeanSnake(food.x,food.y);
  331. food.yes=1;
  332. }
  333. if(food.yes==1)//避免豆子显示在蛇身上而使豆子被清掉
  334. {
  335. DrawBeanSnake(food.x,food.y);
  336. }
  337. for(i=snake.node-1;i>0;i--)
  338. {
  339.  snake.x[i]=snake.x[i-1];
  340.  snake.y[i]=snake.y[i-1];
  341. }
  342. switch(snake.direction)
  343. {
  344.  case 1:snake.x[0]+=1;break;
  345.  case 2:snake.x[0]-=1;break;
  346.  case 3:snake.y[0]-=1;break;
  347.  case 4:snake.y[0]+=1;break;
  348. }
  349. for(i=3;i<snake.node;i++) //从蛇的第四节开始判断是否撞到自己,因为蛇头为两节,第三节不可能拐过来
  350. {
  351.  if(snake.x[i]==snake.x[0]&&snake.y[i]==snake.y[0])
  352.  {
  353.   GameOver();
  354.   snake.life=1;
  355.   break;
  356.  }
  357. }
  358. if(snake.x[0]>17||snake.y[0]>9) //判断蛇是否撞到墙
  359. {
  360.  GameOver();
  361.  snake.life=1;
  362. }
  363. if(snake.life==1) //如果蛇死就跳出循环,重新开始
  364. break;
  365. for(i=0;i<snake.node;i++) //画蛇
  366. DrawBeanSnake(snake.x[i], snake.y[i]);
  367. OSTimeDly(GameSpeed);
  368. if(snake.x[0]==food.x&&snake.y[0]==food.y) //吃到食物后
  369. {
  370.  food.yes=0;
  371.  snake.node++;
  372.  score+=1;
  373.  PrintScore(112,54,score);
  374. }  
  375. ClearSnake(snake.x[snake.node-1], snake.y[snake.node-1]); //清除蛇的最后一节
  376. /*if(key==ESC)
  377. break;
  378. else if(key==UP&&snake.direction!=4) //判断是否往相反的方向移动
  379.  snake.direction=3;
  380. else if(key==RIGHT&&snake.direction!=2)
  381.  snake.direction=1;
  382. else if(key==LIFT&&snake.direction!=1)
  383.  snake.direction=2;
  384. else if(key==DOWN&&snake.direction!=3)
  385.  snake.direction=4;*/
  386. }//END while
  387. }
  388. /****************************************************************************
  389. * 名称:IniPicture()
  390. * 功能:游戏开始时屏幕的边框初始化
  391. *
  392. * 入口参数:无
  393. * 出口参数:无
  394. * 说明:无
  395. ****************************************************************************/
  396. void IniGamePicture(void)
  397. {
  398.     GUI_Initialize();
  399.     GUI_PutHZ(125-12, 0,  (uint8 *)tan0, 16, 16); //边上显示"贪吃蛇"
  400.     GUI_PutHZ(125-12, 16, (uint8 *)chi0, 16, 16);
  401.     GUI_PutHZ(125-12, 32, (uint8 *)she0, 16, 16);
  402.     GUI_Rectangle(0,0,125-13,63,2); //画边界框
  403.     DrawBeanSnake(0,6);
  404.     DrawBeanSnake(1,6);
  405. }
  406. /****************************************************************************
  407. * 名称:IniDesignInformation()
  408. * 功能: 显示设计者信息
  409. *
  410. * 入口参数:无
  411. * 出口参数:无
  412. * 说明:无
  413. ****************************************************************************/
  414. void IniDesignInformation(void)
  415. {
  416. uint32 i=1;
  417. GUI_PutHZ(i*18, 0,   (uint8 *)huang0,16, 16); //黄石理工学院 设计者 周义
  418. i++;
  419.     GUI_PutHZ(i*18, 0,   (uint8 *)shi0,  16, 16);
  420.     i++;
  421.     GUI_PutHZ(i*18, 0,   (uint8 *)li0,   16, 16);
  422.     i++;
  423.     GUI_PutHZ(i*18, 0,   (uint8 *)gong0, 16, 16);
  424.     i++;
  425.     GUI_PutHZ(i*18, 0,   (uint8 *)xue0,  16, 16);
  426.     i++;
  427.     GUI_PutHZ(i*18, 0,   (uint8 *)yuan0, 16, 16);
  428.     
  429.     i=2;
  430.     GUI_PutHZ(i*18, 18,  (uint8 *)she4,  16, 16);
  431.     i++;
  432.     GUI_PutHZ(i*18, 18,  (uint8 *)ji0,   16, 16);
  433.     i++;
  434.     GUI_PutHZ(i*18, 18,  (uint8 *)zhe0,  16, 16);
  435.     
  436.     i=3;
  437.     GUI_PutHZ(i*18, 36,  (uint8 *)zhou0, 16, 16);
  438.     i++;
  439.     GUI_PutHZ(i*18, 36,  (uint8 *)yi0,   16, 16);
  440.     OSTimeDlyHMSM(0,0,0,50);
  441. }
  442. /****************************************************************************
  443. * 名称:GUI_PutHZ_Gai()
  444. * 功能: GUI_PutHZ修改版,坐标(0,0)到(8,4)
  445. *
  446. * 入口参数:x
  447. * y
  448. * dat
  449. * 出口参数:无
  450. * 说明:无
  451. ****************************************************************************/
  452. void GUI_PutHZ_Gai(uint32 x, uint32 y, uint8 *dat)
  453. {
  454. //GUI_PutHZ(x*16, y*16, *dat, 16, 16);
  455. }
  456. /****************************************************************************
  457. * 名称:LedInit()
  458. * 功能: Led口的输入输出定义
  459. *
  460. * 入口参数:无
  461. * 出口参数:无
  462. * 说明:无
  463. ****************************************************************************/
  464. void LedInit(void)
  465. {
  466.   PINSEL0=0x00000000;
  467.   PINSEL1=0x00000000;
  468.   IODIR=0xffffffff;
  469.   IOSET=LED1;
  470.   IOSET=LED2;
  471.   IOSET=LED3;
  472. }
  473. /****************************************************************************
  474. * 名称:LedInit()
  475. * 功能: Led口的输入输出定义
  476. *
  477. * 入口参数:无
  478. * 出口参数:无
  479. * 说明:无
  480. ****************************************************************************/
  481. void KeyInit(void)
  482. {
  483. PINSEL0=0x00000000;
  484.   PINSEL1=0x00000000;
  485.   IODIR  =0xe83fffff;
  486. }
  487. /****************************************************************************
  488. * 名称: main()
  489. * 功能: 初始化uC/OS-II操作系统,建立第一个任务,然后启动系统。
  490. ****************************************************************************/
  491. int  main(void)
  492. {
  493. OSInit ();
  494. OSTaskCreate(Task0,    (void *)0, &TaskStk[TaskStkLengh - 1],      10);
  495. OSTaskCreate(TaskLed1, (void *)0, &TaskLed1Stk[TASK_STK_SIZE - 1], 30);
  496.     OSTaskCreate(TaskLed2, (void *)0, &TaskLed2Stk[TASK_STK_SIZE - 1], 35);
  497.     OSTaskCreate(TaskLed3, (void *)0, &TaskLed3Stk[TASK_STK_SIZE - 1], 31);
  498. OSStart ();
  499. return 0;
  500. }
  501. /*********************************************************************************************************
  502. **                            Task0 任务0
  503. ** 功能:主任务,游戏的显示任务
  504. ********************************************************************************************************/
  505. void  Task0(void *pdata)
  506. {   
  507. pdata = pdata;
  508. TargetInit ();
  509. LedInit();
  510. GUI_Initialize();       // 初始化LCM
  511.     GUI_SetColor(1, 0);     // 设置前景色和背景色
  512.     OSTimeDly(10);
  513.     IniDesignInformation();
  514.     OSTimeDly(10);
  515.     IniGamePicture();
  516.     GamePlay();   
  517. while (1)
  518. {
  519. OSTimeDly(10);
  520. }
  521. }
  522. /*********************************************************************************************************
  523. **                            TaskLed1 任务1
  524. ** 功能:LED闪烁任务,显示操作系统的运行状况
  525. ********************************************************************************************************/
  526. void  TaskLed1(void *pdata)
  527. {   
  528.    
  529.     pdata=pdata;
  530. TargetInit();
  531. LedInit();
  532. while(1)
  533. {
  534. IOSET=LED2;
  535. OSTimeDlyHMSM(0,0,0,50); 
  536. IOCLR=LED2;
  537. //OSTaskSuspend(5);
  538. OSTimeDlyHMSM(0,0,0,50);  
  539. }                                
  540. while(1);
  541. }
  542. /*********************************************************************************************************
  543. **                            TaskLed2 任务2
  544. ** 功能:键盘扫描任务
  545. ********************************************************************************************************/
  546. void  TaskLed2(void *pdata)
  547. {   
  548. //POSMSG pMsg;
  549. pdata=pdata;
  550. TargetInit();
  551. KeyInit();
  552. while(1)
  553. {
  554. if((IO0PIN&KEY_UP)==0)
  555. {
  556. OSTimeDlyHMSM(0,0,0,5);
  557. if((IO0PIN&KEY_UP)==0)
  558. {
  559. snake.direction=3;
  560. IOSET=LED2;
  561. while((IO0PIN&KEY_UP)==0);
  562. }
  563. }
  564. if((IO0PIN&KEY_DOWN)==0)
  565. {
  566. OSTimeDlyHMSM(0,0,0,5);
  567. if((IO0PIN&KEY_DOWN)==0)
  568. {
  569. snake.direction=4;
  570. IOCLR=LED2;
  571. while((IO0PIN&KEY_DOWN)==0);
  572. }
  573. }
  574. if((IO0PIN&KEY_LIFT)==0)
  575. {
  576. OSTimeDlyHMSM(0,0,0,5);
  577. if((IO0PIN&KEY_LIFT)==0)
  578. {
  579. snake.direction=2;
  580. while((IO0PIN&KEY_LIFT)==0);
  581. }
  582. }
  583. if((IO0PIN&KEY_RIGHT)==0)
  584. {
  585. OSTimeDlyHMSM(0,0,0,5);
  586. if((IO0PIN&KEY_RIGHT)==0)
  587. {
  588. snake.direction=1;
  589. while((IO0PIN&KEY_RIGHT)==0);
  590. }
  591. }
  592. //pMsg=OSCreateMessage(0,(snake.direction+1),snake.direction>>16);
  593. //if(pMsg)
  594. // SendMessage(pMsg);
  595.     OSTimeDlyHMSM(0,0,0,5);
  596.     }//end while
  597.                                  
  598. while(1);
  599. }
  600. /*********************************************************************************************************
  601. **                            TaskLed3 任务3
  602. ** 功能:LED闪烁任务,显示操作系统的运行状况
  603. ********************************************************************************************************/
  604. void  TaskLed3(void *pdata)
  605. {  
  606. //uint8 txmsg;
  607. uint32 j;
  608. //txmsg = 'A';
  609. pdata=pdata;
  610. TargetInit();
  611. LedInit();
  612. while(1)
  613. {
  614. for(j=0;j<=2;j++)
  615. {
  616. IOSET=LED3;
  617. OSTimeDlyHMSM(0,0,0,50);
  618. IOCLR=LED3;
  619. OSTimeDlyHMSM(0,0,0,50);
  620. }
  621. //OSMboxPost(TxMbox,(void *)&txmsg);
  622. }                                
  623. while(1);
  624. }  
  625. /*********************************************************************************************************
  626. **                            End Of File
  627. ********************************************************************************************************/