#include "stm32f4xx.h" #include "stm32f4xx_rcc.c" #include "stm32f4xx_gpio.c" #include "dd.h" // initialize port E (switches), Gpio_Pin_3 to GPIO_Pin_6 as inputs void SWITCHinit (void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; //GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; GPIO_Init(GPIOE, &GPIO_InitStructure); } // initialize port D (LEDS), Gpio_Pin_12 to GPIO_Pin_15 as outputs void LEDinit (void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; //GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOD, &GPIO_InitStructure); } void main (void) { // char switches = 0; SWITCHinit(); LEDinit(); while (1) { // switches = GPIOE->IDR; if (switches & S370) LED_GR_ON; else LED_GR_OFF; // S370 = 0x0008 if (switches & S371) LED_OR_ON; else LED_OR_OFF; // S370 = 0x0010 if (switches & S372) LED_RD_ON; else LED_RD_OFF; // S370 = 0x0020 if (switches & S373) LED_BL_ON; else LED_BL_OFF; // S370 = 0x0040 }; }