STMCU小助手
发布时间:2022-1-9 20:00
|
/**( s% U# \: K+ m- z# P ****************************************************************************** * File Name : main.c * Date : 30/12/2014 14:33:58 * Description : Main program body ****************************************************************************** * * COPYRIGHT(c) 2014 STMicroelectronics * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * 1. Redistributions of source code must retain the above copyright notice,4 ]. L `1 T" Q0 J6 C * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice," y; p# j# Y' b& V9 f- u * this list of conditions and the following disclaimer in the documentation( k# f9 |" r& v6 n: A2 a( N * and/or other materials provided with the distribution. * 3. Neither the name of STMicroelectronics nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL& H0 b+ ^5 R+ { w: k; N * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER3 ~7 d$ A8 J! d6 q0 C * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE5 N6 |5 ~( v9 n; S E4 ~ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ******************************************************************************2 z4 J2 |, x0 u3 E */6 k6 S I% v C9 q- f2 B3 F) ]/ f: g' b# i /* Includes ------------------------------------------------------------------*/# P3 i# n7 G% W #include "stm32f0xx_hal.h"9 V* Q* I/ E$ s8 m( Q + f) O# }/ p% a3 }" t /* USER CODE BEGIN Includes */$ P: e) f: `* y7 _ 6 b7 `& g: I& ^- ] /* USER CODE END Includes */ $ ]' F( A8 d1 n& b; b; \' C /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ 3 ~+ F4 n3 D! A. \8 W$ l/ d D /* USER CODE END PV */& `, e- [. I# j5 i8 h9 T7 ] /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void);, [7 T) s- V9 _0 f1 o/ f" s static void MX_GPIO_Init(void); uint16_t nDelay = 500; /* USER CODE BEGIN PFP */ j6 P3 D4 u: x0 P /* USER CODE END PFP */ 2 S+ X) b O1 r+ U /* USER CODE BEGIN 0 */ $ {1 e9 c) I* I! V& M. l& M' K; S7 q0 g /* USER CODE END 0 */ + S* k$ P d' g: m' e; F& x int main(void)8 W2 V1 P7 A& o: f3 a { ( i1 _9 U* i) H" a; B /* USER CODE BEGIN 1 */+ B9 o1 t% o) ^, K/ Q. v 7 N* E# q% d/ p /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config();! [0 l2 O o. l+ F3 S /* Initialize all configured peripherals */1 O5 _- o0 T& L8 h2 c MX_GPIO_Init(); /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ 6 r- C# }; J" q! a' x0 ]* u /* USER CODE BEGIN 3 */ /* Infinite loop */% h' l3 N* O# g# T2 c" R while (1)! k2 Z* g2 E2 o6 s) ~5 s9 L1 ~ I { HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5,GPIO_PIN_SET);0 r, S& b( m/ Z U HAL_Delay(nDelay );* ^- a6 C7 u& i0 L0 u% {! w HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5,GPIO_PIN_RESET);1 q0 `3 q% A$ J8 P HAL_Delay(nDelay );7 L7 P! |/ X* p; E0 ^. u }7 G0 B1 w( o4 N5 \ /* USER CODE END 3 */ } /** System Clock Configuration5 E& S0 o2 z2 e, C' Q */ void SystemClock_Config(void) {8 @) z% C' {: { 8 j2 ?1 i( E c RCC_OscInitTypeDef RCC_OscInitStruct; RCC_ClkInitTypeDef RCC_ClkInitStruct; RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;2 C2 S+ [8 i2 E* ? RCC_OscInitStruct.HSIState = RCC_HSI_ON; RCC_OscInitStruct.HSICalibrationValue = 16;) w. S! o3 |1 @- b8 F RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; HAL_RCC_OscConfig(&RCC_OscInitStruct); RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;3 x( \5 W/ Q& u4 b4 C( C) w8 }1 H RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;9 e0 V; n3 f" {2 T( A$ x" O RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0);# A3 W/ `7 s2 y' j8 i$ A+ E3 R __SYSCFG_CLK_ENABLE();3 H) T8 l/ X& H# W% {6 |* q2 t g }) O6 z$ E7 q0 } /** Configure pins as * Analog5 v1 C3 W8 H4 ]; N2 v7 N6 J * Input * Output5 r( L; e* K/ b * EVENT_OUT * EXTI7 Q1 I K4 s7 e- ?6 L */2 Y& _8 ^# s1 W0 y void MX_GPIO_Init(void)$ {2 }; f" [2 @6 Y6 Y0 h' H, j { % K; P% S8 L9 K9 ^3 y2 V9 j GPIO_InitTypeDef GPIO_InitStruct;$ @, w. I3 m; q* Z8 | /* GPIO Ports Clock Enable */6 j! A* c- }5 V% v __GPIOC_CLK_ENABLE();2 _' F* N' T+ k3 U __GPIOA_CLK_ENABLE();) L0 R& \( w9 d8 x8 D, H$ G ^! c 1 A# @ x7 y) K" F/ j$ \( E /*Configure GPIO pin : PC13 */+ S+ C: M( u3 _. I9 a& R GPIO_InitStruct.Pin = GPIO_PIN_13; GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;# ?% b# x/ u, d6 W7 v GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);# g) E/ |4 ]5 A% W6 E 3 q8 v! x8 F$ l5 l! G, k /*Configure GPIO pin : PA5 */ GPIO_InitStruct.Pin = GPIO_PIN_5; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;2 |* c5 T. m+ k; T8 v GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_LOW;" r5 ?* m# ^0 K+ C# n# ` HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* EXTI interrupt init*/; l. X- E5 j& \7 F, C) \; q HAL_NVIC_SetPriority(EXTI4_15_IRQn, 0, 0); HAL_NVIC_EnableIRQ(EXTI4_15_IRQn); # L9 p, }5 a+ a; ~ }) P9 C7 v- @6 P9 ^ /* USER CODE BEGIN 4 */ void EXTI4_15_IRQHandler(void) {8 U3 q, c0 E: M) ~" V8 U /* USER CODE BEGIN EXTI4_15_IRQn 0 */& K' a! s& R* M5 y switch(nDelay)) T( I5 k' G; p1 s* _( m$ u { case 500:nDelay = 400;break; z: x9 C7 |+ D2 o6 |$ }" H) X case 400:nDelay = 300;break; case 300:nDelay = 200;break;- m+ U9 x/ o$ m4 Z5 a case 200:nDelay = 100;break; case 100:nDelay = 80;break;+ n1 t$ f9 M3 }5 Z) g case 80:nDelay = 50;break; case 50:nDelay = 40;break; case 40:nDelay = 30;break;$ {6 F) ]6 Y( Y; u1 v- { case 30:nDelay = 20;break;) U$ ]; n# L* g/ u case 20:nDelay = 10;break;) I7 E2 Q) a6 \0 B+ k* I case 10:nDelay = 9;break;) Y; m1 x* t! D; \' N& ~ case 9:nDelay = 8;break;9 L* d# Y' } F- p0 | case 8:nDelay = 7;break; case 7:nDelay = 6;break; case 6:nDelay = 5;break; s0 b. i- G/ e. u case 5:nDelay = 4;break;. [) M0 w/ X: ]( O7 B2 L" F case 4:nDelay = 3;break; case 3:nDelay = 2;break; case 2:nDelay = 1;break;6 W' `( C: U' S) c4 M, D& X default:nDelay = 500;break; }2 q4 W4 ?6 f, _$ L4 b5 D /* USER CODE END EXTI4_15_IRQn 0 */4 I) @4 B) t: O- J0 b6 A- b HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_13);- @# D: T4 K I9 F* o N3 k( N1 R /* USER CODE BEGIN EXTI4_15_IRQn 1 */+ e/ } W9 q7 X; h /* USER CODE END EXTI4_15_IRQn 1 */* \+ |; @7 i; u- k6 r; Z# e }+ t4 Y& f: m- {7 d /* USER CODE END 4 */5 \ Y; Q" F+ M5 V2 Z1 c' | ^5 m3 m& z' T, g% x #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name6 u4 Y E3 @3 s. { * @param line: assert_param error line source number0 A+ O% e" s' z/ E * @retval None, l# \& `: \ M( \2 n */: D& m3 E: k- f2 \# U void assert_failed(uint8_t* file, uint32_t line) { /* USER CODE BEGIN 6 */' N# z, {+ |, U7 _. |: R# I; V /* User can add his own implementation to report the file name and line number,; N; X* Q, p% H+ u; H ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) *// Z& r1 G: o( |2 m /* USER CODE END 6 */ }* \. ?: d3 R/ V) ?! s ; l# C6 b! M3 k1 _/ I k #endif' T2 L/ A! ?8 |" Q. X /** * @} */ /** * @}6 H) @7 d+ T" _. c3 I7 o, } */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
DMA 原理从 0 到 1:为什么它能解放 CPU?一文讲透 DMA 的工作流程
小白也能明白的STM32的低功耗与唤醒机制
STM32系统中2种数据掉电保护的方法
分享STM32F051中文参考手册(重制书签版)
AI工具训练营-用ChatGPT解决HID Keyboard实现的问题
STM32固件库分享,超全系列整理
STM32小白入门指南:从基础到OTA实现方案
STM32超详细学习笔记
新手必看!STM32单片机应该怎么学?
如果你解决了这些问题,就可以直接学STM32
微信公众号
手机版