这个是可行的程序,之前的没有用这个,Puts里面输出的是字符串。之前的程序
#define uchar unsigned char
#define uint unsigned int
#define RX_LEN 25600
void USART_Configuration(void); //串口初始化
void NVIC_Configuration(void); //中断初始化
uint RX_DATA_Handler(void);
void Rev_to_Handle(void);
char get_ch[8];
static int Handle_ch[16];
static int ch_num=0;
int Con_i=0;
volatile int Rev_flag=0;
int main(void)
{
delay_init(72);
delay_ms(10);
NVIC_Configuration();
USART_Configuration();
printf("\r\n begin. \n\n");
while(1)
{
int array_num;
if(Rev_flag)
{
Rev_flag=0;
for(array_num=0;array_num<8;array_num++)
{
//Handle_ch[array_num]=get_ch[array_num];
USART1_Put_Char(get_ch[array_num]);
}
}
}
}
void USART1_IRQHandler(void)
{
while(USART_GetFlagStatus (USART1,USART_IT_RXNE)!=RESET)
{
get_ch[ch_num]=USART_ReceiveData(USART1);
//USART1_Put_Char(get_ch[ch_num++]);
ch_num++;
//Con_i ++;
USART_ClearITPendingBit(USART1,USART_IT_RXNE);
if(ch_num >= 8)
{
Con_i =0;
Rev_flag=1;
ch_num=0;
}
}
}
void USART_Configuration(void)
{
USART_InitTypeDef USART_InitStucture;
GPIO_InitTypeDef GPIO_InitStructure;
//Configure USART1 clock
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_USART1,ENABLE);
//configure USART1 PA9,PA10
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_9; //TX
GPIO_InitStructure.GPIO_Speed =GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode =GPIO_Mode_AF_PP;
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_10; //RX
GPIO_InitStructure.GPIO_Speed =GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode =GPIO_Mode_IN_FLOATING;//Mode_IPU
GPIO_Init(GPIOA,&GPIO_InitStructure);
//USART Mode Config
USART_InitStucture.USART_BaudRate =115200;
USART_InitStucture.USART_WordLength =USART_WordLength_8b ;
USART_InitStucture.USART_StopBits =USART_StopBits_1 ;
USART_InitStucture.USART_Parity =USART_Parity_No;
USART_InitStucture.USART_HardwareFlowControl =USART_HardwareFlowControl_None ;
USART_InitStucture.USART_Mode=USART_Mode_Rx |USART_Mode_Tx ;
USART_Init(USART1,&USART_InitStucture); //串口接收中断使能
USART_ClearFlag(USART1, USART_IT_RXNE); //清中断,以免一启用中断后立即产生中断
USART_ITConfig (USART1,USART_IT_RXNE,ENABLE);
USART_Cmd(USART1,ENABLE);
}
void NVIC_Configuration()
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig (NVIC_PriorityGroup_0 );
NVIC_InitStructure.NVIC_IRQChannel =USART1_IRQn ;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority =0;
NVIC_InitStructure.NVIC_IRQChannelCmd =ENABLE ;
NVIC_Init(&NVIC_InitStructure);
}
|