napiszemy prosty program do mrugania naszymi diodami. Płytka posiada dwie diody
dla użytkownika (czerwona i zielona) i właśnie je wykorzystamy.
Pod listingiem zamieszczę cały projekt do CooCoxa więc będzie można sobie go
pobrać i odpalić od razu na swoim PC. W kodzie zamieściłem komentarze więc widać co i jak :)
#include "main.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
void Delay(volatile uint32_t nCount);
void init(void);
int main(void)
{
SystemInit();
init();
while(1)
{
GPIOG->ODR |= GPIO_Pin_13; // PG13 mryganie //ODR - output data register
GPIOG->ODR &=~ GPIO_Pin_14; // PG14 mryganie
Delay(5000000);
GPIOG->ODR &=~ GPIO_Pin_13; // PG13 mryganie
GPIOG->ODR |= GPIO_Pin_14; // PG14 mryganie
Delay(5000000);
}
}
void init(void) {
GPIO_InitTypeDef GPIO_InitStructure;
// włączenie zegara
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOG, ENABLE); //ustawienie zegara
// ustawienie pinów portu G
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOG, &GPIO_InitStructure);
}
void Delay(volatile uint32_t nCount) { // funkcja opóźniająca
while(nCount--)
{
}
}
A tutaj link do projektu: link
Brak komentarzy:
Prześlij komentarz