• Linux编程实现蜂鸣器演奏康定情歌


    Linux编程实现蜂鸣器演奏康定情歌

     
    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. }   
  • 相关阅读:
    一、Git安装
    三、ASP.NET Core 部署Linux 第二篇(Core SDK 3.1)
    .net core 3.1
    一、GitHub创建仓并提交项目
    二、GitHub创建仓并提交项目
    django xdmin使用
    python logging一个通用的使用模板
    一则小脚本(工作中用)
    jmeter 压测最近的心得体会
    jmeter 分布式实战
  • 原文地址:https://www.cnblogs.com/LiuYanYGZ/p/10190881.html
Copyright © 2020-2023  润新知