Linux編程實現蜂鳴器演奏康定情歌

來源:互聯網
上載者:User
 
  1. #include   <sys/io.h>  
  2. #include   <unistd.h>  
  3. void   play(unsigned   int*   freq,   unsigned   int*   delay);  
  4. main()  
  5. {  
  6.       int   i;  
  7.       unsigned   int   freq[]={   330   ,   392   ,   330   ,   294   ,   330   ,   392   ,  
  8.               330   ,   394   ,   330   ,   330   ,   392   ,   330   ,  
  9.               294   ,   262   ,   294   ,   330   ,   392   ,   294   ,  
  10.               262   ,   262   ,   220   ,   196   ,   196   ,   220   ,  
  11.               262   ,   294   ,   330   ,   262   ,   0   }   ;  
  12.       unsigned   int   time[]={   50   ,   50   ,   50   ,   25   ,   25   ,   50   ,  
  13.               25   ,   25   ,   100,   50   ,   50   ,   25   ,  
  14.               25   ,   50   ,   50   ,   25   ,   25   ,   100,  
  15.               50   ,   25   ,   25   ,   50   ,   25   ,   25   ,  
  16.               50   ,   25   ,   25   ,   100   };  
  17.       unsigned   int   freq2[]={  
  18.               196,262,262,262,330,294,262,294,330,294,262,  
  19.               330,394,440,440,394,330,330,262,294,262,294,  
  20.               330,294,262,230,230,196,262,440,394,330,330,  
  21.               262,294,262,294,440,394,330,330,394,440,523,  
  22.               394,330,330,262,294,262,294,330,294,262,230,  
  23.               230,196,262,440,394,330,330,262,294,262,294,  
  24.               440,394,330,330,394,440,523,394,330,330,262,  
  25.               294,262,294,330,294,262,230,230,196,262,0  
  26.       };  
  27.       unsigned   int   time2[]={  
  28.               25,38,12,25,25,38,12,25,12,12,56,25,25,50,25,  
  29.               38,12,12,12,38,12,25,12,12,38,12,25,25,100,25,  
  30.               38,12,12,12,38,12,25,25,38,12,25,25,100,25,38,  
  31.               12,12,12,38,12,25,12,12,38,12,25,25,100,25,38,  
  32.               12,12,12,38,12,25,25,38,12,25,25,100,25,38,12,  
  33.               12,12,38,12,25,12,12,38,12,25,25,100  
  34.       };  
  35. unsigned   int   freq_alert[]={  
  36.               2000,   2400,   0  
  37.       };  
  38.       unsigned   int   time_alert[]={  
  39.               50,   60  
  40.       };  
  41.       for(i   =   0;   i   <   5;   i++)  
  42.       {  
  43.               play(freq_alert,   time_alert);  
  44.       }  
  45.       play(freq2,   time2);  
  46. }  
  47. void play(unsigned   int*   freq,   unsigned   int*   time)  
  48. {  
  49.       int   i;  
  50.       for(i=0;freq[i]!=0;i++)  
  51.       {  
  52.               speaker(freq[i],   time[i]);  
  53.       }  
  54. }  
  55. int speaker(unsigned   int   freq,unsigned   int   delay)  
  56. {     
  57.     static   int   flag=0,bit;  
  58.     if(fl   ag==0)  
  59.     {  
  60.           flag=1;  
  61.           iopl(3);  
  62.     }  
  63.     outb(0xb6,0x43);  
  64.     outb((freq & 0xff),     0x42);  
  65.     outb((freq>>8), 0x42);  
  66.     bit=inb(0x61);  
  67.     outb(3   |   bit,0x61);  
  68.     usleep(10000*delay);  
  69.     outb(0xfc   |   bit,0x61);  
  70. }   
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.