Código Ejemplo 1 → Encender un Led cada 1 segundo
#include "stm32f4xx.h"
int main(void){
RCC -> AHB1ENR |= 0x7; //Se activan relojes puertos A, B, C
GPIOA -> MODER |= 0x400; // Se configura el puerto PA5 como salida 0100 0000 0000
while(1){
GPIOA -> ODR |= (1UL<<5); //Colocar en '1' el pin PA5
for(int i = 0; i<1600000; i++); //Delay de 1s aprox
GPIOA -> ODR &= ~(1UL<<5); //Colocar en '0' el pin PA5
for(int i = 0; i<1600000; i++); //Delay de 1s aprox
}
return 0;
}
Código Ejemplo 2 → Encender un Led cuando se oprima el botón de usuario
#include "stm32f4xx.h"
int main(void){
RCC -> AHB1ENR |= 0x7; //Se activan relojes puertos A, B, C
GPIOA -> MODER |= 0x400; // Se configura el puerto PA5 como salida 0100 0000 0000
while(1){
if(!(GPIOC -> IDR &(1UL<<13))){ //Si el pin PC13 está oprimido
GPIOA -> ODR |= (1UL<<5); //Enciende el pin PA5
}else{
GPIOA -> ODR &= ~(1UL<<5); //Apaga el pin PA5
}
}
return 0;
}