Created
March 2, 2017 09:02
-
-
Save embed0/c32604f4c9ade443b6ae45e2cc7907a6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stm32f10x.h" | |
void GPIO_Config(void); | |
void RCC_Config(void); | |
void NVIC_Config(void); | |
int main(void) | |
//konfiguracja systemu | |
{ | |
int i; | |
RCC_Config(); | |
GPIO_Config(); | |
NVIC_Config(); | |
/*Tu nalezy umiescic ewentualne dalsze funkcje konfigurujace system*/ | |
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); | |
while (1) { | |
/*Tu nalezy umiescic glowny kod programu*/ | |
GPIO_InitTypeDef GPIO_InitStructure; // deklarujemy strukture do inicjalizacji portu | |
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //wlacz taktowanie portu GPIO A | |
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;// konfigurujemy piny 0 i 1 | |
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // jako wyjscia push-pull | |
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // z taktowaniem 50MHz | |
GPIO_Init(GPIOA, &GPIO_InitStructure); // inicjalizujemy port GPIO A | |
//GPIO_WriteBit(GPIOA,GPIO_Pin_0,Bit_SET); | |
while(1) | |
{ | |
if(!GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_3)) | |
{ | |
GPIO_WriteBit(GPIOA,GPIO_Pin_0,Bit_SET); | |
GPIO_WriteBit(GPIOA,GPIO_Pin_1,Bit_SET); | |
} | |
else | |
{ | |
GPIO_WriteBit(GPIOA,GPIO_Pin_0, (BitAction)0); | |
GPIO_WriteBit(GPIOA,GPIO_Pin_1, (BitAction)0); | |
} | |
} | |
}; | |
return 0; | |
} | |
void RCC_Config(void) | |
//konfigurowanie sygnalow taktujacych | |
{ | |
ErrorStatus HSEStartUpStatus; //zmienna opisujaca rezultat uruchomienia HSE | |
RCC_DeInit(); //Reset ustawien RCC | |
RCC_HSEConfig(RCC_HSE_ON); //Wlaczenie HSE | |
HSEStartUpStatus = RCC_WaitForHSEStartUp(); //Odczekaj az HSE bedzie gotowy | |
if(HSEStartUpStatus == SUCCESS) | |
{ | |
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);// | |
FLASH_SetLatency(FLASH_Latency_2); //ustaw zwloke dla pamieci Flash; zaleznie od taktowania rdzenia | |
//0:<24MHz; 1:24~48MHz; 2:>48MHz | |
RCC_HCLKConfig(RCC_SYSCLK_Div1); //ustaw HCLK=SYSCLK | |
RCC_PCLK2Config(RCC_HCLK_Div1); //ustaw PCLK2=HCLK | |
RCC_PCLK1Config(RCC_HCLK_Div2); //ustaw PCLK1=HCLK/2 | |
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9); //ustaw PLLCLK = HSE*9 czyli 8MHz * 9 = 72 MHz | |
//inne przykladowe konfiguracje: | |
//RCC_PLLConfig(RCC_PLLSource_HSI_Div2, RCC_PLLMul_9); //ustaw PLLCLK = HSI/2*9 czyli 8MHz / 2 * 9 = 36 MHz | |
//RCC_PLLConfig(RCC_PLLSource_HSE_Div2, RCC_PLLMul_9); //ustaw PLLCLK = HSE/2*9 czyli 8MHz / 2 * 9 = 36 MHz | |
RCC_PLLCmd(ENABLE); //wlacz PLL | |
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET); //odczekaj na poprawne uruchomienie PLL | |
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); //ustaw PLL jako zrodlo sygnalu zegarowego | |
while(RCC_GetSYSCLKSource() != 0x08); //odczekaj az PLL bedzie sygnalem zegarowym systemu | |
/*Tu nalezy umiescic kod zwiazany z konfiguracja sygnalow zegarowych potrzebnych w programie peryferiow*/ | |
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);//wlacz taktowanie portu GPIO B | |
} else { | |
} | |
} | |
void NVIC_Config(void) | |
{ | |
//Konfigurowanie kontrolera przerwan NVIC | |
#ifdef VECT_TAB_RAM | |
// Jezeli tablica wektorow w RAM, to ustaw jej adres na 0x20000000 | |
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); | |
#else // VECT_TAB_FLASH | |
// W przeciwnym wypadku ustaw na 0x08000000 | |
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); | |
#endif | |
} | |
void GPIO_Config(void) | |
{ | |
//konfigurowanie portow GPIO | |
GPIO_InitTypeDef GPIO_InitStructure; | |
/*Tu nalezy umiescic kod zwiazany z konfiguracja poszczegolnych portow GPIO potrzebnych w programie*/ | |
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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment