0% found this document useful (0 votes)
2 views

code_bai1

The document contains two C programs for STM32F4 microcontrollers. The first program configures PA5 as a general-purpose output and toggles its state with delays. The second program additionally configures PC13 as an input and changes the state of PA5 based on the input from PC13.

Uploaded by

phanpham2k4
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

code_bai1

The document contains two C programs for STM32F4 microcontrollers. The first program configures PA5 as a general-purpose output and toggles its state with delays. The second program additionally configures PC13 as an input and changes the state of PA5 based on the input from PC13.

Uploaded by

phanpham2k4
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include "stm32f4xx.

h"

int main(void) {
RCC->AHB1ENR |= (1 << 0);//Enable clock in portA

GPIOA->MODER &= ~(3 << (5 * 2));//Reset port PA5


GPIOA->MODER |= (1 << (5 * 2));//Configure port PA5 as general purpose output
mode

while (1) {
GPIOA->ODR |= (1 << 5);//Set port PA5 to logic high level
for (int i = 0; i < 300000; i++) { }
GPIOA->ODR &= ~(1 << 5); //Set port PA5 to logic low level
for (int i = 0; i < 300000; i++) { }
}
}

#include "stm32f4xx.h"

int main(void) {
RCC->AHB1ENR |= (1 << 0);
RCC->AHB1ENR |= (1 << 2);

GPIOA->MODER &= ~(3 << (5 * 2));


GPIOA->MODER |= (1 << (5 * 2));

GPIOC->MODER &= ~(3 << (13 * 2));

while (1) {
if(GPIOC->IDR & (1 << 13)){
GPIOA->BSRR = (1 << (5 + 16));
}
else{
GPIOA->BSRR = (1 << 5);
}
}
}

You might also like