EEM-465 Gömülü Sistemler
2022-2023 Güz Dönemi Ders 7
SysTick Timer (Zamanlayıcı)
Meşgul bekleme yöntemi
#include "stm32f4xx.h"
int main(){
RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN;
GPIOD->MODER |= GPIO_MODER_MODER14_0;
// 1 saniye gecikme icin
SysTick->LOAD = 2000000;
// 100 hz frekansında sinyal için
// SysTick->LOAD = 10000;
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
while(1){
GPIOD->ODR |= GPIO_ODR_OD14;
while(!(SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk));
GPIOD->ODR &= ~GPIO_ODR_OD14;
while(!(SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk));
}
}
CLK_SOURCE bitinin etkisi
#include "stm32f4xx.h"
int main(){
RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN;
GPIOD->MODER |= GPIO_MODER_MODER14_0;
//5ms gecikme
SysTick->CTRL |= SysTick_CTRL_CLKSOURCE_Msk;
SysTick->LOAD = 80000;
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
while(1){
GPIOD->ODR |= GPIO_ODR_OD14;
while(!(SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk));
GPIOD->ODR &= ~GPIO_ODR_OD14;
while(!(SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk));
}
}
Yoklama yöntemi, xor ile LED yakma ve söndürme
#include "stm32f4xx.h"
int main(){
RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN;
GPIOD->MODER |= GPIO_MODER_MODER14_0;
//0.5 sn gecikme
SysTick->CTRL |= SysTick_CTRL_CLKSOURCE_Msk;
SysTick->LOAD = 8000000;
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
while(1){
if(SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk){
GPIOD->ODR ^= GPIO_ODR_OD14;
}
//diger kodlamalar buraya eklenebilir.
}
}
Yoklama yöntemi, ODR yazmacının kontrolü ile LED yakma söndürme
#include "stm32f4xx.h"
int main(){
RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN;
GPIOD->MODER |= GPIO_MODER_MODER14_0;
//0.5 sn gecikme
SysTick->CTRL |= SysTick_CTRL_CLKSOURCE_Msk;
SysTick->LOAD = 8000000;
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
while(1){
if(SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk){
if(GPIOD->ODR & GPIO_ODR_OD14)
GPIOD->ODR &= ~GPIO_ODR_OD14;
else
GPIOD->ODR |= GPIO_ODR_OD14;
}
//diger kodlamalar buraya eklenebilir.
}
}
Kesme ile sürenin bittiğinin tespiti
#include "stm32f4xx.h"
void SysTick_Handler(void);
void SysTick_Handler(void){
if(GPIOD->ODR & GPIO_ODR_OD14)
GPIOD->ODR &= ~GPIO_ODR_OD14;
else
GPIOD->ODR |= GPIO_ODR_OD14;
}
int main(){
RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN;
GPIOD->MODER |= GPIO_MODER_MODER14_0;
NVIC_EnableIRQ(SysTick_IRQn);
//0.1 sn gecikme
SysTick->CTRL |= SysTick_CTRL_CLKSOURCE_Msk;
SysTick->LOAD = 160000;
SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk;
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
while(1){
//diger kodlamalar
}
}