LED灯的基本控制

题目要求

首先让8路LED指示灯闪烁3遍然后熄灭,接着依次点亮LED指示灯,最后依次熄灭LED灯,程序循环实现上述功能。

分析设计

原理图:
原理图
74HC138
首先应该选通Y4C,也就是ABC = 100。

代码

#include <regx52.h>
#define uchar unsigned char 
#define uint unsigned int
	
void HC138(uchar channel)
{
	switch (channel)
	{
		case 4:
			P2 = (P2 & 0x1f) | 0x80;
		break;
		case 5:
			P2 = (P2 & 0x1f) | 0xa0;
		break;
		case 6:
			P2 = (P2 & 0x1f) | 0xc0;
		break;
		case 7:
			P2 = (P2 & 0x1f) | 0xe0;
		break;
	}
}

void Delay(uint t) 
{
	while (t -- ) ;
	while (t -- ) ;
}

void LED_3()
{
	int i;
	for (i = 0; i < 3; i ++ )
	{
		P0 = 0x00;
		Delay(60000);
		Delay(60000);
		P0 = 0xff;
		Delay(60000);
		Delay(60000);
	}
}

void LED() 
{
	int i;
	LED_3();
	
	for (i = 0; i < 8; i ++ ) 
	{
		P0 = 0xfe << i;
		Delay(60000);
		Delay(60000);
	}
	
	for (i = 0; i < 8; i ++ )
	{
		P0 |= 0x01 << i;
		Delay(60000);
		Delay(60000);
	}
}

void main()
{
	HC138(4);
	while(1)
	{
		LED();
	}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值