Kod: Zaznacz cały
/****************************************************************************************************/
/* */
/* Name: blinky.c */
/* */
/* Purpose: Test Program for STM32VLDiscovery - blinks the LEDs on and off at different rates */
/* (Green = 4 x Slower than Blue). Green is turned off if the button is pressed. */
/* */
/* Created: 21st September 2010 */
/* */
/* Author: Paul Robson ([email protected]) */
/* Simonsson Fun Techonlogies (original work on code for STM32) */
/* STM32F4DISCOVERY adapation by A. Wassatsch */
/* */
/****************************************************************************************************/
#define HWREG(x) (*((volatile unsigned long *)(x)))
#define RCC 0x40023800
#define RCC_AHB1ENR (RCC + 0x30)
#define GPIOA 0x40020000
#define GPIOA_IDR (GPIOA + 0x10)
#define GPIOD 0x40020c00
#define GPIOD_MODER (GPIOD + 0x0)
#define GPIOD_BSRR (GPIOD + 0x18)
#define STACK_TOP 0x20002000 /* To może poruszać się całkiem szybko! */
void nmi_handler(void);
void hardfault_handler(void);
void delay(void);
int main(void);
/* Four vectors - the starting stack pointer value, code entry point and NMI and Hard-Fault handlers */
/* Cztery wektory - początkowa wartość wskaźnika stosu, punkt wejścia kod i NMI i Hard-Fault teleskopowe */
unsigned int * myvectors[4]
__attribute__ ((section(".isr_vector")))= {
(unsigned int *) STACK_TOP,
(unsigned int *) main,
(unsigned int *) nmi_handler,
(unsigned int *) hardfault_handler
};
int main(void)
{
int n = 0;
int button;
HWREG(RCC_AHB1ENR) |= 0x08 | 0x01; /* Enable the GPIOA (bit 0) and GPIOD (bit 3) Włącz GPIOA (bit 0) i GPIOD (bit 3) */
HWREG(GPIOD_MODER) = 0x05000000; /* Set GPIOD Pin 12 and Pin 13 to outputs Set GPIOD Pin 12 i pin 13 na wyjścia */
while(1)
{
delay(); /* A short delay */
button = (( HWREG(GPIOA_IDR) & 0x1) == 0); /* Read the button - the button pulls down PA0 to logic 0 Odczyt przycisk - przycisk ściąga PA0 logice 0*/
n++; /* Count the delays */
if (n & 1) { /* Copy bit 0 of counter into GPIOC:Pin 8 Kopiuj * 0 bit licznika do GPIOC: Pin 8*/
HWREG(GPIOD_BSRR) = 1<<12 ;
} else {
HWREG(GPIOD_BSRR) = 1<<28;
}
if ((n & 4) && button) { /* Copy bit 4 of counter into GPIOC:Pin 9 if button pressed */
HWREG(GPIOD_BSRR) = 1<<13 ;
} else {
HWREG(GPIOD_BSRR) = 1<<29;
}
}
}
void delay(void)
{
int i = 100000; /* About 1/4 second delay Około 1/4 sekundy opóźnienia*/
while (i-- > 0) {
asm("nop"); /* This stops it optimising code out Zatrzymuje on optymalizacji kodu z*/
}
}
void nmi_handler(void)
{
return ;
}
void hardfault_handler(void)
{
return ;
}