单片机开发之声光报警Helloworld

代码如下:

// Header:
// File Name: 声光报警程序
// Author:	NEIL
// Date:  

#include<reg52.h>
#include <intrins.h>
sbit LED_OPEN = P2^3;//定义LED脚管
sbit beep=P2^0;//定义蜂鸣器脚管


void delayms(unsigned char ms)	
// 延时子程序
{						
	unsigned char i;
	while(ms--)
	{
		for(i = 0; i < 240; i++);
	}
}

main()
{
	unsigned char LED;
	LED_OPEN=0;
	beep=0;
	LED = 0xfe;
	P0 = 0x00;
	
	while(1)
	{
		beep=0;
		P0 =LED;
		delayms(240);
		beep=1;
		delayms(240);			
		LED = _crol_(LED,1);//循环右移1位,点亮下一个LED
		
		
	}
}

你可能感兴趣的:(Date,header,File)