中科因仑“3+1”工程特种兵精英论坛
标题:
蜂鸣器实验程序
[打印本页]
作者:
XJzy
时间:
2015-9-26 22:11
标题:
蜂鸣器实验程序
#include <reg51.h>
#include <intrins.h>
sbit SPK = P3^6;
unsigned char frq;
void delayms(unsigned char ms);
main()
{
TMOD = 0x01;
frq = 0x00;
TH0 = 0x00;
TL0 = 0xff;
TR0 = 1;
IE = 0x82;
while(1)
{
frq++;
delayms(1);
}
}
void timer0() interrupt 1 using 1
{
TH0 = 0xfe;
TL0 = frq;
SPK = ~SPK;
}
void delayms(unsigned char ms)
// 延时子程序
{
unsigned char i;
while(ms--)
{
for(i = 0; i < 120; i++);
}
}
欢迎光临 中科因仑“3+1”工程特种兵精英论坛 (http://bbs.enlern.com/)
Powered by Discuz! X3.4