单片机C语言程序设计:按键发音

嵌入式系统 时间:2013-06-27来源:网络

/* 名称:按键发音

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

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

*/

#includereg51.h>

#define uchar unsigned char

#define uint unsigned int

sbit BEEP=P3^7;

sbit K1=P1^4;

sbit K2=P1^5;

sbit K3=P1^6;

sbit K4=P1^7;

//延时

void DelayMS(uint x)

{

uchar t;

while(x--) for(t=0;t120;t++);

}

//按周期 t 发音

void Play(uchar t)

{


uchar i;

for(i=0;i100;i++)

{

BEEP=~BEEP;

DelayMS(t);

}

BEEP=0;

}

1 2

关键词: 单片机 C语言 按键发音

加入微信
获取电子行业最新资讯
搜索微信公众号:EEPW

或用微信扫描左侧二维码

相关文章

查看电脑版