三种简单易懂的方法教你如何使用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);
}
}
}
上一篇: 从零开始学STM32 F103:一步步点亮LED流水灯教程
下一篇: 用51单片机制作炫酷流水灯教程