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

📄 music.lst

📁 用51单片机播放音乐《天空之城》
💻 LST
字号:
C51 COMPILER V7.20   MUSIC                                                                 05/15/2009 12:13:02 PAGE 1   


C51 COMPILER V7.20, COMPILATION OF MODULE MUSIC
OBJECT MODULE PLACED IN music.OBJ
COMPILER INVOKED BY: D:\Program Files\Keil\C51\BIN\C51.EXE music.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          #include <reg52.h>
   2          #define uint unsigned int
   3          #define uchar unsigned char
   4          typedef bit BOOL  ; 
   5          
   6          sbit voice=P2^0;
   7          sbit rs = P2^6 ; 
   8          sbit rw = P3^6 ;
   9          sbit ep = P2^7 ;
  10          
  11          uchar code sound[]={0xff,
  12                              0x1c,0x30,0x19,0x30,0x18,0x40,0x19,0x30,0x18,0x30,0x13,0x30,0x19,0x80,
  13                              0x26,0x30,0x26,0x30,0x1c,0x40,0x20,0x30,0x1c,0x30,0x18,0x30,0x20,0x60,
  14                              0x26,0x30,0x26,0x30,0x24,0x40,0x26,0x30,0x24,0x30,0x18,0x40,0x26,0x60,
  15                              0x18,0x20,0x18,0x20,0x18,0x20,0x19,0x40,0x24,0x30,0x24,0x30,0x19,0x30,
  16                              0x19,0x60,0x1c,0x30,0x19,0x30,0x18,0x40,0x19,0x30,0x18,0x30,0x13,0x30,
  17                              0x19,0x60,0x26,0x30,0x26,0x30,0x1c,0x40,0x20,0x30,0x1c,0x30,0x18,0x30,
  18                              0x20,0x80,0x26,0x30,0x24,0x30,0x24,0x30,0x18,0x30,0x19,0x20,0x19,0x30,
  19                              0x18,0x30,0x15,0x20,0x15,0x20,0x13,0x20,0x18,0x40,0x18,0x30,0x19,0x30,
  20                              0x1c,0x20,0x1c,0x20,0x19,0x30,0x20,0x30,0x1c,0x60,0x18,0x30,0x15,0x30,
  21                              0x13,0x40,0x15,0x30,0x13,0x30,0x10,0x30,0x15,0x60,0x20,0x30,0x20,0x30,
  22                              0x18,0x30,0x19,0x30,0x18,0x30,0x13,0x30,0x13,0x60,0x1c,0x20,0x19,0x20,
  23                              0x18,0x30,0x19,0x30,0x15,0x20,0x15,0x20,0x18,0x40,0x20,0x30,0x20,0x30,
  24                              0x12,0x30,0x13,0x30,0x15,0x30,0x18,0x30,0x13,0xc0,0x13,0x80,0x13,0x30,
  25                              0x0e,0x80,0x10,0x30,0x10,0x30,0x13,0x20,0x15,0x20,0x18,0x40,0x18,0x30,
  26                              0x15,0x30,0x18,0x20,0x15,0x20,0x15,0x30,0x10,0x30,0x13,0x60,0x13,0x30,
  27                              0x0e,0x60,0x10,0x60,0x13,0x20,0x15,0x20,0x18,0x40,0x18,0x30,0x15,0x30,
  28                              0x15,0x20,0x18,0x20,0x15,0x30,0x19,0x30,0x1c,0x60,0x1c,0x30,0x19,0x30,
  29                              0x1c,0xc0,0x00,
  30                             };
  31                                             
  32          void delay(uchar) ;
  33          void lcd_wcmd(uchar) ;
  34          BOOL lcd_bz() ;
  35          void lcd_pos(uchar) ;
  36          void lcd_wdat(uchar) ;
  37          void display(uchar,uchar *) ;
  38          
  39          code uchar  dis1[] = {"LOVECCNU"} ;
  40          code uchar  dis2[] = {" MUSIC! "} ;
  41                                             
  42          void longdelay(uchar s)  //长延时
  43          {
  44   1               while(s--)
  45   1               {
  46   2                      delay(60) ;
  47   2               }
  48   1      }
  49          
  50          void delay(uchar ms)
  51          {       // 延时子程序
  52   1               uchar i ;
  53   1               while(ms--)
  54   1               {
  55   2                      for(i = 0 ; i<250;i++) ;
C51 COMPILER V7.20   MUSIC                                                                 05/15/2009 12:13:02 PAGE 2   

  56   2               }
  57   1      }
  58          
  59          BOOL lcd_bz()
  60          {       // 测试LCD忙碌状态
  61   1               BOOL result ;
  62   1               rs = 0 ;
  63   1               rw = 1 ;
  64   1               ep = 1 ;
  65   1               result = (BOOL)(P0 & 0x80) ;
  66   1               ep = 0 ;
  67   1               return result ; 
  68   1      }
  69          
  70          void lcd_wcmd(uchar cmd)
  71          {       // 写入指令数据到LCD
  72   1              while(lcd_bz()) ;
  73   1              rs = 0 ;
  74   1              rw = 0 ;
  75   1              ep = 0 ;
  76   1              P0 = cmd ;
  77   1              ep = 1 ;
  78   1              ep = 0 ;  
  79   1      }
  80          
  81          void lcd_pos(uchar pos)
  82          {       //设定显示位置
  83   1              lcd_wcmd(pos | 0x80) ;
  84   1      }
  85          
  86          void lcd_wdat(uchar dat) 
  87          {       //写入字符显示数据到LCD
  88   1              while(lcd_bz()) ;
  89   1              rs = 1 ;
  90   1              rw = 0 ;
  91   1              ep = 0 ;
  92   1              P0 = dat ;
  93   1              ep = 1 ;
  94   1              ep = 0 ; 
  95   1      }
  96          
  97          void lcd_init()
  98          {       //LCD初始化设定
  99   1               lcd_wcmd(0x38) ;   //function set
 100   1               delay(1) ;
 101   1               lcd_wcmd(0x38) ;   //function set
 102   1               delay(1) ;
 103   1               lcd_wcmd(0x08) ;   //display on/off
 104   1               delay(1) ;
 105   1               lcd_wcmd(0x01) ;   //清除LCD的显示内容
 106   1               delay(1) ;
 107   1               lcd_wcmd(0x06) ;   //entry mode set
 108   1               delay(1) ;
 109   1               lcd_wcmd(0x0c) ;   //entry mode set
 110   1               delay(1) ;
 111   1      }
 112          
 113          /*---------------
 114          函数名称:display()
 115          功能 :在LCD上显示数组的数据
 116          说明 :先写显示地址,后写显示数据
 117          调用 :lcd_wcmd(), lcd_pos()
C51 COMPILER V7.20   MUSIC                                                                 05/15/2009 12:13:02 PAGE 3   

 118          入口参数:pos 写入的位置,q指向要写入的数据所在的数组
 119          返回值 :无
 120          ----------------*/
 121          void display(uchar pos, uchar *q)
 122          { 
 123   1               uchar i ;
 124   1               //lcd_wcmd(0x01) ; //clear 
 125   1               delay(10) ;
 126   1               lcd_pos(pos) ;
 127   1               for(i=0 ;i<16;i++)
 128   1               {
 129   2                        lcd_wdat(*q) ;
 130   2                        q++ ;
 131   2                        longdelay(2) ;
 132   2               } 
 133   1      }
 134                                             
 135                                                  
 136          uchar zdjs=0, jp;
 137          del(yj);
 138          void main(void)
 139            {
 140   1            uint dpjs=0;
 141   1            uchar yj;
 142   1            TMOD=0x01,IE=0x82;
 143   1            TH0=0xd8, TL0=0xef;
 144   1            TR0=1;
 145   1              
 146   1               P1=0xf0;
 147   1               delay(200) ;
 148   1               P1=0xff;
 149   1               lcd_init() ;    // 初始化LCD   
 150   1               delay(10) ;
 151   1               display(0x00,dis1) ;
 152   1               display(0x40,dis2) ;
 153   1               lcd_wcmd(0x07) ;   //entry mode set
 154   1               P1=0xf0;
 155   1      
 156   1      while(1)
 157   1         { 
 158   2           
 159   2            zdjs=0;
 160   2            dpjs++; yj=sound[dpjs]; 
 161   2           dpjs++; jp=sound[dpjs];
 162   2         while(zdjs!=jp)
 163   2             { 
 164   3            if(yj!=0xff)
 165   3         {
 166   4                   if(yj!=0)
 167   4                     {
 168   5                   voice=!voice;
 169   5                       del(yj);
 170   5                      }
 171   4                      else
 172   4                {
 173   5                dpjs=0; 
 174   5                            break;
 175   5                           }
 176   4          }
 177   3          else
 178   3            {
 179   4              voice=0;
C51 COMPILER V7.20   MUSIC                                                                 05/15/2009 12:13:02 PAGE 4   

 180   4                       del(jp);
 181   4          }
 182   3            }
 183   2             }
 184   1         }
 185          time0() interrupt 1  using 1
 186                {
 187   1               TH0=0xd8, TL0=0xef;
 188   1               zdjs++;
 189   1                 }
 190          del(yj)
 191              {
 192   1            uchar yj2=2;
 193   1             while(yj!=0)
 194   1               {      
 195   2                     while(yj2!=0)
 196   2                        {
 197   3                           yj2--;
 198   3                           }
 199   2                        yj2=2;
 200   2                   yj--;  
 201   2             }
 202   1         
 203   1           }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    382    ----
   CONSTANT SIZE    =    260    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =      2       8
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----       1
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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