扬声器发声

#include <sys/io.h>
#include <unistd.h>

void play(unsigned int* freq, unsigned int* delay);

int main()
{
    int i;

     unsigned int freq_alert[]={
                262,294,262,294,0};

    unsigned int time_alert[]={
             12,12,12,12};

       for(i = 0; i < 1; i++)
            {
        play(freq_alert, time_alert);
            }

     return 0;
}

void play(unsigned int* freq, unsigned int* time)
{
    int i;
    for(i=0;freq[i]!=0;i++)
            {
        speaker(freq[i], time[i]);
            }
}

int speaker(unsigned int freq,unsigned int delay)
{
    static int flag=0,bit;
   if(flag==0)
        {
       flag=1;
       iopl(3);
        }    
    outb(0xb6,0x43);
    outb((freq & 0xff),0x42);
    outb((freq >> 8),0x42);
    bit=inb(0x61);
    outb(3 | bit,0x61);
    usleep(40000*delay);
    outb(0xfc | bit,0x61);
}










posted on 2012-08-25 16:22  小风儿_xf  阅读(132)  评论(0编辑  收藏  举报

导航