51单片机爱心流水灯代码
时间: 2023-11-07 13:04:31 浏览: 187
51单片机流水灯代码
以下是51单片机爱心流水灯的代码示例:
```c
#include <reg52.h>
sbit led0 = P1^0;
sbit led1 = P1^1;
sbit led2 = P1^2;
sbit led3 = P1^3;
sbit led4 = P1^4;
sbit led5 = P1^5;
sbit led6 = P1^6;
sbit led7 = P1^7;
void delay(unsigned int t) {
unsigned int i, j;
for (i = t; i > 0; i--)
for (j = 110; j > 0; j--);
}
void main() {
while (1) {
led0 = 0;
delay(10);
led1 = 0;
delay(10);
led2 = 0;
delay(10);
led3 = 0;
delay(10);
led4 = 0;
delay(10);
led5 = 0;
delay(10);
led6 = 0;
delay(10);
led7 = 0;
delay(10);
led0 = 1;
delay(10);
led1 = 1;
delay(10);
led2 = 1;
delay(10);
led3 = 1;
delay(10);
led4 = 1;
delay(10);
led5 = 1;
delay(10);
led6 = 1;
delay(10);
led7 = 1;
delay(10);
}
}
```
请注意,以上示例代码使用的是P1口作为LED灯的控制引脚,具体根据你的硬件连接情况进行调整。每个ledx变量对应一个LED灯的控制引脚,通过将其赋值为0来点亮LED灯。
阅读全文