藍橋杯大賽-嵌入式-基本模組快速總結
【模組一】LCD
Lcd液晶驅動函式的改寫
新增標頭檔案 #include "stdio.h"
格式化顯示
【模組二】LED
void LED_Init(void);
void LED_Control(u16 LED, u8 Status);
void LED_Toggling(u16 LED);
LED 巨集定義從GPIO_Pin_8開始
LED燈亮滅控制
LED燈翻轉(用於閃爍)
【模組三】Timer
參考庫檔案路徑:TIM/TimeBase main.c 、**it.c
void TIM4_Init(void);
void TIM4_IRQHandler(void)
【模組四】KEY
void KEY_Init(void);
void KEY_Read(void);
void KEY_Process(void);
void Status_Update(void);
Key 驅動按鍵模式為輸入浮空
巨集定義
長、短按鍵檢測
根據按鍵情況更新狀態處理完成後,清除以下變數
【模組五】I2C
EEPROM等驅動函式一定要初始化、一定要初始化、一定要初始化
void i2c_init(void);
等待應答函式交換兩行程式碼
新增的讀寫函式
void Write_AT24c02(u8 add, u8 data);
u8 Read_AT24c02(u8 add);
【模組六】RTC
參考庫檔案路徑:
RTC/ Calendar main.c 、**it.c
RTC_IRQHandler()、Time_Display()、Time_Adjust()、NVIC_Configuration()
RTC/ LSI_Calib main.c
RTC_Configuration()
包含以下函式
void RTC_IRQHandler(void)
void Time_Adjust(uint32_t Tmp_HH, uint32_t Tmp_MM, uint32_t Tmp_SS)
void RTC_Configuration(void)
void NVIC_Configuration(void)
RTC初始化配置函式的註釋
註釋BKP_RTCOutputConfig(BKP_RTCOutputSource_Second);
防止下載程式後螢幕左3/4灰屏
解決無法顯示00:00:00的程式碼
修改時間調整函式
RTC中斷
【模組七】UART
參考庫檔案路徑:
USART/Interrupt main.c 、***it.c
RCC_Configuration(); NVIC_Configuration(); GPIO_Configuration(); USART2_IRQHandler();
USART/Printf main.c
PUTCHAR_PROTOTYPE
包含以下函式
void USART2_Init(void)
void USART2_IRQHandler(void)
int fputc(int ch, FILE *f)
串列埠初始化函式
改寫fputc 函式,實現printf格式化輸出函式
串列埠中斷函式
【模組八】ADC
參考庫檔案路徑 :ADC/ADC1_DMA main.c
ADC_Channel8_Init()
100ms採集一次電壓
算術平均濾波法處理
其他簡便的濾波方法:限幅濾波法、中位值濾波法、滑動平均濾波法、中位值平均濾波法、一階滯後濾波法等
【模組九】PWM_Output
參考庫檔案路徑 :
TIM/OCToggle/ main.c ***it.c
RCC_Configuration(); NVIC_Configuration(); GPIO_Configuration();
void TIM3_IRQHandler(void)
包含函式
void TIM3_PWM_Init(void);
void TIM3_PWM_CH1(u32 freq, float duty);
PWM 輸出注意
TIM2 與TIM3輸出模式類似,修改數字字尾即可
OC1 翻轉模式
修改TIM3中斷函式 實現頻率、佔空比可調
【模組十】PWM_Capture
參考庫檔案路徑 :
TIM/ InputCapture/ main.c ***it.c
RCC_Configuration(); NVIC_Configuration(); GPIO_Configuration();
void TIM3_IRQHandler(void)
包含函式
void TIM3_Caputer_Init(void)
void TIM3_IRQHandler(void)
TIM_OC1polarityconfig(TIM3, TIM_ICPolarity_Rising)
TIM3_CH1_Freq = (uint32_t) SystemCoreClock / TIM3_CH1_ReadValue2;
TIM3_CH1_Duty = TIM3_CH1_ReadValue1 * 100 / TIM3_CH1_ReadValue2;