******************************************************************************
* @file GPIO/IOToggle/main.c
* @author MCD Application Team
* @version V3.5.0
* @date 08-April-2011
* @brief Main program body.
******************************************************************************
* @attention
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "stm32_eval.h"
GPIO_InitTypeDef GPIO_InitStructure;
void RCC_Configuration(void)
{
RCC_DeInit();
RCC_HSICmd(ENABLE);
while(RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET);
RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI);
RCC_HSEConfig(RCC_HSE_OFF);
RCC_LSEConfig(RCC_LSE_OFF);
RCC_PLLConfig(RCC_PLLSource_HSI_Div2,RCC_PLLMul_9); // 72HMz
RCC_PLLCmd(ENABLE);
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);
RCC_ADCCLKConfig(RCC_PCLK2_Div4);
RCC_PCLK2Config(RCC_HCLK_Div1);
RCC_PCLK1Config(RCC_HCLK_Div2);
RCC_HCLKConfig(RCC_SYSCLK_Div1);
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
while(RCC_GetSYSCLKSource() != 0x08);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD|RCC_APB2Periph_AFIO, ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable,ENABLE);//disable JTAG
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_ResetBits(GPIOD,GPIO_Pin_2);
}
void delay_us(u32 n)
{
u8 j;
while(n--)
for(j=0;j<10;j++);
}
void delay_ms(u32 n)
{
while(n--)
delay_us(1000);
}
/**
* @brief Main program.
* @param None
* @retval None
*/
int main(void)
{ unsigned char flag=0;
RCC_Configuration();
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
while(1)
{
GPIO_SetBits(GPIOC,GPIO_Pin_0);
GPIO_SetBits(GPIOC,GPIO_Pin_1);
GPIO_SetBits(GPIOC,GPIO_Pin_2);
GPIO_SetBits(GPIOC,GPIO_Pin_3);
GPIO_SetBits(GPIOC,GPIO_Pin_4);
GPIO_SetBits(GPIOC,GPIO_Pin_5);
GPIO_SetBits(GPIOC,GPIO_Pin_6);
GPIO_SetBits(GPIOC,GPIO_Pin_7);
delay_ms(100);
GPIO_ResetBits(GPIOC,GPIO_Pin_0);
delay_ms(100);
GPIO_SetBits(GPIOC,GPIO_Pin_0);
delay_ms(100);
GPIO_ResetBits(GPIOC,GPIO_Pin_1);
delay_ms(100);
GPIO_SetBits(GPIOC,GPIO_Pin_1);
delay_ms(100);
GPIO_ResetBits(GPIOC,GPIO_Pin_2);
delay_ms(100);
GPIO_SetBits(GPIOC,GPIO_Pin_2);
delay_ms(100);
GPIO_ResetBits(GPIOC,GPIO_Pin_3);
delay_ms(100);
GPIO_SetBits(GPIOC,GPIO_Pin_3);
delay_ms(100);
GPIO_ResetBits(GPIOC,GPIO_Pin_4);
delay_ms(100);
GPIO_SetBits(GPIOC,GPIO_Pin_4);
delay_ms(100);
GPIO_ResetBits(GPIOC,GPIO_Pin_5);
delay_ms(100);
GPIO_SetBits(GPIOC,GPIO_Pin_5);
delay_ms(100);
GPIO_ResetBits(GPIOC,GPIO_Pin_6);
delay_ms(100);
GPIO_SetBits(GPIOC,GPIO_Pin_6);
delay_ms(100);
GPIO_ResetBits(GPIOC,GPIO_Pin_7);
delay_ms(100);
GPIO_SetBits(GPIOC,GPIO_Pin_7);
delay_ms(100);
}
}