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

📄 hurricanelamp.lst

📁 protuse的实例学习单片机
💻 LST
字号:
C51 COMPILER V8.05a   HURRICANELAMP                                                        11/26/2008 21:07:36 PAGE 1   


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

line level    source

   1          #include <REG52.H>
   2          
   3          unsigned char RunMode;
   4          //**********************************System Fuction*************************************************
   5          void Delay1ms(unsigned int count){
   6   1              unsigned int i,j;
   7   1              for(i=0;i<count;i++)
   8   1              for(j=0;j<120;j++);
   9   1      }
  10          
  11          unsigned char code LEDDisplayCode[] = { 0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,        //0~7
  12                                                                  0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E,0xFF};
  13          
  14          void Display(unsigned char Value){
  15   1              P3 = LEDDisplayCode[Value];
  16   1      }
  17          
  18          void LEDFlash(unsigned char Count){
  19   1              unsigned char i;
  20   1              bit Flag;
  21   1              for(i = 0; i<Count;i++)
  22   1              {
  23   2                      Flag = !Flag;
  24   2                      if(Flag)
  25   2                              Display(RunMode);
  26   2                      else
  27   2                              Display(0x10);
  28   2                      Delay1ms(100);
  29   2              }
  30   1              Display(RunMode);
  31   1      }
  32          
  33          unsigned char GetKey(void){
  34   1              unsigned char KeyTemp,CheckValue,Key = 0x00;
  35   1              CheckValue = P2&0x32;
  36   1              if(CheckValue==0x32)
  37   1                      return 0x00;
  38   1              
  39   1              Delay1ms(10);
  40   1              KeyTemp = P2&0x32;
  41   1              if(KeyTemp==CheckValue)
  42   1                      return 0x00;
  43   1      
  44   1              if(!(CheckValue&0x02))
  45   1                      Key|=0x01;
  46   1              if(!(CheckValue&0x10))
  47   1                      Key|=0x02;
  48   1              if(!(CheckValue&0x20))
  49   1                      Key|=0x04;
  50   1              return Key;
  51   1      }
  52          
  53          unsigned int TimerCount,SystemSpeed,SystemSpeedIndex;
  54          void InitialTimer2(void)
  55          {
C51 COMPILER V8.05a   HURRICANELAMP                                                        11/26/2008 21:07:36 PAGE 2   

  56   1              T2CON  = 0x00;                  //16 Bit Auto-Reload Mode
  57   1              TH2 = RCAP2H = 0xFC;    //重装值,初始值 TL2 = RCAP2L = 0x18;
  58   1              ET2=1;                                  //定时器 2 中断允许
  59   1              TR2 = 1;                                //定时器 2 启动
  60   1              EA=1;
  61   1      }
  62          
  63          unsigned int code SpeedCode[]={   1,   2,   3,   5,   8,  10,  14,  17,  20,  30,
  64                                                                       40,  50,  60,  70,  80,  90, 100, 120, 140, 160,
  65                                                                          180, 200, 300, 400, 500, 600, 700, 800, 900,1000};//30
  66          void SetSpeed(unsigned char Speed){
  67   1              SystemSpeed =SpeedCode[Speed];
  68   1      }
  69          
  70          void LEDShow(unsigned int LEDStatus){
  71   1              P1 = ~(LEDStatus&0x00FF);
  72   1              P0 = ~((LEDStatus>>8)&0x00FF);
  73   1      }
  74          
  75          void InitialCPU(void){
  76   1              RunMode = 0x00;
  77   1              TimerCount = 0;
  78   1              SystemSpeedIndex = 10;
  79   1      
  80   1              P1 = 0x00;
  81   1              P0 = 0x00;
  82   1              P2 = 0xFF;
  83   1              P3 = 0x00;
  84   1              Delay1ms(500);
  85   1              P1 = 0xFF;
  86   1              P0 = 0xFF;
  87   1              P2 = 0xFF;
  88   1              P3 = 0xFF;
  89   1              SetSpeed(SystemSpeedIndex);
  90   1              Display(RunMode);
  91   1      }
  92          
  93          //Mode 0
  94          unsigned int LEDIndex = 0;
  95          bit LEDDirection = 1,LEDFlag = 1;
  96          void Mode_0(void)
  97          {
  98   1              LEDShow(0x0001<<LEDIndex);
  99   1              LEDIndex = (LEDIndex+1)%16;
 100   1      }
 101          //Mode 1
 102          void Mode_1(void){
 103   1              LEDShow(0x8000>>LEDIndex);
 104   1              LEDIndex = (LEDIndex+1)%16;
 105   1      }
 106          //Mode 2
 107          void Mode_2(void)
 108          {
 109   1              if(LEDDirection)
 110   1                      LEDShow(0x0001<<LEDIndex);
 111   1              else
 112   1                      LEDShow(0x8000>>LEDIndex);
 113   1              if(LEDIndex==15)
 114   1                      LEDDirection = !LEDDirection;
 115   1         LEDIndex = (LEDIndex+1)%16;
 116   1      }
 117          //Mode 3
C51 COMPILER V8.05a   HURRICANELAMP                                                        11/26/2008 21:07:36 PAGE 3   

 118          void Mode_3(void){
 119   1              if(LEDDirection)
 120   1                      LEDShow(~(0x0001<<LEDIndex));
 121   1              else
 122   1                      LEDShow(~(0x8000>>LEDIndex));
 123   1              if(LEDIndex==15)
 124   1                      LEDDirection = !LEDDirection;
 125   1         LEDIndex = (LEDIndex+1)%16;
 126   1      }
 127          
 128          //Mode 4
 129          void Mode_4(void)
 130          {
 131   1              if(LEDDirection)
 132   1              {
 133   2                      if(LEDFlag)
 134   2                              LEDShow(0xFFFE<<LEDIndex);
 135   2                      else
 136   2                              LEDShow(~(0x7FFF>>LEDIndex));
 137   2              }
 138   1              else
 139   1              {
 140   2                      if(LEDFlag)
 141   2                              LEDShow(0x7FFF>>LEDIndex);
 142   2                      else
 143   2                              LEDShow(~(0xFFFE<<LEDIndex));
 144   2              }
 145   1              if(LEDIndex==15)
 146   1              {
 147   2                      LEDDirection = !LEDDirection;
 148   2                      if(LEDDirection)        LEDFlag = !LEDFlag;
 149   2              }
 150   1              LEDIndex = (LEDIndex+1)%16;
 151   1      }
 152          
 153          //Mode 5
 154          void Mode_5(void){
 155   1              if(LEDDirection)
 156   1                      LEDShow(0x000F<<LEDIndex);
 157   1              else
 158   1                      LEDShow(0xF000>>LEDIndex);
 159   1              if(LEDIndex==15)
 160   1                      LEDDirection = !LEDDirection;
 161   1          LEDIndex = (LEDIndex+1)%16;
 162   1      }
 163          
 164          //Mode 6
 165          void Mode_6(void){
 166   1              if(LEDDirection)
 167   1                      LEDShow(~(0x000F<<LEDIndex));
 168   1              else
 169   1                      LEDShow(~(0xF000>>LEDIndex));
 170   1              if(LEDIndex==15)
 171   1                      LEDDirection = !LEDDirection;
 172   1              LEDIndex = (LEDIndex+1)%16;
 173   1      }
 174          
 175          //Mode 7
 176          void Mode_7(void)
 177          {
 178   1              if(LEDDirection)
 179   1                      LEDShow(0x003F<<LEDIndex);
C51 COMPILER V8.05a   HURRICANELAMP                                                        11/26/2008 21:07:36 PAGE 4   

 180   1              else
 181   1                      LEDShow(0xFC00>>LEDIndex);
 182   1              if(LEDIndex==9)
 183   1                      LEDDirection = !LEDDirection;
 184   1          LEDIndex = (LEDIndex+1)%10;
 185   1      }
 186          
 187          //Mode 8
 188          void Mode_8(void){
 189   1              LEDShow(++LEDIndex);
 190   1      }
 191          
 192          void TimerEventRun(void){
 193   1              if(RunMode==0x00){
 194   2                      Mode_0();       
 195   2              }
 196   1              else if(RunMode ==0x01){
 197   2                      Mode_1();
 198   2              }
 199   1              else if(RunMode ==0x02)
 200   1              {
 201   2                      Mode_2();
 202   2              }
 203   1              else if(RunMode ==0x03){
 204   2                      Mode_3();
 205   2              }
 206   1              else if(RunMode ==0x04){
 207   2                      Mode_4();
 208   2              }
 209   1              else if(RunMode ==0x05)
 210   1              {
 211   2                      Mode_5();
 212   2              }
 213   1              else if(RunMode ==0x06){
 214   2                      Mode_6();
 215   2              }
 216   1              else if(RunMode ==0x07){
 217   2                      Mode_7();
 218   2              }
 219   1              else if(RunMode ==0x08){
 220   2                      Mode_8();
 221   2              }
 222   1      }
 223          
 224          void Timer2(void) interrupt 5 using 3{
 225   1              TF2 = 0;        //中断标志清除( Timer2 必须软件清标志!)
 226   1              if(++TimerCount>=SystemSpeed){
 227   2                      TimerCount = 0;
 228   2                      TimerEventRun();
 229   2              }
 230   1      }
 231          unsigned char MusicIndex = 0;
 232          void KeyDispose(unsigned char Key){
 233   1              if(Key&0x01){
 234   2                      LEDDirection = 1;
 235   2                      LEDIndex = 0;
 236   2                      LEDFlag = 1;
 237   2                      RunMode = (RunMode+1)%9;
 238   2                      Display(RunMode);
 239   2              }
 240   1              if(Key&0x02){
 241   2                      if(SystemSpeedIndex>0){
C51 COMPILER V8.05a   HURRICANELAMP                                                        11/26/2008 21:07:36 PAGE 5   

 242   3                              --SystemSpeedIndex;
 243   3                              SetSpeed(SystemSpeedIndex);
 244   3                      }
 245   2                      else{
 246   3                              LEDFlash(6);
 247   3                      }
 248   2              }
 249   1              if(Key&0x04){
 250   2                      if(SystemSpeedIndex<28){
 251   3                              ++SystemSpeedIndex;
 252   3                              SetSpeed(SystemSpeedIndex);
 253   3                      }
 254   2                      else{
 255   3                              LEDFlash(6);
 256   3                      }
 257   2              }       
 258   1      }
 259          
 260          //***********************************************************************************
 261          main(){
 262   1              unsigned char Key;
 263   1              InitialCPU();
 264   1              InitialTimer2();
 265   1      
 266   1              while(1){
 267   2                      Key = GetKey();
 268   2                      if(Key!=0x00){
 269   3                              KeyDispose(Key);
 270   3                      }
 271   2              }
 272   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1006    ----
   CONSTANT SIZE    =     77    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     10       4
   IDATA SIZE       =   ----    ----
   BIT SIZE         =      2       1
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

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