蜂鸣器
#include
#define uchar unsigned char
#define uint unsigned int
int a,b;
intcodetable[]={63628,63835,64021,64103,64260,64331,64400,64524};
int code yinfu[][2]={{5,5000},{5,2000},{6,5000},{2,5000},{1,5000},{1,2000},{6,5000},{2,5000},
{5,5000},{5,5000},{6,2000},{1,5000},{6,2000},{5,5000},{1,5000},{1,2000},{6,2000},{2,5000},
{5,5000},{2,5000},{1,5000},{7,2000},{6,5000},{5,5000},
{5,5000},{2,5000},{3,2000},{2,5000},{1,5000},{1,2000},{6,5000},{2,2000},{3,5000},{2,2000},
{1,5000},{2,2000},{1,5000},{7,2000},{6,5000},{5,5000}
};
sbit beep=P2^7;
sbit key1=P2^0;
sbit key2=P2^1;
sbit key3=P2^2;
sbit key4=P2^4;
int sum;
int dbc(int i)
{
TR0=1;
sum=table[i];
}
void delay(uint x)
{
int i,j;
for(i=x;i>0;i--)
{
for(j=110;j>0;j--);
}
}
void init()
{
TMOD=0x01;
TH0=sum/256;
TL0=sum%256;
EA=1;
ET0=1;
}
void t0_time() interrupt 1
{
TH0=sum/256;
TL0=sum%256;
beep=~beep;
}
void keyscan()
{
if(key1==0)
{
delay(10);
if(key1==0)
{
dbc(0);
}
}
if(key2==0)
{
delay(10);
if(key2==0)
{
dbc(1);
}
}
if(key3==0)
{
delay(10);
if(key3==0)
{
dbc(2);
}
}
if(key4==0)
{
delay(10);
if(key4==0)
{
dbc(3);
}
}
if(P2==0xff)
{
TR0=0;
beep=1;
}
}
void main()
{
int s,k;
k=0;
init();
while(1)
{
keyscan();
while(k<40)
{
for(s=yinfu[k][1];s>0;s--)
dbc(yinfu[k][0]);
k++;
}
}
}