Uzun Uzadıya Yazmanın Pekte Anlamı Yok.
Minimal 3usd lik bir board ile yapılan bir çalışmanın parçası bildiğiniz timer interrupt.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
#include "stm32f10x.h" volatile unsigned int Timer2_Counter=0; void init_port() { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz; GPIO_Init(GPIOC, &GPIO_InitStructure); } void TIM2_IRQHandler(void) { if(TIM_GetITStatus(TIM2,TIM_IT_Update) != RESET) { TIM_ClearITPendingBit(TIM2, TIM_IT_Update); // Clear the interrupt flag Timer2_Counter++; if (Timer2_Counter>100){ if (GPIO_ReadOutputDataBit(GPIOC,GPIO_Pin_13)==1){ GPIO_ResetBits(GPIOC,GPIO_Pin_13); Timer2_Counter=0; } else{ GPIO_SetBits(GPIOC,GPIO_Pin_13); Timer2_Counter=0; } } } } void init_Timer2() { NVIC_InitTypeDef NVIC_InitStructure; TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; /* TIM2 Clock Enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); /* Enable TIM2 Global Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* TIM2 Initialize */ TIM_TimeBaseStructure.TIM_Period=1000-1; // 1kHz TIM_TimeBaseStructure.TIM_Prescaler=24-1; // 1MHz TIM_TimeBaseStructure.TIM_ClockDivision=0; TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up; TIM_TimeBaseInit(TIM2,&TIM_TimeBaseStructure); /* TIM2 Enale */ TIM_Cmd(TIM2,ENABLE); TIM_ITConfig(TIM2,TIM_IT_Update, ENABLE); // interrupt enable } int main() { SystemInit(); init_port(); init_Timer2(); while(1) { } } |
Ziyaretci : 1780