蓝桥杯板子完成一个花式流水灯 :①L1-L8全部一起闪烁三次 ; ②L1闪烁三次 ③ L1---L8--L1-L8往返流水灯三次 ④ 从最两端的两个LED流向中间,再流向两边,重复三重复②--- ④ 的过程。
时间: 2023-05-14 16:07:01 浏览: 130
以下是实现花式流水灯的代码:
```c
#include <reg52.h>
sbit L1 = P1^0;
sbit L2 = P1^1;
sbit L3 = P1^2;
sbit L4 = P1^3;
sbit L5 = P1^4;
sbit L6 = P1^5;
sbit L7 = P1^6;
sbit L8 = P1^7;
void delay(unsigned int t)
{
while(t--);
}
void all_flash(int n)
{
int i;
while(n--)
{
L1 = L2 = L3 = L4 = L5 = L6 = L7 = L8 = 0;
delay(50000);
L1 = L2 = L3 = L4 = L5 = L6 = L7 = L8 = 1;
delay(50000);
}
}
void L1_flash(int n)
{
int i;
while(n--)
{
L1 = 0;
delay(50000);
L1 = 1;
delay(50000);
}
}
void flow_flash(int n)
{
int i;
while(n--)
{
L1 = 0;
L2 = 0;
L3 = 0;
L4 = 0;
L5 = 0;
L6 = 0;
L7 = 0;
L8 = 0;
delay(50000);
L1 = 1;
delay(50000);
L2 = 1;
delay(50000);
L3 = 1;
delay(50000);
L4 = 1;
delay(50000);
L5 = 1;
delay(50000);
L6 = 1;
delay(50000);
L7 = 1;
delay(50000);
L8 = 1;
delay(50000);
L8 = 0;
delay(50000);
L7 = 0;
delay(50000);
L6 = 0;
delay(50000);
L5 = 0;
delay(50000);
L4 = 0;
delay(50000);
L3 = 0;
delay(50000);
L2 = 0;
delay(50000);
L1 = 0;
delay(50000);
L1 = 1;
delay(50000);
L2 = 1;
delay(50000);
L3 = 1;
delay(50000);
L4 = 1;
delay(50000);
L5 = 1;
delay(50000);
L6 = 1;
delay(50000);
L7 = 1;
delay(50000);
L8 = 1;
delay(50000);
}
}
void wave_flash(int n)
{
int i;
while(n--)
{
L1 = 0;
L8 = 0;
delay(50000);
L2 = 0;
L7 = 0;
delay(50000);
L3 = 0;
L6 = 0;
delay(50000);
L4 = 0;
L5 = 0;
delay(50000);
L5 = 1;
L4 = 1;
delay(50000);
L6 = 1;
L3 = 1;
delay(50000);
L7 = 1;
L2 = 1;
delay(50000);
L8 = 1;
L1 = 1;
delay(50000);
}
}
void main()
{
all_flash(3);
L1_flash(3);
flow_flash(3);
wave_flash(3);
}
```
这个代码实现了题目中要求的四个花式流水灯效果。
阅读全文