智慧小車實訓之STM32 -- 點亮LED燈
阿新 • • 發佈:2018-11-12
原理圖:
實現程式碼
light.h
#ifndef __LIGHT_H
#define __LIGHT_H
#include <sys.h>
#define LED1 PDout(0)
#define LED2 PDout(1)
#define LED3 PDout(3)
void LED_init(void);
#endif
light.c
#include "sys.h" #include "light.h" void LED_init() { GPIO_InitTypeDef GPIO_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);//´ò¿ªÊ±ÖÓ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_3; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;//Êä³ö¹¦ÄÜ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//ÍÆÍìÊäÈë GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//ÉÏÀ GPIO_Init(GPIOD, &GPIO_InitStructure);//³õʼ»¯D¶Ë¿Ú }
main.c
#include "stm32f4xx.h"
#include "usart.h"
#include "delay.h"
#include "light.h"
int main(void)
{
delay_init(168);
LED_init();
LED1 = 0;
LED2 = 1;
LED3 = 0;
while(1)
{
LED1 = ~LED1;
LED2 = ~LED2;
LED3 = ~LED3;
delay_ms(1000);
}
return 0;
}
效果LED1和LED3同步每個1秒閃爍,同時LED2交替閃爍(LED在液晶屏右下方)