当前位置:诺佳网 > 电子/半导体 > 嵌入式技术 >

按下不同按键,发出不同频率声音应用设计

时间:2018-01-22 | 栏目:嵌入式技术 | 点击:

/*名称:按键发音

说明:按下不同的按键会是SOUNDER发出不同频率的声音。本例使用延时函数实现不同频率的声音

输出,以后也可使用定时器

*/

#include

#defineucharunsignedchar

#defineuintunsignedint

sbitBEEP=P3^7;

sbitK1=P1^4;

sbitK2=P1^5;

sbitK3=P1^6;

sbitK4=P1^7;

//延时

voidDelayMS(uintx)

{

uchart;

while(x--)for(t=0;t<120;t++);

}

//按周期t发音

voidPlay(uchart)

{

uchari;

for(i=0;i<100;i++)

{

BEEP=~BEEP;

DelayMS(t);

}

BEEP=0;

}

voidmain()

{

P1=0xff;

BEEP=0;

while(1)

{

if(K1==0)Play(1);

if(K2==0)Play(2);

if(K3==0)Play(3);

if(K4==0)Play(4);

}

}

您可能感兴趣的文章:

相关文章