Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stm32f4xx_conf.h"
- #include "stm32f4xx_gpio.h"
- #include "stm32f4xx_rcc.h"
- #include "stm32f4xx_tim.h"
- #define button GPIOA, GPIO_Pin_0
- //Dodane moduly: RCC, GPIO, EXTI, TIM, MISC, SYSCFG
- int licznik=0;
- GPIO_InitTypeDef GPIO_InitStructure;
- //Diody
- void LED(){
- //dodanie sygnalow zegara do portow
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
- // Konfigurowanie diod
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14| GPIO_Pin_15; //12-15 diody
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; //tryb dzialania: IN/OUT-we/wy binarne, AF- funkcja alternatywna, AN-we analogowe
- GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //typ wyjscia: PP-komplementarne/OD-otwarty dren
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; //max predkosc (2,25,50,100)
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; //podciaganie wyprowadzenia: NOPULL- brak, UP- do napiecia zasilania, DOWN- do masy
- GPIO_Init(GPIOD, &GPIO_InitStructure); //(nazwa portu, struktura)
- }
- void green_on(){
- GPIO_SetBits(GPIOD, GPIO_Pin_12);
- }
- void green_off(){
- GPIO_ResetBits(GPIOD, GPIO_Pin_12);
- }
- void orange_on(){
- GPIO_SetBits(GPIOD, GPIO_Pin_13);
- }
- void orange_off(){
- GPIO_ResetBits(GPIOD, GPIO_Pin_13);
- }
- void red_on(){
- GPIO_SetBits(GPIOD, GPIO_Pin_14);
- }
- void red_off(){
- GPIO_ResetBits(GPIOD, GPIO_Pin_14);
- }
- void blue_on(){
- GPIO_SetBits(GPIOD, GPIO_Pin_15);
- }
- void blue_off(){
- GPIO_ResetBits(GPIOD, GPIO_Pin_15);
- }
- void all_on(){
- green_on();
- orange_on();
- red_on();
- blue_on();
- }
- void all_off(){
- green_off();
- orange_off();
- red_off();
- blue_off();
- }
- //Przycisk
- void Button(){
- //dodanie sygnalow zegara do portow
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
- // Konfigurowanie przycisku
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; //tryb dzialania: IN/OUT-we/wy binarne, AF- funkcja alternatywna, AN-we analogowe
- GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //typ wyjscia: PP-komplementarne/OD-otwarty dren
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; //max predkosc (2,25,50,100)
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; //podciaganie wyprowadzenia: NOPULL- brak, UP- do napiecia zasilania, DOWN- do masy
- GPIO_Init(GPIOA, &GPIO_InitStructure); //(nazwa portu, struktura)
- }
- void button_green_on(){
- if(GPIO_ReadInputDataBit(button == 1)) green_on();
- }
- void button_green_off(){
- if(GPIO_ReadInputDataBit(button == 0)) green_off();
- }
- void button_blue_on(){
- if(GPIO_ReadInputDataBit(button == 1)) blue_on();
- }
- void button_blue_off(){
- if(GPIO_ReadInputDataBit(button == 0)) blue_off();
- }
- void button_red_on(){
- if(GPIO_ReadInputDataBit(button == 1)) red_on();
- }
- void button_red_off(){
- if(GPIO_ReadInputDataBit(button == 0)) red_off();
- }
- void button_orange_on(){
- if(GPIO_ReadInputDataBit(button == 1)) orange_on();
- }
- void button_orange_off(){
- if(GPIO_ReadInputDataBit(button == 0)) orange_off();
- }
- void button_all_on(){
- if(GPIO_ReadInputDataBit(button == 1)) all_on();
- }
- void button_all_off(){
- if(GPIO_ReadInputDataBit(button == 0)) all_off();
- }
- //Delay
- void Delay(__IO uint32_t nCount){
- while(nCount--){
- }
- }
- int main(void)
- {
- SystemInit();
- Button();
- LED();
- while(1)
- {
- button_all_on();
- button_all_off();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement