EEM-465 Gömülü Sistemler
2022-2023 Güz Dönemi Ders 6
Kesme (interrupt)
Kesme ile yanan ledi değiştirme, gecikmeli
#include "stm32f4xx.h"
volatile static int led=12;
void bekle(volatile int x);
void bekle(volatile int x){
volatile int i;
for(i=0;i<1000000*x;i++);
}
void EXTI0_IRQHandler(void);
void EXTI0_IRQHandler(void){
EXTI->PR |= EXTI_PR_PR0;
led++;
if(led==16)
led=12;
}
int main(){
RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN |
RCC_AHB1ENR_GPIOAEN;
RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN;
GPIOD->MODER |= GPIO_MODER_MODER12_0 |
GPIO_MODER_MODER13_0 |
GPIO_MODER_MODER14_0 |
GPIO_MODER_MODER15_0;
NVIC_EnableIRQ(EXTI0_IRQn);
SYSCFG->EXTICR[0] &= ~SYSCFG_EXTICR1_EXTI0;
EXTI->RTSR |= EXTI_RTSR_TR0;
EXTI->IMR |= EXTI_IMR_IM0;
while(1){
GPIOD->ODR |= 1<<led;
bekle(3);
GPIOD->ODR &= ~(0xFU<<12);
bekle(3);
}
}
Kesme ile yanan ledi değiştirme, gecikmesiz
#include "stm32f4xx.h"
volatile static int pin=12;
volatile static int i, son_deger=3000000;
void EXTI0_IRQHandler(void);
void EXTI0_IRQHandler(void){
EXTI->PR |= EXTI_PR_PR0;
pin++;
son_deger=0;
if(pin==16)
pin=12;
}
int main(){
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN | RCC_AHB1ENR_GPIODEN;
RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN;
GPIOD->MODER |= GPIO_MODER_MODER12_0 |
GPIO_MODER_MODER13_0 |
GPIO_MODER_MODER14_0 |
GPIO_MODER_MODER15_0;
SYSCFG->EXTICR[0]&= ~SYSCFG_EXTICR1_EXTI0;
NVIC_EnableIRQ(EXTI0_IRQn);
EXTI->IMR |= EXTI_IMR_IM0;
EXTI->RTSR |= EXTI_RTSR_TR0;
while(1){
GPIOD->ODR |= 1<<pin;
for(i=0;i<son_deger;i++);
GPIOD->ODR &= ~(0xFU<<12);
for(i=0;i<son_deger;i++);
son_deger=3000000;
}
}