点亮LED灯

1、点亮一个LED灯

#include <REGX52.H>

void main()
{
	 P1=0xfe;//1111 1110
}

2、一个LED闪烁

#include <REGX52.H>
#include <INTRINS.H>

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)
{
	P1=0xFE;
	Delay500ms();
	P1=0xFf;
	Delay500ms();
	
}
}

3、LED流水灯

#include <REGX52.H>
#include <INTRINS.H>

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)
	{
		P1=0xfe;//1111 1110
		Delay500ms();
		P1=0xfd;//1111 1101
		Delay500ms();
		P1=0xfb;//1111 1011
		Delay500ms();
		P1=0xf7;//1111 0111
		Delay500ms();
		P1=0xef;//1110 1111
		Delay500ms();
		P1=0xdf;//1101 1111
		Delay500ms();
		P1=0xbe;//1011 1111
		Delay500ms();
		P1=0x7f;//0111 1111
		Delay500ms();
		
	}
}

4、LED流水灯plus

#include <REGX52.H>

#include <INTRINS.H>


void Delay1ms(unsigned int xms)		//@11.0592MHz
{
	unsigned char i, j;
	while(xms)
	{
		_nop_();
		i = 2;
		j = 199;
	do
	{
		while (--j);
	} while (--i);
		xms--;
	}
}
void mian()
{
		while(1)
		{
			P1=0xfe;//1111 1110
			Delay1ms(500);
			P1=0xfd;//1111 1101
			Delay1ms(500);
			P1=0xfb;//1111 1011
			Delay1ms(500);
			P1=0xf7;//1111 0111
			Delay1ms(500);
			P1=0xef;//1110 1111
			Delay1ms(500);
			P1=0xdf;//1101 1111
			Delay1ms(500);
			P1=0xbe;//1011 1111
			Delay1ms(500);
			P1=0x7f;//0111 1111
			Delay1ms(500);
		}
}