51 单片机学习_1.2 LED闪烁

文章目录

  • 解释
  • 代码

解释

Delay500ms()为一个延时函数,延时0.5s

一次亮与灭之间插入一个延时函数,就能看到LED闪烁

代码

#include 
#include 

void Delay500ms()		//@11.0592MHz
{
	unsigned char i, j, k;

	_nop_();
	i = 4;
	j = 129;
	k = 119;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}


void main(){
	while(1){
		P2 = 0xfe;
		Delay500ms();
		P2 = 0xff;
		Delay500ms();
	}
}

你可能感兴趣的:(单片机实验,51单片机)