EEM-465 Gömülü Sistemler
2022-2023 Güz Dönemi Ders 5
stm32f407xx.h başlık dosyasındaki tanımları kullanarak programlama
LED yakma söndürme
#include "stm32f4xx.h"
int main(){
volatile int i;
RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN;
GPIOD->MODER |= GPIO_MODER_MODER15_0;
while(1){
GPIOD->ODR |= GPIO_ODR_OD15;
for(i=0;i<1000000;i++);
GPIOD->ODR &= ~GPIO_ODR_OD15;
for(i=0;i<1000000;i++);
}
}
4 LEDi yakma söndürme
#include "stm32f4xx.h"
int main(){
volatile int i;
RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN;
GPIOD->MODER |= GPIO_MODER_MODER12_0 | GPIO_MODER_MODER13_0 |
GPIO_MODER_MODER14_0 | GPIO_MODER_MODER15_0;
while(1){
GPIOD->ODR |= GPIO_ODR_OD12 |GPIO_ODR_OD13 |
GPIO_ODR_OD14 |GPIO_ODR_OD15 ;
for(i=0;i<1000000;i++);
GPIOD->ODR &= ~(GPIO_ODR_OD12 |GPIO_ODR_OD13 |
GPIO_ODR_OD14 |GPIO_ODR_OD15) ;
for(i=0;i<1000000;i++);
}
}
Buton kontrollü 4 LEDi yakma söndürme
#include "stm32f4xx.h"
int main(){
volatile int i;
RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN | RCC_AHB1ENR_GPIOAEN;
GPIOD->MODER |= GPIO_MODER_MODER12_0 | GPIO_MODER_MODER13_0 |
GPIO_MODER_MODER14_0 | GPIO_MODER_MODER15_0;
//A portunun 0.pininin modu hali hazirda input olmasina ragmen
//islemin nasil yapildiginin gosterilmesi icin modunu ayarlayalim.
GPIOA->MODER &= ~GPIO_MODER_MODER0;
while(1){
if(GPIOA->IDR & GPIO_IDR_ID0){
GPIOD->ODR |= GPIO_ODR_OD12 |GPIO_ODR_OD13 |
GPIO_ODR_OD14 |GPIO_ODR_OD15 ;
for(i=0;i<1000000;i++);
GPIOD->ODR &= ~(GPIO_ODR_OD12 |GPIO_ODR_OD13 |
GPIO_ODR_OD14 |GPIO_ODR_OD15) ;
for(i=0;i<1000000;i++);
}
}
}