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

📄 音乐跑马灯.lst

📁 一共有九种模式
💻 LST
📖 第 1 页 / 共 5 页
字号:
C51 COMPILER V8.02   __乐跑马灯                                                            12/14/2008 18:54:51 PAGE 1   


C51 COMPILER V8.02, COMPILATION OF MODULE __乐跑马灯
OBJECT MODULE PLACED IN 音乐跑马灯.OBJ
COMPILER INVOKED BY: D:\Program Files\Keil\C51\BIN\C51.EXE 音乐跑马灯.c BROWSE DEBUG OBJECTEXTEND

line level    source

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

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

 118          void Mode_2(void)
 119          {
 120   1              if(LEDDirection)
 121   1                      LEDShow(0x0001<<LEDIndex);
 122   1              else
 123   1                      LEDShow(0x8000>>LEDIndex);
 124   1              if(LEDIndex==15)
 125   1                      LEDDirection = !LEDDirection;
 126   1         LEDIndex = (LEDIndex+1)%16;
 127   1      }
 128          //Mode 3
 129          void Mode_3(void)
 130          {
 131   1              if(LEDDirection)
 132   1                      LEDShow(~(0x0001<<LEDIndex));
 133   1              else
 134   1                      LEDShow(~(0x8000>>LEDIndex));
 135   1              if(LEDIndex==15)
 136   1                      LEDDirection = !LEDDirection;
 137   1         LEDIndex = (LEDIndex+1)%16;
 138   1      }
 139          
 140          //Mode 4
 141          void Mode_4(void)
 142          {
 143   1              if(LEDDirection)
 144   1              {
 145   2                      if(LEDFlag)
 146   2                              LEDShow(0xFFFE<<LEDIndex);
 147   2                      else
 148   2                              LEDShow(~(0x7FFF>>LEDIndex));
 149   2              }
 150   1              else
 151   1              {
 152   2                      if(LEDFlag)
 153   2                              LEDShow(0x7FFF>>LEDIndex);
 154   2                      else
 155   2                              LEDShow(~(0xFFFE<<LEDIndex));
 156   2              }
 157   1              if(LEDIndex==15)
 158   1              {
 159   2                      LEDDirection = !LEDDirection;
 160   2                      if(LEDDirection)        LEDFlag = !LEDFlag;
 161   2              }
 162   1              LEDIndex = (LEDIndex+1)%16;
 163   1      }
 164          
 165          //Mode 5
 166          void Mode_5(void)
 167          {
 168   1              if(LEDDirection)
 169   1                      LEDShow(0x000F<<LEDIndex);
 170   1              else
 171   1                      LEDShow(0xF000>>LEDIndex);
 172   1              if(LEDIndex==15)
 173   1                      LEDDirection = !LEDDirection;
 174   1          LEDIndex = (LEDIndex+1)%16;

⌨️ 快捷键说明

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