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

📄 main.lst

📁 单片机上用128*64液晶 做的开窗游戏
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V8.05a   MAIN                                                                 02/17/2008 15:54:11 PAGE 1   


C51 COMPILER V8.05a, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN main.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE main.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          #include <reg52.h>
   2          #include <12864.h>
   3          #include <asc.h>
   4          #include <level.h>
   5          #include <img.h>
   6          
   7          //菜单的实现
   8          /*-------------------------------------------------------------*/
   9          #define MENU_SIZE 8              //菜单长度
  10          
  11          unsigned char idata KeyFuncIndex=0;    //存放当前的菜单索引
  12          
  13          void (*KeyFuncPtr)();            //定义按键功能指针
  14          //定义类型 
  15          typedef struct 
  16          {
  17             unsigned char KeyStateIndex;   //当前的状态索引号
  18             unsigned char KeyDownState;    //按下向下键时的状态索引号
  19             unsigned char KeyUpState;      //按下向上键时的状态索引号
  20             unsigned char KeyEnterState;   //按下回车键时的状态索引号
  21             void (*CurrentOperate)();      //当前状态应该执行的功能操作
  22          }  StateTab;
  23          /*-------------------------------------------------------------*/
  24          //定义状态量:
  25          #define LEVELMAX 17
  26          unsigned char idata MenuState=1;              //在菜单的状态下
  27          unsigned char idata GameState=0;                  //在开窗游戏的状态下
  28          unsigned char idata SettingState=0;       //在游戏的设置状态下
  29          unsigned char idata FocusX=2;             //当前窗户的焦点(0~4,0~4)
  30          unsigned char idata FocusY=2;
  31          unsigned char idata FocusXOld;            //上个窗户的焦点坐标
  32          unsigned char idata FocusYOld;
  33          unsigned char idata Level=0;            //存放当前的游戏级别
  34          unsigned char idata CurLevDat[5][5];    //存放当前的游戏数据,note the key word "data"
  35          unsigned char idata LevelTemp;
  36          //
  37          //0:the menu state 1:the GameState 2: the SettingState
  38          unsigned char keyInputState=0; 
  39            
  40          /*-------------------------------------------------------------*/
  41          //定义字符串
  42          unsigned char code s0[]="WindowGame      ";
  43          unsigned char code s1[]="AboutTheGame    ";
  44          unsigned char code s2[]="GameStart       ";
  45          unsigned char code s3[]="LevelSetting    ";
  46          unsigned char code s4[]="                ";
  47          unsigned char code s5[]="Cancel          ";
  48          unsigned char code s6[]="You do well!";
  49          /*-------------------------------------------------------------*/
  50          //指定窗户的开关状态并且显示更新LCD
  51          //x,y是窗户的坐标
  52          //flag :窗户的开关状态 (1:从打开到关闭,0:从关闭到打开)
  53          void OneWindowStateDisp(unsigned char x,unsigned char y,bit flag)
  54          {
  55   1          unsigned char i,j;
C51 COMPILER V8.05a   MAIN                                                                 02/17/2008 15:54:11 PAGE 2   

  56   1              for (j=0;j<5;j++)
  57   1                for(i=0;i<5;i++)
  58   1                {
  59   2                    if(x==i&&y==j)
  60   2                        {
  61   3                           x=5+12*i;
  62   3                               y=5+12*j;
  63   3                               RectArea(x+1,y+1,(x+6)-1,(y+6)-1,flag);
  64   3                        }
  65   2                }
  66   1      }
  67          /*-------------------------------------------------------------*/
  68          //将游戏数据中的窗户开关状态显示到LCD上
  69          void WindowStateDisp(void)
  70          {
  71   1              unsigned char i,j;
  72   1              bit flag;
  73   1          for (j=0;j<5;j++)
  74   1                for(i=0;i<5;i++)
  75   1                {
  76   2                   if(CurLevDat[j][i]==0)
  77   2                          flag=0;
  78   2                       else
  79   2                          flag=1;
  80   2                       OneWindowStateDisp(i,j,flag);
  81   2                }
  82   1      
  83   1      }
  84          /*-------------------------------------------------------------*/
  85          //对窗户焦点进行存放备用
  86          void FocusStore()
  87          {
  88   1         FocusXOld=FocusX;
  89   1         FocusYOld=FocusY;
  90   1      }
  91          /*-------------------------------------------------------------*/
  92          void FocusDis(void)
  93          {
  94   1          unsigned char i,j,x,y;
  95   1              for(j=0;j<5;j++)
  96   1                for(i=0;i<5;i++)
  97   1                {             
  98   2                    //将当前的焦点显示在当前的窗户上
  99   2                    if(i==FocusX&&j==FocusY)
 100   2                        {      
 101   3                       x=5+12*i;
 102   3                           y=5+12*j;
 103   3                       Rect(x-2,y-2,(x+6)+2,(y+6)+2,1);
 104   3                        }
 105   2                        //擦除原来窗户的焦点
 106   2                        if(i==FocusXOld&&j==FocusYOld)
 107   2                        {
 108   3                       x=5+12*i;
 109   3                           y=5+12*j;
 110   3                       Rect(x-2,y-2,(x+6)+2,(y+6)+2,0);
 111   3                        }
 112   2                }
 113   1         
 114   1      }
 115          /*-------------------------------------------------------------*/
 116          //在游戏状态下按下enter键后对游戏窗户打开关闭数据的修改
 117          //
C51 COMPILER V8.05a   MAIN                                                                 02/17/2008 15:54:11 PAGE 3   

 118          void GameEnter(void)
 119          {
 120   1          unsigned char i,j;
 121   1              for(j=0;j<5;j++)
 122   1                for(i=0;i<5;i++)
 123   1                {
 124   2                    if(((i==FocusX)&&(j==FocusY-1))||((i==(FocusX-1))&&(j==FocusY))||(i==FocusX&&j==FocusY)||((i==(Focu
             -sX+1))&&(j==FocusY))||((i==FocusX)&&(j==(FocusY+1))) )
 125   2                        {
 126   3                           // CurLevDat[j][i]=~CurLevDat[j][i];  //错误的写法
 127   3                               if(CurLevDat[j][i]==0)
 128   3                                  CurLevDat[j][i]=1;
 129   3                           else 
 130   3                                  CurLevDat[j][i]=0;
 131   3                        }
 132   2      
 133   2                }
 134   1      }
 135          /*-------------------------------------------------------------*/
 136          void Stat0(void)
 137          {
 138   1          en_disp(0,0,16,Asc,s0,0);
 139   1              en_disp(2,0,16,Asc,s1,1);
 140   1              en_disp(4,0,16,Asc,s4,1);
 141   1              en_disp(6,0,16,Asc,s4,1);
 142   1      }
 143          /*-------------------------------------------------------------*/
 144          void Stat1(void)
 145          {       
 146   1          en_disp(0,0,16,Asc,s0,1);
 147   1              en_disp(2,0,16,Asc,s1,0);
 148   1              en_disp(4,0,16,Asc,s4,1);
 149   1              en_disp(6,0,16,Asc,s4,1);
 150   1      }
 151          /*-------------------------------------------------------------*/
 152          void Stat2(void)
 153          {
 154   1          en_disp(0,0,16,Asc,s2,0);
 155   1              en_disp(2,0,16,Asc,s3,1);
 156   1              en_disp(4,0,16,Asc,s5,1);
 157   1              en_disp(6,0,16,Asc,s4,1);
 158   1      }
 159          /*-------------------------------------------------------------*/
 160          void Stat3(void)
 161          {
 162   1          en_disp(0,0,16,Asc,s2,1);
 163   1              en_disp(2,0,16,Asc,s3,0);
 164   1              en_disp(4,0,16,Asc,s5,1);
 165   1              en_disp(6,0,16,Asc,s4,1);
 166   1      }
 167          /*-------------------------------------------------------------*/
 168          void Stat4(void)         //return the first floor
 169          {
 170   1          en_disp(0,0,16,Asc,s2,1);
 171   1              en_disp(2,0,16,Asc,s3,1);
 172   1              en_disp(4,0,16,Asc,s5,0);
 173   1              en_disp(6,0,16,Asc,s4,1);
 174   1      }
 175          /*-------------------------------------------------------------*/
 176          //initial the game data
 177          void initGameDat(void)
 178          {
C51 COMPILER V8.05a   MAIN                                                                 02/17/2008 15:54:11 PAGE 4   

 179   1          unsigned char i,j;
 180   1              for (j=0;j<5;j++)
 181   1                 for(i=0;i<5;i++)
 182   1                 {
 183   2                     CurLevDat[j][i]=LevelDat[Level][j][i];
 184   2                 }
 185   1              //
 186   1              FocusX=2;
 187   1              FocusY=2;
 188   1      }
 189          /*-------------------------------------------------------------*/
 190          //draw the game ground
 191          void drawGameGnd(void)
 192          {
 193   1          unsigned char i,j,x,y;
 194   1          ClearLCD();
 195   1              Rect(0,0,63,63,1);
 196   1              Rect(1,1,62,62,1);
 197   1              //draw the widow frame 
 198   1              for(j=0;j<5;j++)                       //要注意这里
 199   1                for(i=0;i<5;i++)
 200   1                {
 201   2                    x=5+12*i;
 202   2                        y=5+12*j;
 203   2                    Rect(x,y,x+6,y+6,1);
 204   2                }
 205   1      }
 206          /*-------------------------------------------------------------*/
 207          //draw the level text
 208          void LevelText(void)
 209          {
 210   1          unsigned char s[2];
 211   1          s[0]=Level/10+'0';
 212   1              s[1]=Level%10+'0';
 213   1      
 214   1              en_disp(2,64,7,Asc," Level:",1);
 215   1              en_disp(4,90,2,Asc,s,1);
 216   1      }
 217          /*-------------------------------------------------------------*/
 218          void Stat5(void)                 //enter the "WindowGame" state 
 219          {
 220   1          //退出菜单状态,进入游戏状态
 221   1              keyInputState=1;
 222   1              //在这里进行游戏数据的初始化
 223   1              initGameDat();           
 224   1              //画游戏场地
 225   1              drawGameGnd();
 226   1              //draw the window focus
 227   1              FocusDis();
 228   1              //将游戏数据中窗户的开关状态显示在lcd上
 229   1              WindowStateDisp();
 230   1              //Draw the Level Text
 231   1              LevelText();
 232   1      
 233   1      }
 234          /*-------------------------------------------------------------*/
 235          void Stat6(void)                 //enter the "LevelSetting" state
 236          {
 237   1              keyInputState=2;
 238   1              ClearLCD();
 239   1              LevelText();
 240   1      }
C51 COMPILER V8.05a   MAIN                                                                 02/17/2008 15:54:11 PAGE 5   

 241          /*-------------------------------------------------------------*/
 242          void Stat7(void)             //enter the "AboutTheGame" state
 243          {
 244   1       //   ClearLCD();
 245   1          img12864_disp(img0);
 246   1      }
 247          /*-------------------------------------------------------------*/
 248          StateTab code KeyTab[MENU_SIZE]=
 249          {
 250             {0,1,1,2,(*Stat0)},     //一层
 251             {1,0,0,7,(*Stat1)},
 252          
 253             {2,3,4,5,(*Stat2)},     //二层
 254             {3,4,2,6,(*Stat3)},
 255             {4,2,3,0,(*Stat4)},

⌨️ 快捷键说明

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