Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stm32f10x.h"
- #include <math.h>
- void GPIO_Config(void);
- void RCC_Config(void);
- void setAllLigts(int tab[4]);
- int main(void)
- {
- volatile unsigned long int i;
- int counter = 0;
- int x;
- int tab[4];
- //konfiguracja systemu
- RCC_Config();
- GPIO_Config();
- /*Tu nalezy umiescic ewentualne dalsze funkcje konfigurujace system*/
- GPIO_ResetBits(GPIOB, GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7);
- while (1)
- {
- for(i = 0; i < 0x40000ul; i++);
- for(i=1; i<=4; i++)
- {
- x = (int)pow(2.0,(double)i); // 2, 4, 8, 16
- tab[i-1] = ((counter%x)<(x/2)) ? 0 : 1; // <1, <2, <4, <8
- }
- setAllLigts(tab);
- if((++counter) == 16) { counter = 0; }
- };
- return 0;
- }
- void setAllLigts(int tab[4])
- {
- GPIO_WriteBit(GPIOB, GPIO_Pin_0, tab[0]==1 ? Bit_SET : Bit_RESET);
- GPIO_WriteBit(GPIOB, GPIO_Pin_1, tab[1]==1 ? Bit_SET : Bit_RESET);
- GPIO_WriteBit(GPIOB, GPIO_Pin_2, tab[2]==1 ? Bit_SET : Bit_RESET);
- GPIO_WriteBit(GPIOB, GPIO_Pin_3, tab[3]==1 ? Bit_SET : Bit_RESET);
- }
- //konfigurowanie sygnalow taktujacych
- void RCC_Config(void)
- {
- ErrorStatus HSEStartUpStatus; //zmienna opisujaca rezultat uruchomienia HSE
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);
- 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
- 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 GPIO_Config(void)
- {
- //konfigurowanie portow GPIO
- GPIO_InitTypeDef GPIO_InitStructure;
- GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
- /*Tu nalezy umiescic kod zwiazany z konfiguracja poszczegolnych portow GPIO potrzebnych w programie*/
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //wyjscie push-pull
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement