int main( void )
{
u8 *pr,i;
u8 loc_temp[20];
GPIO_Init(GPIOC, GPIO_Pin_3, GPIO_Mode_Out_PP_High_Fast); //TXD //txd初始化为高电平互补推挽输出模式
GPIO_Init(GPIOC, GPIO_Pin_2, GPIO_Mode_In_PU_No_IT); //RXD //rxd初始化为不带中断上拉输入模式
CLK_PeripheralClockConfig (CLK_Peripheral_USART1,ENABLE);//开启USART时钟
USART_Init(USART1,38400,USART_WordLength_8b,USART_StopBits_1,USART_Parity_No,USART_Mode_Tx|USART_Mode_Rx);//设置USART参数9600,8N1,接收/发送
USART_ITConfig (USART1,USART_IT_RXNE,ENABLE);//使能接收中断
USART_Cmd (USART1,ENABLE);//使能USART
CLK_PeripheralClockConfig (CLK_Peripheral_TIM4,ENABLE); //使能外设时钟
TIM4_TimeBaseInit(TIM4_Prescaler_128, 0xff);
TIM4_ClearFlag(TIM4_FLAG_Update);
TIM4_ITConfig(TIM4_IT_Update, ENABLE);
TIM4_Cmd(ENABLE);
enableInterrupts();
Delay(60000);
GSM_Start_Config();
while(1)
{
}
}
//===============================================================
INTERRUPT_HANDLER(USART1_RX_TIM5_CC_IRQHandler,28) //串口中断处理程序
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
u8 cc;
if( USART_GetITStatus(USART1,USART_IT_RXNE)!=RESET)//接收中断处理
{
USART_ClearITPendingBit (USART1,USART_IT_RXNE);//清中断标志
cc=USART_ReceiveData8 (USART1);
if(USART_RX_STA<200)
{
receive_count=0;
if(USART_RX_STA==0)
{
count_start_flag =1;//计数器开始计数
}
USART_RX_BUF[USART_RX_STA++]=cc;
}
else
{
USART_RX_STA|=1<<14;
count_start_flag =0;
}
}
if(USART_GetFlagStatus(USART1,USART_FLAG_OR)==SET)//溢出中断处理
{
USART_ClearFlag(USART1,USART_FLAG_OR);
USART_ReceiveData8 (USART1);
}
} |