#include "sys.h"
#include "usart.h"	
////////////////////////////////////////////////////////////////////////////////// 	 
//如果使用ucos,则包括下面的头文件即可.
#if SYSTEM_SUPPORT_OS
#include "includes.h"					//ucos 使用	  
#endif
//////////////////////////////////////////////////////////////////////////////////	 
//本程序只供学习使用，未经作者许可，不得用于其它任何用途
//ALIENTEK STM32F4探索者开发板
//串口1初始化		   
//正点原子@ALIENTEK
//技术论坛:www.openedv.com
//修改日期:2014/6/10
//版本：V1.5
//版权所有，盗版必究。
//Copyright(C) 广州市星翼电子科技有限公司 2009-2019
//All rights reserved
//********************************************************************************
//V1.3修改说明 
//支持适应不同频率下的串口波特率设置.
//加入了对printf的支持
//增加了串口接收命令功能.
//修正了printf第一个字符丢失的bug
//V1.4修改说明
//1,修改串口初始化IO的bug
//2,修改了USART_RX_STA,使得串口最大接收字节数为2的14次方
//3,增加了USART_REC_LEN,用于定义串口最大允许接收的字节数(不大于2的14次方)
//4,修改了EN_USART1_RX的使能方式
//V1.5修改说明
//1,增加了对UCOSII的支持
////////////////////////////////////////////////////////////////////////////////// 	  
 

//////////////////////////////////////////////////////////////////
//加入以下代码,支持printf函数,而不需要选择use MicroLIB	  
#if 1
#pragma import(__use_no_semihosting)             
//标准库需要的支持函数                 
struct __FILE 
{ 
	int handle; 
}; 

FILE __stdout;       
//定义_sys_exit()以避免使用半主机模式    
void _sys_exit(int x) 
{ 
	x = x; 
} 
//重定义fputc函数 
int fputc(int ch, FILE *f)
{ 	
	while((UART4->SR&0X40)==0);//循环发送,直到发送完毕   
	UART4->DR = (u8) ch;      
	return ch;
}
#endif
 
//串口1中断服务程序
//注意,读取USARTx->SR能避免莫名其妙的错误   	
u8 USART_RX_BUF[USART_REC_LEN];     //接收缓冲,最大USART_REC_LEN个字节.
//接收状态
//bit15，	接收完成标志
//bit14，	接收到0x0d
//bit13~0，	接收到的有效字节数目
u16 USART_RX_STA=0;       //接收状态标记	



/* 接收缓冲, 最大USART_REC_LEN个字节. */
uint8_t g_usart1_rx_buf[USART_REC_LEN];

uint16_t g_usart1_rx_sta = 0;
uint16_t g_usart1_rx_state = 0;
uint16_t g_usart2_rx_state = 0;
uint16_t g_usart3_rx_state = 0;
uint16_t g_usart4_rx_state = 0;
uint16_t g_usart5_rx_state = 0;
uint16_t g_usart6_rx_state = 0;


uint8_t g_rx1_buffer[RXBUFFERSIZE];                  /* HAL库使用的串口接收缓冲 */
/* 接收缓冲, 最大USART_REC_LEN个字节. */
uint8_t g_usart2_rx_buf[USART_REC_LEN];

uint16_t g_usart2_rx_sta = 0;

uint8_t g_rx2_buffer[RXBUFFERSIZE];                  /* HAL库使用的串口接收缓冲 */
/* 接收缓冲, 最大USART_REC_LEN个字节. */
uint8_t g_usart3_rx_buf[USART_REC_LEN];

uint16_t g_usart3_rx_sta = 0;

uint8_t g_rx3_buffer[RXBUFFERSIZE];                  /* HAL库使用的串口接收缓冲 */
/* 接收缓冲, 最大USART_REC_LEN个字节. */
uint8_t g_usart4_rx_buf[USART_REC_LEN];

uint16_t g_usart4_rx_sta = 0;

uint8_t g_rx4_buffer[RXBUFFERSIZE];                  /* HAL库使用的串口接收缓冲 */
/* 接收缓冲, 最大USART_REC_LEN个字节. */
uint8_t g_usart5_rx_buf[USART_REC_LEN];

uint16_t g_usart5_rx_sta = 0;

uint8_t g_rx5_buffer[RXBUFFERSIZE];                  /* HAL库使用的串口接收缓冲 */

/* 接收缓冲, 最大USART_REC_LEN个字节. */
uint8_t g_usart6_rx_buf[USART_REC_LEN];

uint16_t g_usart6_rx_sta = 0;

uint8_t g_rx6_buffer[RXBUFFERSIZE];                  /* HAL库使用的串口接收缓冲 */


char receive_buffer1[RXBUFFERSIZE]={0}; 
char receive_buffer2[RXBUFFERSIZE]={0}; 
char receive_buffer3[RXBUFFERSIZE]={0}; 

//初始化IO 串口1 
//bound:波特率
void uart1_init(u32 bound){
   //GPIO端口设置
  GPIO_InitTypeDef GPIO_InitStructure;
	USART_InitTypeDef USART_InitStructure;
	NVIC_InitTypeDef NVIC_InitStructure;
	
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE); //使能GPIOA时钟
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);//使能USART1时钟
 
	//串口1对应引脚复用映射
	GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_USART1); //GPIOA9复用为USART1
	GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_USART1); //GPIOA10复用为USART1
	
	//USART1端口配置
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10; //GPIOA9与GPIOA10
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//复用功能
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;	//速度50MHz
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //推挽复用输出
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //上拉
	GPIO_Init(GPIOA,&GPIO_InitStructure); //初始化PA9，PA10

   //USART1 初始化设置
	USART_InitStructure.USART_BaudRate = bound;//波特率设置
	USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字长为8位数据格式
	USART_InitStructure.USART_StopBits = USART_StopBits_1;//一个停止位
	USART_InitStructure.USART_Parity = USART_Parity_No;//无奇偶校验位
	USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件数据流控制
	USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;	//收发模式
  USART_Init(USART1, &USART_InitStructure); //初始化串口1
	
  USART_Cmd(USART1, ENABLE);  //使能串口1 
	
	//USART_ClearFlag(USART1, USART_FLAG_TC);
	

	USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);//开启相关中断

	//Usart1 NVIC 配置
  NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;//串口1中断通道
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3;//抢占优先级3
	NVIC_InitStructure.NVIC_IRQChannelSubPriority =3;		//子优先级3
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;			//IRQ通道使能
	NVIC_Init(&NVIC_InitStructure);	//根据指定的参数初始化VIC寄存器、
	
}


void USART1_IRQHandler(void)                	//串口1中断服务程序
{
     u8 uart1_data;
	   if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)  //接收中断
		{		
			USART_ClearITPendingBit(USART1, USART_IT_RXNE);
		     uart1_data =USART_ReceiveData(USART1);	//读取接收到的数据
			 g_rx1_buffer[0] = uart1_data;
			 
			 //Uart6_Send_data(g_rx1_buffer,1);
       if ( g_usart1_rx_sta == 0 && g_rx1_buffer[0] == 0xBB )
		       {
		           g_usart1_rx_buf[0] = g_rx1_buffer[0];
			    g_usart1_rx_sta = 1;   			
		         }
		        else if( g_usart1_rx_sta != 0 )
		         {
                                  g_usart1_rx_buf[g_usart1_rx_sta & 0X3FFF] = g_rx1_buffer[0];
                                  g_usart1_rx_sta++;
                                  if(g_usart1_rx_sta > (USART_REC_LEN - 1))
                                   {
                                         g_usart1_rx_sta = 0;     
			                    g_usart1_rx_state = 1;			  
		                         //	     memset(g_usart1_rx_buf, 0x0, 6);	
		                         //	     g_rx1_buffer[0] = 0x0;	 
                     }
		}
	 
		} 
		 else if(USART_GetITStatus(USART1, USART_IT_TXE) != RESET) 
		 {
			    USART_ClearITPendingBit(USART1, USART_IT_TXE);
		 } 
} 

 

void uart2_init(u32 bound){
   //GPIO端口设置
  GPIO_InitTypeDef GPIO_InitStructure;
	USART_InitTypeDef USART_InitStructure;
	NVIC_InitTypeDef NVIC_InitStructure;
	
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE); //使能GPIOA时钟
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);//使能USART1时钟
 
	//串口2对应引脚复用映射
	GPIO_PinAFConfig(GPIOA,GPIO_PinSource2,GPIO_AF_USART2); //GPIOA2复用为USART2
	GPIO_PinAFConfig(GPIOA,GPIO_PinSource3,GPIO_AF_USART2); //GPIOA3复用为USART3
	
	//USART1端口配置
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3; //GPIOA9与GPIOA10
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//复用功能
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;	//速度50MHz
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //推挽复用输出
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //上拉
	GPIO_Init(GPIOA,&GPIO_InitStructure); //初始化PA9，PA10

   //USART1 初始化设置
	USART_InitStructure.USART_BaudRate = bound;//波特率设置
	USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字长为8位数据格式
	USART_InitStructure.USART_StopBits = USART_StopBits_1;//一个停止位
	USART_InitStructure.USART_Parity = USART_Parity_No;//无奇偶校验位
	USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件数据流控制
	USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;	//收发模式
  USART_Init(USART2, &USART_InitStructure); //初始化串口1
	
  USART_Cmd(USART2, ENABLE);  //使能串口1 
	
	//USART_ClearFlag(USART1, USART_FLAG_TC);
	

	USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);//开启相关中断

	//Usart1 NVIC 配置
  NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;//串口1中断通道
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3;//抢占优先级3
	NVIC_InitStructure.NVIC_IRQChannelSubPriority =3;		//子优先级3
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;			//IRQ通道使能
	NVIC_Init(&NVIC_InitStructure);	//根据指定的参数初始化VIC寄存器、
	
}


void USART2_IRQHandler(void)                	//串口1中断服务程序
{
     u8 uart1_data;
	   if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)  //接收中断
		{		
			USART_ClearITPendingBit(USART2, USART_IT_RXNE);
		     uart1_data =USART_ReceiveData(USART2);	//读取接收到的数据
			 g_rx2_buffer[0] = uart1_data;
			 //USART_ClearITPendingBit(USART1, USART_IT_RXNE);
                       if ( g_usart2_rx_sta == 0 && g_rx2_buffer[0] == 0xBB )
		       {
		           g_usart2_rx_buf[0] = g_rx2_buffer[0];
			    g_usart2_rx_sta = 1;   			
		         }
		        else if( g_usart2_rx_sta != 0 )
		         {
                                  g_usart2_rx_buf[g_usart2_rx_sta & 0X3FFF] = g_rx2_buffer[0];
                                  g_usart2_rx_sta++;
                                  if(g_usart2_rx_sta > (USART_REC_LEN - 1))
                                   {
                                         g_usart2_rx_sta = 0;     
			                    g_usart2_rx_state = 1;			  
		                         //	     memset(g_usart1_rx_buf, 0x0, 6);	
		                         //	     g_rx1_buffer[0] = 0x0;	 
                     }
		}
	 
		} 
		 else if(USART_GetITStatus(USART2, USART_IT_TXE) != RESET) 
		 {
			    USART_ClearITPendingBit(USART2, USART_IT_TXE);
		 } 
} 

 
void uart3_init(u32 bound){
   //GPIO端口设置
  GPIO_InitTypeDef GPIO_InitStructure;
	USART_InitTypeDef USART_InitStructure;
	NVIC_InitTypeDef NVIC_InitStructure;
	
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,ENABLE); //使能GPIOA时钟
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);//使能USART1时钟
 
	//串口3对应引脚复用映射
	GPIO_PinAFConfig(GPIOA,GPIO_PinSource8,GPIO_AF_USART3); //GPIOD8复用为USART1
	GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_USART3); //GPIOD9复用为USART1
	
	//USART3端口配置
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9; //
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//复用功能
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;	//速度50MHz
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //推挽复用输出
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //上拉
	GPIO_Init(GPIOD,&GPIO_InitStructure); //初始化PA9，PA10

   //USART3 初始化设置
	USART_InitStructure.USART_BaudRate = bound;//波特率设置
	USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字长为8位数据格式
	USART_InitStructure.USART_StopBits = USART_StopBits_1;//一个停止位
	USART_InitStructure.USART_Parity = USART_Parity_No;//无奇偶校验位
	USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件数据流控制
	USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;	//收发模式
  USART_Init(USART3, &USART_InitStructure); //初始化串口1
	
  USART_Cmd(USART3, ENABLE);  //使能串口1 
	
	//USART_ClearFlag(USART1, USART_FLAG_TC);
	

	USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);//开启相关中断

	//Usart1 NVIC 配置
  NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;//串口1中断通道
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3;//抢占优先级3
	NVIC_InitStructure.NVIC_IRQChannelSubPriority =3;		//子优先级3
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;			//IRQ通道使能
	NVIC_Init(&NVIC_InitStructure);	//根据指定的参数初始化VIC寄存器、
	
}


void USART3_IRQHandler(void)                	//串口1中断服务程序
{
     u8 uart1_data;
	   if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET)  //接收中断
		{		
			USART_ClearITPendingBit(USART3, USART_IT_RXNE);
		  uart1_data =USART_ReceiveData(USART3);	//读取接收到的数据
			g_rx3_buffer[0] = uart1_data;
      if ( g_usart3_rx_sta == 0 && g_rx3_buffer[0] == 0xBB )
		       {
		           g_usart3_rx_buf[0] = g_rx3_buffer[0];
			    g_usart3_rx_sta = 1;   			
		         }
		        else if( g_usart3_rx_sta != 0 )
		         {
                                  g_usart3_rx_buf[g_usart3_rx_sta & 0X3FFF] = g_rx3_buffer[0];
                                  g_usart3_rx_sta++;
                                  if(g_usart3_rx_sta > (USART_REC_LEN - 1))
                                   {
                                         g_usart3_rx_sta = 0;     
			                    g_usart3_rx_state = 1;			  
		                         //	     memset(g_usart1_rx_buf, 0x0, 6);	
		                         //	     g_rx1_buffer[0] = 0x0;	 
                     }
		}
	 
		} 
		 else if(USART_GetITStatus(USART3, USART_IT_TXE) != RESET) 
		 {
			    USART_ClearITPendingBit(USART3, USART_IT_TXE);
		 } 
} 

 
void uart4_init(u32 bound){
   //GPIO端口设置
  GPIO_InitTypeDef GPIO_InitStructure;
	USART_InitTypeDef USART_InitStructure;
	NVIC_InitTypeDef NVIC_InitStructure;
	
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE); //使能GPIOA时钟
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4,ENABLE);//使能USART1时钟
  //     RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);

  //      SYSCFG->PMC |= ((uint32_t)0x00008000); // 开启USART4重映射（PA0/PA1）

	//串口1对应引脚复用映射
	GPIO_PinAFConfig(GPIOA,GPIO_PinSource0,GPIO_AF_UART4); //GPIOA9复用为USART1
	GPIO_PinAFConfig(GPIOA,GPIO_PinSource1,GPIO_AF_UART4); //GPIOA10复用为USART1
	
	//USART1端口配置
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1; //GPIOA9与GPIOA10
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//复用功能
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;	//速度50MHz
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //推挽复用输出
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //上拉
	GPIO_Init(GPIOA,&GPIO_InitStructure); //初始化PA9，PA10

   //USART1 初始化设置
	USART_InitStructure.USART_BaudRate = bound;//波特率设置
	USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字长为8位数据格式
	USART_InitStructure.USART_StopBits = USART_StopBits_1;//一个停止位
	USART_InitStructure.USART_Parity = USART_Parity_No;//无奇偶校验位
	USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件数据流控制
	USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;	//收发模式
  USART_Init(UART4, &USART_InitStructure); //初始化串口1
	
  USART_Cmd(UART4, ENABLE);  //使能串口1 
	
	//USART_ClearFlag(USART1, USART_FLAG_TC);
	

	USART_ITConfig(UART4, USART_IT_RXNE, ENABLE);//开启相关中断

	//Usart1 NVIC 配置
  NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn;//串口1中断通道
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3;//抢占优先级3
	NVIC_InitStructure.NVIC_IRQChannelSubPriority =3;		//子优先级3
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;			//IRQ通道使能
	NVIC_Init(&NVIC_InitStructure);	//根据指定的参数初始化VIC寄存器、
	
}


void UART4_IRQHandler(void)                	//串口1中断服务程序
{
	u8 Res;
} 

 
void uart5_init(u32 bound){
   //GPIO端口设置
  GPIO_InitTypeDef GPIO_InitStructure;
	USART_InitTypeDef USART_InitStructure;
	NVIC_InitTypeDef NVIC_InitStructure;
	
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC,ENABLE); //使能GPIOA时钟
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,ENABLE); //使能GPIOA时钟

	RCC_APB2PeriphClockCmd(RCC_APB1Periph_UART5,ENABLE);//使能USART1时钟
 
	//串口1对应引脚复用映射
	GPIO_PinAFConfig(GPIOC,GPIO_PinSource12,GPIO_AF_UART5); //GPIOA9复用为USART1
	GPIO_PinAFConfig(GPIOD,GPIO_PinSource2,GPIO_AF_UART5); //GPIOA10复用为USART1
	
	//USART1端口配置
       GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 ; //GPIOA9与GPIOA10
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//复用功能
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;	//速度50MHz
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //推挽复用输出
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //上拉
	GPIO_Init(GPIOC,&GPIO_InitStructure); //初始化PA9，PA10

       GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 ; //GPIOA9与GPIOA10
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//复用功能
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;	//速度50MHz
	//GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //推挽复用输出
	//GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //上拉
	GPIO_Init(GPIOD,&GPIO_InitStructure); //初始化PA9，PA10


   //USART1 初始化设置
	USART_InitStructure.USART_BaudRate = bound;//波特率设置
	USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字长为8位数据格式
	USART_InitStructure.USART_StopBits = USART_StopBits_1;//一个停止位
	USART_InitStructure.USART_Parity = USART_Parity_No;//无奇偶校验位
	USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件数据流控制
	USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;	//收发模式
  USART_Init(UART5, &USART_InitStructure); //初始化串口1
	
  USART_Cmd(UART5, ENABLE);  //使能串口1 
	
	//USART_ClearFlag(USART1, USART_FLAG_TC);
	

	USART_ITConfig(UART5, USART_IT_RXNE, ENABLE);//开启相关中断

	//Usart1 NVIC 配置
  NVIC_InitStructure.NVIC_IRQChannel = UART5_IRQn;//串口1中断通道
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3;//抢占优先级3
	NVIC_InitStructure.NVIC_IRQChannelSubPriority =3;		//子优先级3
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;			//IRQ通道使能
	NVIC_Init(&NVIC_InitStructure);	//根据指定的参数初始化VIC寄存器、
	
}


void UART5_IRQHandler(void)                	//串口1中断服务程序
{
	u8 Res;
} 

 
void uart6_init(u32 bound){
   //GPIO端口设置
  GPIO_InitTypeDef GPIO_InitStructure;
	USART_InitTypeDef USART_InitStructure;
	NVIC_InitTypeDef NVIC_InitStructure;
	
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC,ENABLE); //使能GPIOA时钟
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6,ENABLE);//使能USART1时钟
 
	//串口1对应引脚复用映射
	//GPIO_PinAFConfig(GPIOC,GPIO_PinSource6,GPIO_AF_USART1); //GPIOA9复用为USART1
	//GPIO_PinAFConfig(GPIOC,GPIO_PinSource7,GPIO_AF_USART1); //GPIOA10复用为USART1  串口复用设置错误
	
	// 3. 引脚复用映射（将PC6/PC7映射到USART6）
    GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_USART6); // PC6 -> USART6_TX
    GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_USART6); // PC7 -> USART6_RX   
	//USART1端口配置
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7; //GPIOA9与GPIOA10
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//复用功能
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;	//速度50MHz
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //推挽复用输出
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //上拉
	GPIO_Init(GPIOC,&GPIO_InitStructure); //初始化PA9，PA10

   //USART1 初始化设置
	USART_InitStructure.USART_BaudRate = bound;//波特率设置
	USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字长为8位数据格式
	USART_InitStructure.USART_StopBits = USART_StopBits_1;//一个停止位
	USART_InitStructure.USART_Parity = USART_Parity_No;//无奇偶校验位
	USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件数据流控制
	USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;	//收发模式
  USART_Init(USART6, &USART_InitStructure); //初始化串口1
	
  USART_Cmd(USART6, ENABLE);  //使能串口1 
	
	//USART_ClearFlag(USART1, USART_FLAG_TC);
	

	USART_ITConfig(USART6, USART_IT_RXNE, ENABLE);//开启相关中断

	//Usart1 NVIC 配置
  NVIC_InitStructure.NVIC_IRQChannel = USART6_IRQn;//串口1中断通道
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3;//抢占优先级3
	NVIC_InitStructure.NVIC_IRQChannelSubPriority =3;		//子优先级3
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;			//IRQ通道使能
	NVIC_Init(&NVIC_InitStructure);	//根据指定的参数初始化VIC寄存器、
	
}


void USART6_IRQHandler(void)                	//串口6中断服务程序
{
     u8 uart1_data;
	   if(USART_GetITStatus(USART6, USART_IT_RXNE) != RESET)  //接收中断
		{		
			USART_ClearITPendingBit(USART6, USART_IT_RXNE);
		     uart1_data =USART_ReceiveData(USART6);	//读取接收到的数据
			 g_rx6_buffer[0] = uart1_data;
			 //USART_ClearITPendingBit(USART1, USART_IT_RXNE);
                       if ( g_usart2_rx_sta == 0 && g_rx6_buffer[0] == 0xBB )
		       {
		           g_usart6_rx_buf[0] = g_rx6_buffer[0];
			    g_usart6_rx_sta = 1;   			
		         }
		        else if( g_usart6_rx_sta != 0 )
		         {
                                  g_usart6_rx_buf[g_usart6_rx_sta & 0X3FFF] = g_rx6_buffer[0];
                                  g_usart6_rx_sta++;
                                  if(g_usart6_rx_sta > (USART_REC_LEN - 1))
                                   {
                                         g_usart6_rx_sta = 0;     
			                    g_usart6_rx_state = 1;			  
		                         //	     memset(g_usart1_rx_buf, 0x0, 6);	
		                         //	     g_rx1_buffer[0] = 0x0;	 
                     }
		}
	 
		} 
		 else if(USART_GetITStatus(USART6, USART_IT_TXE) != RESET) 
		 {
			    USART_ClearITPendingBit(USART6, USART_IT_TXE);
		 } 
} 

 
//发送数据
void Uart1_Send_data(u8 *databuf,u16 len)
{
    u8 i = 0;
    for(i=0; i<len; i++)
    {
        USART_SendData(USART1, *databuf); //发送一个字节数据
        while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET) {}; //
        databuf++;//i++;
    }
}

void Uart4_Send_data(u8 *databuf,u16 len)
{
    u8 i = 0;
    for(i=0; i<len; i++)
    {
        USART_SendData(UART4, *databuf); //发送一个字节数据
        while (USART_GetFlagStatus(UART4, USART_FLAG_TXE) == RESET) {}; //
        databuf++;//i++;
    }
}

void Uart6_Send_data(u8 *databuf,u16 len)
{
    u8 i = 0;
    for(i=0; i<len; i++)
    {
        USART_SendData(USART6, *databuf); //发送一个字节数据
        while (USART_GetFlagStatus(USART6, USART_FLAG_TXE) == RESET) {}; //
        databuf++;//i++;
    }
}

