STM32 study notes - lit led

 

 

hardware:

 

 

Programming ideas:

Led to a high level not corresponding to the light, on the light to a low level, in other words, the control operation is led blinking PB5 PE5 or both pins, the pins prior to the operation, we have to determine the lead a clock pin, this pin operating mode (output or outputs, in this experiment is the output push End), operating speed. All set finished, in order to write high-low write operation on this pin.

Function involved

void RCC_APB2PeriphClockCmd (uint32_t RCC_APB2Periph, FunctionalState NewState) // set the clock on pin

void GPIO_Init (GPIO_TypeDef * GPIOx, GPIO_InitTypeDef * GPIO_InitStruct) // for the corresponding pin, the pin operation mode, the operating speed set pins

void GPIO_SetBits (GPIO_TypeDef * GPIOx, uint16_t GPIO_Pin) // io port is provided to the high

void GPIO_ResetBits (GPIO_TypeDef * GPIOx, uint16_t GPIO_Pin) // io port is provided to the low

Init_led void (void)
{
GPIO_InitTypeDef GPIO_InitStruct;
RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOB, the ENABLE); // port PB clock enable
RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOE, ENABLE); // PE port clock enable

GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP; // set to push the end output
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_5; // set the pin. 5
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; // operating frequency is 50MHz
GPIO_Init (GPIOB, & GPIO_InitStruct); // initialize GPIOB the IO port
GPIO_Init (GPIOE, & GPIO_InitStruct); // GPIOE IO port initialization
}

main int (void)
{
  Init_led (); // initialize system led
  delay_init (); // initialize delay
  the while (. 1)
  {
    GPIO_SetBits (GPIOB, GPIO_Pin_5); // set pin high led Off
    GPIO_ResetBits (GPIOE, GPIO_Pin_5); // set pin low light led
    delay_ms (500); // delay 500ms
    GPIO_ResetBits (GPIOB, GPIO_Pin_5); // set pin low light led
    GPIO_SetBits (GPIOE, GPIO_Pin_5 ); // set pin high led Off
    delay_ms (500); // delay 500ms
  }
}

 

Guess you like

Origin www.cnblogs.com/wuhoudezhenyu/p/11795842.html