其他分享
首页 > 其他分享> > 蓝桥杯单片机CT107D_01_LED

蓝桥杯单片机CT107D_01_LED

作者:互联网

#include<reg52.h>

void Delay(unsigned int t)
{
	while(t--);
	while(t--);
}

void Select_HC138(unsigned char n)
{
	switch(n)
	{
		case 4:
			P2 = (P2 & 0x1f) | 0x80;	 //控制LED
			break;
		case 5:
			P2 = (P2 & 0x1f) | 0xa0;     //控制蜂鸣器
			break;
	}
}

void LED()
{
	unsigned char i;
	for(i=0;i<3;i++)
	{
		P0 = 0x00;			 //点亮LED(低电平点亮)
		Delay(60000);
		Delay(60000);
		P0 = 0xff;
		Delay(60000);
		Delay(60000);
	}
	for(i=1;i<=8;i++)
	{
		P0 = 0xff << i;		//依次点亮LED
		Delay(60000);
		Delay(60000);
	}
	for(i=1;i<=8;i++)
	{
		P0 = ~(0xff << i);
		Delay(60000);
		Delay(60000);
	}	
}

void main()
{	
	Select_HC138(5);	
	P0 = 0x00;			//关闭蜂鸣器
	Select_HC138(4);
	while(1)
	{
	   LED();
	}
}

标签:P2,Delay,P0,01,LED,蓝桥,单片机,60000,HC138
来源: https://blog.csdn.net/qq_41412394/article/details/113746824