📄 main.lst
字号:
190
191 /* TIM2 clocks enable */
192 RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
193
194 /* CAN Periph clock enable */
195 RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN, ENABLE);
196 }
197
198 /*******************************************************************************
199 * Function Name : GPIO_Configuration
200 * Description : Configures the different GPIO ports.
201 * Input : None
202 * Output : None
203 * Return : None
204 *******************************************************************************/
205 void GPIO_Configuration(void)
206 {
207 GPIO_InitTypeDef GPIO_InitStructure;
208
209 /* Configure PC.04 -- PC.11 as Output push-pull */
210 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 |GPIO_Pin_6 | GPIO_Pin_7
211 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11;
212 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
213 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
214 GPIO_Init(GPIOC, &GPIO_InitStructure);
215
216 /* Configure PD.03, PC.04, PC.11 -- PC.15 as input floating */
217 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_11 | GPIO_Pin_12 |
218 GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
219 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
220 GPIO_Init(GPIOD, &GPIO_InitStructure);
221
222 /* Configure CAN pin: RX */
223 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
224 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
225 GPIO_Init(GPIOD, &GPIO_InitStructure);
226
227 /* Configure CAN pin: TX */
228 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
229 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
230 GPIO_Init(GPIOD, &GPIO_InitStructure);
231
232 /* CAN pin remap to PD0/PD1 */
233 GPIO_PinRemapConfig(GPIO_Remap2_CAN,ENABLE);
234
235 /* Configure PE.00 -- PE.15 as Output push-pull */
236 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
237 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
238 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
239 GPIO_Init(GPIOE, &GPIO_InitStructure);
240 }
241
242 /*******************************************************************************
243 * Function Name : NVIC_Configuration
244 * Description : Configures the NVIC and Vector Table base address.
245 * Input : None
246 * Output : None
247 * Return : None
248 *******************************************************************************/
249 void NVIC_Configuration(void)
250 {
251 NVIC_InitTypeDef NVIC_InitStructure;
252
253 #ifdef VECT_TAB_RAM
254 /* Set the Vector Table base location at 0x20000000 */
255 NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
256 #else /* VECT_TAB_FLASH */
257 /* Set the Vector Table base location at 0x08000000 */
258 NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
259 #endif
260
261 /* Configure the Priority Group to 2 bits */
262 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
263
264 /* enabling interrupt */
265 NVIC_InitStructure.NVIC_IRQChannel=TIM2_IRQChannel;
266 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
267 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
268 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
269 NVIC_Init(&NVIC_InitStructure);
270
271
272 /* Enable the EXTI3 Interrupt on PD.3 */
273 NVIC_InitStructure.NVIC_IRQChannel = EXTI3_IRQChannel;
274 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
275 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
276 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
277 NVIC_Init(&NVIC_InitStructure);
278
279 /* Enable the EXTI4 Interrupt on PD.4 */
280 NVIC_InitStructure.NVIC_IRQChannel = EXTI4_IRQChannel;
281 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
282 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
283 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
284 NVIC_Init(&NVIC_InitStructure);
285
286 /* Configure the SysTick handler priority */
287 NVIC_SystemHandlerPriorityConfig(SystemHandler_SysTick, 2, 0);
288 }
289
290 /*******************************************************************************
291 * Function Name : LcdShow_Init
292 * Description : Configure the lcd dispaly: TIM2 initialize in Output Compare
293 * Timing Mode
294 * Input : None
295 * Return : None
296 * Comment : TIM2 Configuration: Output Compare Timing Mode:
297 TIM2CLK = 36 *2 =72MHz, Prescaler = 17, TIM2 counter clock = 4 MHz
298 TIM2 update Period = ARR / TIM2 counter Period = 2 ms
299 CC1 OC period = 1ms
300 *******************************************************************************/
301 void LcdShow_Init(void)
302 {
303 TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
304 TIM_OCInitTypeDef TIM_OCInitStructure;
305
306 /* Time base configuration */
307 TIM_TimeBaseStructure.TIM_Period = 8000;
308 TIM_TimeBaseStructure.TIM_Prescaler = 17;
309 TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
310 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
311 TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
312
313 TIM_ARRPreloadConfig(TIM2,DISABLE);
314 /* only counter overflow/underflow generate U interrupt */
315 TIM_UpdateRequestConfig(TIM2,TIM_UpdateSource_Regular);
316
317 /* Output Compare Timing Mode configuration: Channel1 */
318 TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing;
319 TIM_OCInitStructure.TIM_Channel = TIM_Channel_1;
320 TIM_OCInitStructure.TIM_Pulse = 4000;
321 TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
322 TIM_OCInit(TIM2, &TIM_OCInitStructure);
323
324 TIM_OC1PreloadConfig(TIM2, TIM_OCPreload_Disable);
325
326 /* TIM IT enable */
327 TIM_ITConfig(TIM2, TIM_IT_CC1 | TIM_IT_Update, ENABLE);
328
329 /* TIM2 enable counter */
330 TIM_Cmd(TIM2, ENABLE);
331 }
332
333 /*******************************************************************************
334 * Function Name : SysTick_Config
335 * Description : Configure a SysTick Base time to 10 ms.
336 * Input : None
337 * Output : None
338 * Return : None
339 *******************************************************************************/
340 void SysTick_Config(void)
341 {
342 /* Configure HCLK clock as SysTick clock source */
343 SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
344
345 /* SysTick interrupt each 100 Hz with HCLK equal to 72MHz */
346 SysTick_SetReload(720000);
347
348 /* Enable the SysTick Interrupt */
349 SysTick_ITConfig(ENABLE);
350
351 /* Enable the SysTick Counter */
352 SysTick_CounterCmd(SysTick_Counter_Enable);
353 }
354
355 void Button_Config(void)
356 {
357 GPIO_InitTypeDef GPIO_InitStructure;
358
359 /* Enable GPIOD clock */
360 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
361
362 /* Configure PD.03, PD.04 as output push-pull */
363 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 ;
364 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
365 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
366 GPIO_Init(GPIOD, &GPIO_InitStructure);
367 }
368
369 void Led_Config(void)
370 {
371 GPIO_InitTypeDef GPIO_InitStructure;
372
373 /* Enable GPIOC clock */
374 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
375
376 /* Configure PC.06, PC.07, PC.08 and PC.09 as output push-pull */
377 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_4 | GPIO_Pin_5;
378 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
379 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
380 GPIO_Init(GPIOC, &GPIO_InitStructure);
381 }
382
383 void Led_RW_ON(void)
384 {
385 GPIO_SetBits(GPIOC, GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_4 | GPIO_Pin_5);
386 }
387
388 void Led_RW_OFF(void)
389 {
390 GPIO_ResetBits(GPIOC, GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_4 | GPIO_Pin_5);
391 }
392
393 #ifdef DEBUG
394 /*******************************************************************************
395 * Function Name : assert_failed
396 * Description : Reports the name of the source file and the source line number
397 * where the assert error has occurred.
398 * Input : - file: pointer to the source file name
399 * - line: assert error line source number
400 * Output : None
401 * Return : None
402 *******************************************************************************/
403 void assert_failed(u8* file, u32 line)
404 {
405 /* User can add his own implementation to report the file name and line number,
406 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
407
408 /* Infinite loop */
409 while (1)
410 {
411
412 }
413 }
414 #endif
415 /******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/
Errors: 1
Warnings: 1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -