Just rotate a led turned on trough the pins C0 to C7.
The second parameter of function HAL_GPIO_WritePin
indicates the pins to be written with a new value, each bit representing a pin. We just generate a mask with the <<
operand and the value of i
on each iteration
#include "bsp.h"
int main(void)
{
GPIO_InitTypeDef GPIO_InitStruct; /*gpios initial structure*/
HAL_Init(); /*Init HAL library*/
__HAL_RCC_GPIOC_CLK_ENABLE(); /*Enable clock on port C*/
GPIO_InitStruct.Pin = 0x00FFu; /*pins to set as outputs*/
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; /*outputs on mode push-pull*/
GPIO_InitStruct.Pull = GPIO_NOPULL; /*no pull-up niether pull-down*/
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; /*pins speed*/
/*use the previous parameters to set configuration on pin C0 - C7*/
HAL_GPIO_Init( GPIOC, &GPIO_InitStruct );
/*Turn off the leds on port C from pin C0 to C7 as initial state*/
HAL_GPIO_WritePin( GPIOC, 0x00FF, RESET );
while(1)
{
/*Loop though all 8 pins one at the time every 200ms*/
for( uint32_t i=0 ; i < 8u ; i++ )
{
/*pay atention to mask (1 << i)*/
HAL_GPIO_WritePin( GPIOC, ( 1 << i ), SET ); /*turn on led in turn*/
HAL_Delay( 200u ); /*delay for 200ms*/
HAL_GPIO_WritePin( GPIOC, ( 1 << i ), RESET ); /*turn off the led in turn*/
}
}
}