c语言实现单片机心形流水灯
时间: 2023-05-15 13:07:36 浏览: 125
单片机心形流水灯
以下是一个简单的 C 语言代码实现单片机心形流水灯:
```c
#include <reg52.h>
sbit LED1 = P1^0;
sbit LED2 = P1^1;
sbit LED3 = P1^2;
sbit LED4 = P1^3;
sbit LED5 = P1^4;
sbit LED6 = P1^5;
sbit LED7 = P1^6;
sbit LED8 = P1^7;
void delay(unsigned int t) {
while(t--);
}
void main() {
while(1) {
LED1 = 1;
delay(50000);
LED2 = 1;
delay(50000);
LED3 = 1;
delay(50000);
LED4 = 1;
delay(50000);
LED5 = 1;
delay(50000);
LED6 = 1;
delay(50000);
LED7 = 1;
delay(50000);
LED8 = 1;
delay(50000);
LED1 = 0;
delay(50000);
LED2 = 0;
delay(50000);
LED3 = 0;
delay(50000);
LED4 = 0;
delay(50000);
LED5 = 0;
delay(50000);
LED6 = 0;
delay(50000);
LED7 = 0;
delay(50000);
LED8 = 0;
delay(50000);
}
}
```
这个代码使用了 8 个 LED 灯,通过循环控制每个 LED 灯的亮灭来实现心形流水灯的效果。
阅读全文