Home » BLOG » Contrôle d’une led avec un µC STM32

Contrôle d’une led avec un µC STM32

Exemple de contrôle d’une led sur le port PE8 avec un microcontrôleur STM32F407 :

[pastacode lang=”c” manual=”void%20led_init(void)%0A%7B%0AGPIO_InitTypeDef%20GPIO_InitStruct%3B%0A%0A%09%20%20%2F%2F%20configuration%20en%20sortie%0A%09%20%20GPIO_InitStruct.Pin%20%3D%20GPIO_PIN_8%3B%0A%09%20%20GPIO_InitStruct.Mode%20%3D%20GPIO_MODE_OUTPUT_PP%3B%0A%09%20%20GPIO_InitStruct.Pull%20%3D%20GPIO_NOPULL%3B%0A%09%20%20GPIO_InitStruct.Speed%20%3D%20GPIO_SPEED_FREQ_LOW%3B%0A%09%20%20HAL_GPIO_Init(GPIOE%2C%20%26GPIO_InitStruct)%3B%0A%0A%7D%0A%0Avoid%20led_control(GPIO_PinState%20state_led)%0A%7B%0A%09HAL_GPIO_WritePin(GPIOE%2C%20GPIO_PIN_8%2C%20state_led)%3B%0A%7D%0A%0Avoid%20led_toggle(void)%0A%7B%0A%20%20HAL_GPIO_TogglePin(GPIOE%2C%20GPIO_PIN_8)%3B%0A%7D” message=”” highlight=”” provider=”manual”/]