7 Kasım 2018 Çarşamba

STM32 VL Discovery ile ARM Programlama - Timer Interrupt








#include "stm32f10x.h"

int sayac=0;

void TIM1_UP_TIM16_IRQHandler()
{
 if(TIM_GetITStatus(TIM1, TIM_IT_Update)==SET)
 {
  //USER CODE
  TIM_ClearITPendingBit(TIM1, TIM_IT_Update);
  sayac++;
  if(sayac<1000)
  {
   GPIO_SetBits(GPIOC, GPIO_Pin_8);
  }
  if(sayac>1000)
  {
   GPIO_ResetBits(GPIOC, GPIO_Pin_8);
  }
  if(sayac==2000)
  {
   sayac=0;
  } 
  
 }
 
}
void all_init()
{
 GPIO_InitTypeDef   GPIO_InitStructure;
 TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
 NVIC_InitTypeDef   NVIC_InitStructure;
 
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
 GPIO_InitStructure.GPIO_Pin  = GPIO_Pin_8;
 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
 GPIO_Init(GPIOC, &GPIO_InitStructure);
 
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1 , ENABLE);
 TIM_TimeBaseStructure.TIM_Prescaler   = 1;
 TIM_TimeBaseStructure.TIM_CounterMode  = TIM_CounterMode_Up;
 TIM_TimeBaseStructure.TIM_Period   = 11999;
 TIM_TimeBaseStructure.TIM_ClockDivision  =  TIM_CKD_DIV4;
 TIM_TimeBaseStructure.TIM_RepetitionCounter =   0;
 TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
 TIM_Cmd(TIM1,ENABLE);
 TIM_ITConfig(TIM1, TIM_IT_Update,ENABLE);
 
 NVIC_InitStructure.NVIC_IRQChannel      = TIM1_UP_TIM16_IRQn;
 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00;
 NVIC_InitStructure.NVIC_IRQChannelSubPriority   = 0x01;
 NVIC_InitStructure.NVIC_IRQChannelCmd     = ENABLE;
 NVIC_Init(&NVIC_InitStructure); 
}
int main()
{
 all_init();
 while(1)
 {
  
 }
 
}

Hiç yorum yok:

Yorum Gönder