LED小灯闪烁程序


//LED闪烁程序

#include<reg52.h>

sbit LED = P0^ 0;

sbit ADDR0 = P1 ^ 0;
sbit ADDR1 = P1 ^ 1;
sbit ADDR2 = P1 ^ 2;
sbit ADDR3 = P1 ^ 3;

sbit ENLED = P1 ^ 4;

void main(void)
{
	int i = 0;//定义整形变量用于后面计数延时
    
    //74HC138芯片使能
	ENLED = 0;
	ADDR3 = 1;

    //三极管Q16导通
	ADDR2 = 1;
	ADDR1 = 1;
	ADDR0 = 0;

	while (1)
	{
		LED = 0;//小灯打开

		for (i = 0; i < 9000; i++)//延时
			;

		LED = 1;//小灯关闭

		for (i = 0; i < 9000; i++)//延时
			;
	}
}

//LED闪烁程序

#include<reg52.h>

sbit ADDR0 = P1 ^ 0;
sbit ADDR1 = P1 ^ 1;
sbit ADDR2 = P1 ^ 2;
sbit ADDR3 = P1 ^ 3;

sbit ENLED = P1 ^ 4;

void main(void)
{
	int i = 0;//定义整形变量用于后面计数延时
    
    //74HC138芯片使能
	ENLED = 0;
	ADDR3 = 1;

    //三极管Q16导通
	ADDR2 = 1;
	ADDR1 = 1;
	ADDR0 = 0;

	while (1)
	{
		P0 = 0xFE;//小灯打开

		for (i = 0; i < 9000; i++)//延时
			;

		P0 = 0xFF;//小灯关闭

		for (i = 0; i < 9000; i++)//延时
			;
	}
}