Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stm32f10x.h"
- typedef enum {FALSE = 0, TRUE = !FALSE} bool;
- void GPIO_Config(void);
- void NVIC_Config(void);
- int main(void)
- {
- //deklaracja zmiennych
- volatile unsigned long int i;
- unsigned int pozWlaczLED=0x0100;
- unsigned int stanGPIOB;
- bool kierunekLewo;
- //konfiguracja systemu
- GPIO_Config();
- NVIC_Config();
- //wylaczanie diod 1-8 (porty 8-15)
- GPIO_ResetBits(GPIOB, GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15);
- //pobranie aktualnego stanu calego portu B
- stanGPIOB=GPIO_ReadOutputData(GPIOB);
- //wyzerowanie bitow odpowiedzialnych za LEDy
- stanGPIOB=stanGPIOB&0x00FF;
- //zapisanie nowego stanu portow
- while (1) {
- GPIO_Write(GPIOB, pozWlaczLED | stanGPIOB);
- if (pozWlaczLED<0x8000) { //jesli pozycja jest mniejsza niz pozycja diody 8
- pozWlaczLED=pozWlaczLED<<1; //przesun pozycje o jeden w lewo
- } else {
- pozWlaczLED=0x0100; // jesli byla wlaczona dioda 8, ustaw pozycje 1
- }
- for(i=0;i<0x250000ul; i++); // czekanie okolo 0.25s przy 72MHz
- };
- return 0;
- }
- void NVIC_Config(void)
- //Konfigurowanie kontrolera przerwan NVIC
- {
- }
- void GPIO_Config(void)
- //konfigurowanie portow GPIO
- {
- GPIO_InitTypeDef GPIO_InitStructure; //struktura opisujaca konfiguracje
- //wlacz taktowanie portu GPIO B
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement