#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit fengmingqi=P0^0; //声明IO口
void delay(uint x)//延时子函数
{
uint i,j;
for(i=x;i>0;i--)
for(j=50;j>0;j--);
}
void main(void)
{
while(1) //循环
{
fengmingqi=1; //p0.0口高电平,蜂鸣器发声
delay(500); //延时
fengmingqi=0; //p0.0口低电平,蜂鸣器不发声
delay(500); //延时
}
} |