利用STM32系列开发板与计算机Keil编程设计,载入程序以实现目标:
LED灯闪烁模式自动轮换------模式1:流水灯从左到右,从右到左依次闪烁三次
模式2:全部流水灯闪烁五次
模式3:流水灯编号1、3与流水灯编号2、4,依次闪烁三次
模式4:"流水灯1->流水灯4->流水灯2->流水灯3"依次点亮,循环四次
简单提供代码思路如下:
cpp
#include "stm32f4xx.h"
#include "led.h"
#include "delay.h"
void led_flow_once(void) {
LED0(1); Delay_ms(500); LED0(0);
LED1(1); Delay_ms(500); LED1(0);
LED2(1); Delay_ms(500); LED2(0);
LED3(1); Delay_ms(500); LED3(0);
LED3(1); Delay_ms(500); LED3(0);
LED2(1); Delay_ms(500); LED2(0);
LED1(1); Delay_ms(500); LED1(0);
LED0(1); Delay_ms(500); LED0(0);
}
void led_all_blink(int n) {
for(int i=0; i<n; i++){
LED0(1); LED1(1); LED2(1); LED3(1);
Delay_ms(500);
LED0(0); LED1(0); LED2(0); LED3(0);
Delay_ms(500);
}
}
void led_group_blink(int n) {
for(int i=0; i<n; i++){
LED0(1); LED2(1);
LED1(0); LED3(0);
Delay_ms(500);
LED0(0); LED2(0);
LED1(1); LED3(1);
Delay_ms(500);
}
LED0(0); LED1(0); LED2(0); LED3(0);
}
void led_order_1423(int n) {
for(int i=0; i<n; i++){
LED0(1); Delay_ms(500); LED0(0);
LED3(1); Delay_ms(500); LED3(0);
LED1(1); Delay_ms(500); LED1(0);
LED2(1); Delay_ms(500); LED2(0);
}
}
int main(void)
{
LED_Hardware_Init();
Delay_Init();
while (1)
{
for(int i=0; i<3; i++){
led_flow_once();
}
led_all_blink(5);
led_group_blink(3);
led_order_1423(4);
}
}