金牌会员
 
- 积分
- 2384
- 金钱
- 2384
- 注册时间
- 2012-11-22
- 在线时间
- 403 小时
|
发表于 2017-6-12 15:43:53
|
显示全部楼层
你这个基础还要好好打一打,没有人会帮你写程序的,自己细心点看例程。串口中断里面不需要while(1),只要有中断,就会进。
改为:
u16 res = 0;
void USART1_IRQHandler(void)
{
if(USART_GetITStatus(USART1, USART_IT_RXNE))
{
res = USART_ReceiveData(USART1);
USART_SendData(USART1, res);
}
}
main.c里面改为:
extern u16 res;
int main(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
delay_init(168);
LED_Init();
My_USART1_Init();
while(1)
{
if(res == 1)
{
/* 自己填入要实现的效果 */
}
else if(res == 2)
{
/* 自己填入要实现的效果 */
}
else if(res == 3)
{
/* 自己填入要实现的效果 */
}
else if(res == 4)
{
/* 自己填入要实现的效果 */
}
}
} |
|