⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 game.lst

📁 单片机上的贪吃蛇。12864显示。含详细资料
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V8.02   GAME                                                                  03/12/2009 22:02:27 PAGE 1   


C51 COMPILER V8.02, COMPILATION OF MODULE GAME
OBJECT MODULE PLACED IN Game.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE Game.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          //12864并行接口参考程序,控制器st7920  
   2          #include "reg52.h"
   3          #include "Lcd12864.h"
   4          #include "Key.h"
   5          #define uchar unsigned char
   6          #define uint unsigned int
   7          
   8          static unsigned long Seed = 1;
   9          #define A 48271L
  10          #define M 2147483647L
  11          #define Q (M / A)
  12          #define R (M % A)
  13          /************************************
  14          伪随机数发生器
  15          *************************************/
  16          double Random(void)
  17          {
  18   1              long TmpSeed;
  19   1              TmpSeed=A*(Seed%Q)-R*(Seed/Q);
  20   1              if(TmpSeed>=0)
  21   1                      Seed=TmpSeed;
  22   1              else
  23   1                      Seed=TmpSeed+M;
  24   1              return (double)Seed/M;
  25   1      }
  26          
  27          /**************************************
  28          为伪随机数发生器播种
  29          ***************************************/
  30          void InitRandom(unsigned long InitVal)
  31          {
  32   1              Seed=InitVal;
  33   1      }
  34          
  35          //延时子程序
  36          void delay(unsigned int t)
  37          {  
  38   1              unsigned int i,j;
  39   1              for(i=0;i<t;i++)
  40   1                      for(j=0;j<10;j++);    
  41   1      }
  42          
  43          /*********************************
  44          初始化MPU
  45          **********************************/
  46          void InitCpu(void)
  47          {
  48   1              TMOD=0x0;
  49   1              TH0=0;
  50   1              TL0=0;
  51   1              TR0=1;
  52   1              ET0=1;
  53   1              EA=1;
  54   1      }
  55          
C51 COMPILER V8.02   GAME                                                                  03/12/2009 22:02:27 PAGE 2   

  56          #define N 25
  57          struct Food
  58          {
  59                  unsigned char x;
  60                  unsigned char y;
  61                  unsigned char yes;
  62          }food;//食物结构体
  63          struct Snake
  64          {
  65                  unsigned char x[N];
  66                  unsigned char y[N];
  67                  unsigned char node;
  68                  unsigned char direction;
  69                  unsigned char life;
  70          }snake;//蛇结构体
  71          
  72          unsigned char Flag=0;
  73          unsigned char Score=0;
  74          unsigned char Speed=5;
  75          unsigned char KeyBuffer=0;
  76          #define FUNC 1
  77          #define UP 2
  78          #define DOWN 3
  79          #define LEFT 4
  80          #define RIGHT 5
  81          #define PASSSCORE 20//预定义过关成绩
  82          void Timer0Int(void) interrupt 1
  83          {
  84   1              switch(OSReadKey())
  85   1              {
  86   2                      case 9:
  87   2                                      KeyBuffer=FUNC;
  88   2                                      /*if(++Speed>=10)
  89   2                                              Speed=1;
  90   2                                      Flag|=1<<1;//速度变化标志置1*/
  91   2                                      break;
  92   2                      case 13:
  93   2                                      KeyBuffer=DOWN;
  94   2                                      /*if(snake.direction!=2)
  95   2                                              snake.direction=1;*/
  96   2                                      break;
  97   2                      case 17:
  98   2                                      KeyBuffer=UP;
  99   2                                      /*if(snake.direction!=1)
 100   2                                              snake.direction=2;*/
 101   2                                      break;
 102   2                      case 21:
 103   2                                      KeyBuffer=RIGHT;
 104   2                                      /*if(snake.direction!=4)
 105   2                                              snake.direction=3;*/
 106   2                                      break;
 107   2                      case 25:
 108   2                                      KeyBuffer=LEFT;
 109   2                                      /*if(snake.direction!=3)
 110   2                                              snake.direction=4;*/
 111   2                                      break;
 112   2                      default:
 113   2                                      break;
 114   2              }
 115   1      }
 116          
 117          /******************************
C51 COMPILER V8.02   GAME                                                                  03/12/2009 22:02:27 PAGE 3   

 118          画墙壁,初始化界面
 119          *******************************/
 120          void DrawBoard(void)
 121          {
 122   1              unsigned char n;
 123   1              for(n=0;n<31;n++)
 124   1              {
 125   2                      Lcd_Rectangle(3*n,0,3*n+2,2,1);
 126   2                      Lcd_Rectangle(3*n,60,3*n+2,62,1);
 127   2              }
 128   1              for(n=0;n<21;n++)
 129   1              {
 130   2                      Lcd_Rectangle(0,3*n,2,3*n+2,1);
 131   2                      Lcd_Rectangle(90,3*n,92,3*n+2,1);               
 132   2              }
 133   1              Lcd_HoriLine(93,31,35,1);
 134   1              Lcd_HoriLine(93,63,35,1);
 135   1      }
 136          
 137          /***************************
 138          打印成绩
 139          ****************************/
 140          void PrintScore(void)
 141          {
 142   1              unsigned char Str[3];
 143   1              Lcd_WriteStr(6,0,"成绩");
 144   1              Str[0]=(Score/10)|0x30;//十位
 145   1              Str[1]=(Score%10)|0x30;//个位
 146   1              Str[2]=0;
 147   1              Lcd_WriteStr(7,1,Str);
 148   1      }
 149          
 150          /********************************
 151          打印速度级别
 152          *********************************/
 153          void PrintSpeed(void)
 154          {
 155   1              unsigned char Str[2];
 156   1              Lcd_WriteStr(6,2,"级别");
 157   1              Str[0]=Speed|0x30;
 158   1              Str[1]=0;
 159   1              Lcd_WriteStr(7,3,Str);
 160   1      }
 161          
 162          /***********************************
 163          游戏结束处理
 164          ************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -