欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

三种简单易懂的方法教你如何使用51单片机制作流水灯效果,一文详解数组流水灯

最编程 2024-01-29 09:27:43
...

定义一组数组分别对应点亮LED1~7
然后利用for循环赋值给p2从而实现流水灯

#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table[8] = {0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; //数组
 

// 函数功能:毫秒延时
void delay(uint z)
{
	uint x,y;
	for(x = 0; x < z; x++)
		for(y = 0; y < 113; y++);
}

void main()
{
	uchar i;
	while(1)
	{
		for(i=0;i<8;i++)
		{
			P2 = table[i];
			delay(300);
		}
		
	}
}

数组流水灯