单片机跑马灯12种c语言程序设计,(原创)51单片机C语言程序设计--速学教程实例(入门篇)之流水灯(跑马灯)...
时间: 2023-08-02 13:07:45 浏览: 164
以下是一种基于51单片机的C语言程序设计,用于实现12种不同的跑马灯效果:
```c
#include <reg51.h>
#define LED P1
void delay() {
int i, j;
for(i=0; i<100; i++)
for(j=0; j<100; j++);
}
void main() {
int i, j;
while(1) {
for(i=0; i<12; i++) {
switch(i) {
case 0: LED = 0x01; break;
case 1: LED = 0x02; break;
case 2: LED = 0x04; break;
case 3: LED = 0x08; break;
case 4: LED = 0x10; break;
case 5: LED = 0x20; break;
case 6: LED = 0x40; break;
case 7: LED = 0x80; break;
case 8: LED = 0x10; break;
case 9: LED = 0x08; break;
case 10: LED = 0x04; break;
case 11: LED = 0x02; break;
}
delay();
}
}
}
```
该程序使用了一个循环来遍历12个不同的跑马灯效果。在每次循环中,根据当前迭代的值,将相应的LED灯点亮。程序中使用了一个简单的延迟函数来产生灯效的闪烁。
阅读全文