int main(void) { char ch; //定义一个字符变量,用于接收字符 LED_Init(); //初始化LED USART_Init_Config(); //初始化串口通信 while(1) { ch = USART_ReceiveData(USART1); //接收串口数据 printf("接收到的指令 %c \n",ch); switch(ch) { case 'N': LED_OFF(); //熄灭LED灯 printf("熄灭LED灯 \n"); break; case 'Y': LED_ON(); //点亮LED灯 printf("点亮LED灯 \n"); break; default: printf("请输入正确的指令:N熄灭灯,Y点亮灯!\n"); break; } } }

程序功能:通过串口接收指令控制LED灯的开关。程序初始化LED和串口通信,进入while循环后不断接收串口数据,根据接收到的指令控制LED灯的开关,并在串口终端上输出控制结果

阅读下列程序在空格填上正确代码或注释并说明程序功能。int mainvoid char ch; 定义一个字符变量用于接收字符 LED_Init; ① USART_Init_Config; ② while1 ③ ; printf接收到的指令 c nch;switchchcase N ④

原文地址: https://www.cveoy.top/t/topic/hdGs 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录