Advertisement
nis

main.c for stm32/example/04-tim6

nis
Feb 27th, 2012
721
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.17 KB | None | 0 0
  1. /**
  2.  * Main code of firmware
  3.  */
  4. #include "stm32f10x.h"
  5. #include "core_cm3.h"
  6. #include "main.h"
  7. /* user status flag */
  8. volatile unsigned char status_flag;
  9. void main();
  10. /* Main function */
  11. void main(void) {
  12.         //status_flag = 0;
  13.         /* setup i/o port c */
  14.         RCC->APB2ENR |= RCC_APB2ENR_IOPCEN;
  15.         LED_PORT->CRH |= GPIO_CRH_MODE8_0 | GPIO_CRH_MODE9_0;
  16.         LED_PORT->CRH &= ~(GPIO_CRH_CNF8 | GPIO_CRH_CNF9);
  17.         /* setup i/o port a */
  18.         RCC->APB2ENR |= RCC_APB2ENR_IOPAEN | RCC_APB2ENR_AFIOEN;
  19.         /* setup AFIO andEXTI */
  20.         AFIO->EXTICR[0] |= AFIO_EXTICR1_EXTI0_PA;
  21.         EXTI->IMR |= (1 << 0);
  22.         EXTI->FTSR |= (1 << 0);
  23.         /* setup TIM6 */
  24.         RCC->APB1ENR |= RCC_APB1ENR_TIM6EN;
  25.         TIM6->PSC = 8000 - 1;
  26.         TIM6->ARR = 1000;
  27.         TIM6->DIER |= TIM_DIER_UIE;
  28.         /* enable TIM6 */
  29.         TIM6->CR1 |= TIM_CR1_CEN;
  30.         /* enable TIM6_DAC interrupt */
  31.         NVIC_EnableIRQ(TIM6_DAC_IRQn);
  32.         /* enable EXTI0 interrupt */
  33.         NVIC_EnableIRQ(EXTI0_IRQn);
  34.         /* enable leds */
  35.         LED_PORT->ODR = LED_BLUE | LED_GREEN;
  36.         /* infinity loop */
  37.         while (1);
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement