EasyManuals Logo

STMicroelectronics STM8 User Manual

STMicroelectronics STM8
126 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #28 background imageLoading...
Page #28 background image
i ^= 1;
}
switch(i)
{
case 0:
{
delay_ms(1000);
break;
}
case 1:
{
delay_ms(200);
break;
}
}
GPIO_WriteReverse(GPIOD, GPIO_PIN_0);
}
}
Explanation
The following lines deinitialize the GPIOs we used. Every time you reconfigure or setup a hardware
peripheral for the first time you must deinitialize it before using it. Though it is not mandatory, it will
remove any chance of wrong/conflicting configurations.
GPIO_DeInit(GPIOB);
GPIO_DeInit(GPIOD);
After deinitialization, we are good to go for initializing or setting up the GPIOs. Inputs can be with or
without internal pull-up resistors. Outputs can be either push-pull totem-pole or open drain types.
Each pin can be individually configured and does not have any dependency on another. The following
codes set GPIO PB7 as a floating input with no interrupt capability and GPIO PD0 as a fast push-pull
output. PB7 is set up as a floating input rather than an internally pulled-up input because the button
on the Disco board is already pulled up externally.
GPIO_Init(GPIOB, GPIO_PIN_7, GPIO_MODE_IN_FL_NO_IT);
GPIO_Init(GPIOD, GPIO_PIN_0, GPIO_MODE_OUT_PP_LOW_FAST);
The remaining part of the code in the main loop is just polling the button’s state and altering the delay
time for toggling the LED if the button is pressed.
for(;;)
{
if(GPIO_ReadInputPin(GPIOB, GPIO_PIN_7) == FALSE)
{
while(GPIO_ReadInputPin(GPIOB, GPIO_PIN_7) == FALSE);
i ^= 1;
}
switch(i)
{
case 0:
{
delay_ms(1000);
break;
}

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the STMicroelectronics STM8 and is the answer not in the manual?

STMicroelectronics STM8 Specifications

General IconGeneral
BrandSTMicroelectronics
ModelSTM8
CategoryMicrocontrollers
LanguageEnglish

Related product manuals