Você está na página 1de 5

...op\Uni\SED\Micros\P0_MICRO\Practica0_Micro\Src\main.

txt 1
1
2 /**
3
******************************************************************************
4 * @file : main.c
5 * @brief : Main program body
6
******************************************************************************
7 ** This notice applies to any and all portions of this file
8 * that are not between comment pairs USER CODE BEGIN and
9 * USER CODE END. Other portions of this file, whether
10 * inserted by the user or by software development tools
11 * are owned by their respective copyright owners.
12 *
13 * COPYRIGHT(c) 2018 STMicroelectronics
14 *
15 * Redistribution and use in source and binary forms, with or without
modification,
16 * are permitted provided that the following conditions are met:
17 * 1. Redistributions of source code must retain the above copyright
notice,
18 * this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
notice,
20 * this list of conditions and the following disclaimer in the
documentation
21 * and/or other materials provided with the distribution.
22 * 3. Neither the name of STMicroelectronics nor the names of its
contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS"
27 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE
29 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY,
34 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 *
37
******************************************************************************
38 */
39 /* Includes ------------------------------------------------------------------
*/
40 #include "main.h"
41 #include "stm32f4xx_hal.h"
42
...op\Uni\SED\Micros\P0_MICRO\Practica0_Micro\Src\main.txt 2
43 /* USER CODE BEGIN Includes */
44
45 /* USER CODE END Includes */
46
47 /* Private variables ---------------------------------------------------------
*/
48
49 /* USER CODE BEGIN PV */
50 /* Private variables ---------------------------------------------------------
*/
51
52 /* USER CODE END PV */
53
54 /* Private function prototypes -----------------------------------------------
*/
55 void SystemClock_Config(void);
56 static void MX_GPIO_Init(void);
57
58 /* USER CODE BEGIN PFP */
59 /* Private function prototypes -----------------------------------------------
*/
60
61 /* USER CODE END PFP */
62
63 /* USER CODE BEGIN 0 */
64
65 /* USER CODE END 0 */
66
67 /**
68 * @brief The application entry point.
69 *
70 * @retval None
71 */
72 int main(void)
73 {
74 /* USER CODE BEGIN 1 */
75
76 /* USER CODE END 1 */
77
78 /* MCU
Configuration----------------------------------------------------------*/
79
80 /* Reset of all peripherals, Initializes the Flash interface and the
Systick. */
81 HAL_Init();
82
83 /* USER CODE BEGIN Init */
84
85 /* USER CODE END Init */
86
87 /* Configure the system clock */
88 SystemClock_Config();
89
90 /* USER CODE BEGIN SysInit */
91
92 /* USER CODE END SysInit */
...op\Uni\SED\Micros\P0_MICRO\Practica0_Micro\Src\main.txt 3
93
94 /* Initialize all configured peripherals */
95 MX_GPIO_Init();
96 /* USER CODE BEGIN 2 */
97
98 /* USER CODE END 2 */
99
100 /* Infinite loop */
101 /* USER CODE BEGIN WHILE */
102 while (1)
103 {
104
105 /* USER CODE END WHILE */
106
107 /* USER CODE BEGIN 3 */
108 if (HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0)){
109 HAL_GPIO_WritePin(GPIOD,GPIO_PIN_15,1);
110 } else {
111 HAL_GPIO_WritePin(GPIOD,GPIO_PIN_12,0);
112 }
113 }
114 /* USER CODE END 3 */
115
116 }
117
118 /**
119 * @brief System Clock Configuration
120 * @retval None
121 */
122 void SystemClock_Config(void)
123 {
124
125 RCC_OscInitTypeDef RCC_OscInitStruct;
126 RCC_ClkInitTypeDef RCC_ClkInitStruct;
127
128 /**Configure the main internal regulator output voltage
129 */
130 __HAL_RCC_PWR_CLK_ENABLE();
131
132 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
133
134 /**Initializes the CPU, AHB and APB busses clocks
135 */
136 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
137 RCC_OscInitStruct.HSIState = RCC_HSI_ON;
138 RCC_OscInitStruct.HSICalibrationValue = 16;
139 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
140 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
141 {
142 _Error_Handler(__FILE__, __LINE__);
143 }
144
145 /**Initializes the CPU, AHB and APB busses clocks
146 */
147 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
148 |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
...op\Uni\SED\Micros\P0_MICRO\Practica0_Micro\Src\main.txt 4
149 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
150 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
151 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
152 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
153
154 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
155 {
156 _Error_Handler(__FILE__, __LINE__);
157 }
158
159 /**Configure the Systick interrupt time
160 */
161 HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
162
163 /**Configure the Systick
164 */
165 HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
166
167 /* SysTick_IRQn interrupt configuration */
168 HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
169 }
170
171 /** Configure pins as
172 * Analog
173 * Input
174 * Output
175 * EVENT_OUT
176 * EXTI
177 */
178 static void MX_GPIO_Init(void)
179 {
180
181 GPIO_InitTypeDef GPIO_InitStruct;
182
183 /* GPIO Ports Clock Enable */
184 __HAL_RCC_GPIOA_CLK_ENABLE();
185 __HAL_RCC_GPIOD_CLK_ENABLE();
186
187 /*Configure GPIO pin Output Level */
188 HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15,
GPIO_PIN_RESET);
189
190 /*Configure GPIO pin : PA0 */
191 GPIO_InitStruct.Pin = GPIO_PIN_0;
192 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
193 GPIO_InitStruct.Pull = GPIO_NOPULL;
194 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
195
196 /*Configure GPIO pins : PD12 PD13 PD14 PD15 */
197 GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
198 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
199 GPIO_InitStruct.Pull = GPIO_NOPULL;
200 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
201 HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
202
203 }
...op\Uni\SED\Micros\P0_MICRO\Practica0_Micro\Src\main.txt 5
204
205 /* USER CODE BEGIN 4 */
206
207 /* USER CODE END 4 */
208
209 /**
210 * @brief This function is executed in case of error occurrence.
211 * @param file: The file name as string.
212 * @param line: The line in file as a number.
213 * @retval None
214 */
215 void _Error_Handler(char *file, int line)
216 {
217 /* USER CODE BEGIN Error_Handler_Debug */
218 /* User can add his own implementation to report the HAL error return state
*/
219 while(1)
220 {
221 }
222 /* USER CODE END Error_Handler_Debug */
223 }
224
225 #ifdef USE_FULL_ASSERT
226 /**
227 * @brief Reports the name of the source file and the source line number
228 * where the assert_param error has occurred.
229 * @param file: pointer to the source file name
230 * @param line: assert_param error line source number
231 * @retval None
232 */
233 void assert_failed(uint8_t* file, uint32_t line)
234 {
235 /* USER CODE BEGIN 6 */
236 /* User can add his own implementation to report the file name and line
number,
237 tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line)
*/
238 /* USER CODE END 6 */
239 }
240 #endif /* USE_FULL_ASSERT */
241
242 /**
243 * @}
244 */
245
246 /**
247 * @}
248 */
249
250 /************************ (C) COPYRIGHT STMicroelectronics *****END OF
FILE****/
251

Você também pode gostar