EEM-465 Gömülü Sistemler
2022-2023 Güz Dönemi Ders 8
Temel Zamanlayıcılar
Meşgul bekleme yöntemi
#include "stm32f4xx.h"
int main(){
RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN;
GPIOD->MODER |= GPIO_MODER_MODER13_0;
RCC->APB1ENR |= RCC_APB1ENR_TIM6EN;
TIM6->PSC = 15;
TIM6->ARR = 1000;
TIM6->CR1 |= TIM_CR1_CEN;
while(1){
GPIOD->ODR |= GPIO_ODR_OD13;
while(!(TIM6->SR & TIM_SR_UIF));
TIM6->SR &= ~TIM_SR_UIF;
GPIOD->ODR &= ~GPIO_ODR_OD13;
while(!(TIM6->SR & TIM_SR_UIF));
TIM6->SR &= ~TIM_SR_UIF;
}
}
Yoklama yöntemi
#include "stm32f4xx.h"
int main(){
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOBEN;
GPIOB->MODER |= GPIO_MODER_MODER10_0;
RCC->APB1ENR |= RCC_APB1ENR_TIM6EN;
TIM6->PSC = 31;
TIM6->ARR = 1000;
TIM6->CR1 |= TIM_CR1_CEN;
while(1){
if(TIM6->SR & TIM_SR_UIF){
TIM6->SR &= ~TIM_SR_UIF;
if(GPIOB->ODR & GPIO_ODR_OD10)
GPIOB->ODR &= ~GPIO_ODR_OD10;
else
GPIOB->ODR |= GPIO_ODR_OD10;
}
}
}
Kesme Yöntemi
#include "stm32f4xx.h"
void TIM6_DAC_IRQHandler(void);
void TIM6_DAC_IRQHandler(){
TIM6->SR &= ~TIM_SR_UIF;
if(GPIOB->ODR & GPIO_ODR_OD10)
GPIOB->ODR &= ~GPIO_ODR_OD10;
else
GPIOB->ODR |= GPIO_ODR_OD10;
}
int main(){
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOBEN;
GPIOB->MODER |= GPIO_MODER_MODER10_0;
RCC->APB1ENR |= RCC_APB1ENR_TIM6EN;
TIM6->PSC = 31;
TIM6->ARR = 5000;
TIM6->DIER |= TIM_DIER_UIE;
NVIC_EnableIRQ(TIM6_DAC_IRQn);
TIM6->CR1 |= TIM_CR1_CEN;
while(1){
}
}