RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); //配置系统时钟==PLL时钟
while(RCC_GetSYSCLKSource()!=0x08); //等待系统时钟源的启动
}
//==============以下为开启外设时钟的操作============================//
// RCC_AHBPeriphClockCmd (ABP2设备1 | ABP2设备2 , ENABLE); //启动AHB设备
// RCC_APB2PeriphClockCmd(ABP2设备1 | ABP2设备2 , ENABLE); //启动ABP2设备
// RCC_APB1PeriphClockCmd(ABP2设备1 | ABP2设备2 , ENABLE); //启动ABP1设备
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO | RCC_APB2Periph_USART1 , ENABLE); //打开APB2外设
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOB
|RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5 |RCC_APB1Periph_UART4 |RCC_APB1Periph_USART2 |RCC_APB1Periph_USART3 | RCC_APB1Periph_TIM2,ENABLE);
}
//==============================================================
void SysTick_Configuration(void) //延时函数初始化
{
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
NVIC_SystemHandlerPriorityConfig(SystemHandler_SysTick, 3, 0);
SysTick_SetReload(72000);
SysTick_ITConfig(ENABLE);
}
//=================================
void delay(u32 nTime)
{
SysTick_CounterCmd(SysTick_Counter_Enable);
TimingDelay = nTime;
while(TimingDelay != 0);
SysTick_CounterCmd(SysTick_Counter_Disable);
SysTick_CounterCmd(SysTick_Counter_Clear);
}
//==================================
void TimingDelay_Decrement(void)
{
if (TimingDelay != 0x00)
{
TimingDelay--;
}
}
void Delay(vu32 nCount)
{
for(; nCount != 0; nCount--);
}
//============================================
void NVIC_Configuration(void )
{
NVIC_InitTypeDef NVIC_InitStructure; //定义一个中断结构体
// NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); //设置中断向量表的起始地址为0x08000000
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); //设置NVIC优先级分组,方式。
//注:一共16个优先级,分为抢占式和响应式。两种优先级所占的数量由此代码确定,NVIC_PriorityGroup_x可以是0、1、2、3、4,
//分别代表抢占优先级有1、2、4、8、16个和响应优先级有16、8、4、2、1个。规定两种优先级的数量后,所有的中断级别必须在其中选择,
//抢占级别高的会打断其他中断优先执行,而响应级别高的会在其他中断执行完优先执行。
NVIC_InitStructure.NVIC_IRQChannel = UART5_IRQChannel; //通道设置为串口5中断
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //中断响应优先级0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //打开中断
NVIC_Init(&NVIC_InitStructure); //初始化
//定时器2中断
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure; //定义GPIO初始化结构体
//--------将UART5 的TX 配置为复用推挽输出 AF_PP---------------------//
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_12; //管脚位置定义,标号可以是NONE、ALL、0至15。
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; //输出速度50MHz