#include<stm32f10x_lib.h>
void RCC_Configuration(void);
void NVIC_Configuration(void);
void Delay(vu32 nTime);
GPIO_InitTypeDef GPIO_InitStructure;
static vu32 TimingDelay;
ErrorStatus HSEStartUpStatus;
int main(void)
{
#ifdef DEBUG
debug();
#endif
RCC_Configuration();
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10; //将PF6~9设置为50M推挽输出
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOF,&GPIO_InitStructure);
GPIO_Write(GPIOF,GPIO_Pin_6|GPIO_Pin_8); //置1:D1.D2,其他为零
NVIC_Configuration();
SysTick_SetReload(9000); //定时1ms
SysTick_ITConfig(ENABLE);
while(1)
{
GPIO_Write(GPIOF,(u16)~GPIO_ReadOutputData(GPIOF));
GPIO_ResetBits(GPIOF,GPIO_Pin_10); //D1D3与D2D4闪烁,D5点亮
Delay(1000);//延时500MS
GPIO_Write(GPIOF,(u16)~GPIO_ReadOutputData(GPIOF));
GPIO_SetBits(GPIOF,GPIO_Pin_10); //D1D3与D2D4闪烁,D5熄灭
Delay(1000);
}
}
/*SysTick做延时*/
void Delay(u32 nTime)
{
SysTick_CounterCmd(SysTick_Counter_Enable); //使能Systick计数器
TimingDelay=nTime;
while(TimingDelay!=0);
SysTick_CounterCmd(SysTick_Counter_Disable); //禁用计数器
SysTick_CounterCmd(SysTick_Counter_Clear); //清空计数器
}
void RCC_Configuration(void)
{
RCC_DeInit();
RCC_HSEConfig(RCC_HSE_ON); //启动HSE
HSEStartUpStatus=RCC_WaitForHSEStartUp(); //等待HSE启动
if(HSEStartUpStatus==SUCCESS)
{
/* Enable Prefetch Buffer */
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
/* Flash 2 wait state */
FLASH_SetLatency(FLASH_Latency_2);
RCC_HCLKConfig(RCC_SYSCLK_Div1); //HCLK=系统时钟
RCC_PCLK2Config(RCC_HCLK_Div1); //APB2=HCLK
RCC_PCLK1Config(RCC_HCLK_Div2); //APB1=HCLK/2
RCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_9); //设置72M为系统时钟
RCC_PLLCmd(ENABLE); //使能PLL
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY)==RESET){} //等待PLL准备就绪
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); //将PLL作为SYSCLK
while(RCC_GetSYSCLKSource()!=0x08){} //等待PLL成为SYSCLK
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF, ENABLE); //使能PF时钟
}
}
/*******************************************************************************
* Function Name : NVIC_Configuration
* Description : Configures Vector Table base location.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void NVIC_Configuration(void)
{
#ifdef VECT_TAB_RAM
/* Set the Vector Table base location at 0x20000000 */
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else /* VECT_TAB_FLASH */
/* Set the Vector Table base location at 0x08000000 */
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
#endif
}
/*可变的时间延时衰减率*/
void TimingDelay_Decrement(void)
{
if(TimingDelay!=0x00)
{
TimingDelay--;
}
}
#ifdef DEBUG
/*******************************************************************************
* Function Name : assert_failed
* Description : Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* Input : - file: pointer to the source file name
* - line: assert_param error line source number
* Output : None
* Return : None
*******************************************************************************/
void assert_failed(u8* file, u32 line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
建立工程时+ stm32f10x_lib.c
+ stm32f10x_gpio.c
+ stm32f10x_rcc.c
+ stm32f10x_nvic.c
+ stm32f10x_flash.c
+ stm32f10x_systick.c
这些文件 |