
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit SPK=P1^6;
sbit K1=P1^7;
sbit S1=P1^0;
sbit S2=P1^1;
sbit S3=P1^2;
sbit LED1=P0^0;
sbit LED2=P0^1;
sbit LED3=P0^2;
int main()
{
void print_led();
void Alarm(uchar t);
print_led();
SPK=0;
while (1)
{
if(K1==1)
{
Alarm(90);
Alarm(120);
}
}
}
void print_led()
{
while(1)
{
LED1=S1;
LED2=S2;
LED3=S3;
}
}
//发声函数
void Alarm(uchar t)
{
uchar i,j;
for(i=0;i<200;i++)
{
SPK=~SPK;
for(j=0;j<t;j++);//由参数t行成不同的频率
}
}
