这是一个控制电机的程序。当子程序Void duqi执行时 ,就是当有有毒气体电机会正转,但是想要在这里加一个蜂鸣器函数,毕竟有毒气体有危险。该怎么加啊 ,蜂鸣器的口是P2^3 以下是我的程序 求帮助
#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit zheng_key=P3^5;
sbit fan_key=P3^6;
sbit jiance_key1=P3^7;
sbit jiance_key2=P3^4;
sbit jiance_key3=P3^3;
sbit LED1=P1^5;
sbit LED2=P1^6;
sbit FM=P2^3;
uchar num,flag=0,table_begin;
uchar code table[]={0xf1,0xf2,0xf4,0xf8,0xf8,0xf4,0xf2,0xf1};//Õy·′×a¸ßμíμçƽ¶Ôó|±í
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=125;y>0;y--);
}
void key()
{
uchar j;
if(flag==0)
{
if(jiance_key1==0||jiance_key2==0||jiance_key3==0)//°′¼üÄ£Äa′«¸DÆ÷¼ì2a
{
flag=1; //×Ô¶ˉêÖ¶ˉÇD»»±ê־λ,ÇD»»ÎaêÖ¶ˉ
delay(50);
if(jiance_key1==0||jiance_key2==0||jiance_key3==0)
{
table_begin=0;//Õy×a
while(!(jiance_key1||jiance_key2||jiance_key3))
{
for(j=0+table_begin;j<4+table_begin;j++)
{
P1=table[j];
delay(5);
}
}
}
}
}
if(flag==1)//êÖ¶ˉÄ£ê½
{
if(zheng_key==0)
{
delay(50);
if(zheng_key==0)
{
table_begin=0;//Õy×a
while(!zheng_key)
{
for(j=0+table_begin;j<4+table_begin;j++)
{
P1=table[j];
delay(5);
}
}
}
}
if(fan_key==0)
{
delay(50);
if(fan_key==0)
{
table_begin=4;//·′×a
while(!fan_key)
{
for(j=0+table_begin;j<4+table_begin;j++)
{
P1=table[j];
delay(5);
}
}
}
}
}
}
void duqi()
{
uchar j;
if(LED1==0)
table_begin=4;
while(!LED1)
{
for(j=0+table_begin;j<4+table_begin;j++)
{
P1=table[j];
delay(5);
}
}
}
void yudi()
{
uchar j;
if(LED2==0)
table_begin=0;
while(!LED2)
{
for(j=0+table_begin;j<4+table_begin;j++)
{
P1=table[j];
delay(5);
}
}
}
void main()
{
while(1)
{
key();
duqi();
yudi();
}
}
|