完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
求大神帮忙看看哪有问题,用串口给发数据不能实现灯的亮灭
#include #define uchar unsigned char #define S2RI 0x01 #define S2ti 0x02 ***it led=P1^1; uchar temp; void UartInit(void) //9600bps@11.0592MHz { AUXR &= 0xF7; //波特率不倍速 S2CON = 0x50; //8位数据,可变波特率 AUXR |= 0x04; //独立波特率发生器时钟为Fosc,即1T BRT = 0xDC; //设定独立波特率发生器重装值 AUXR |= 0x10; //启动独立波特率发生器 IE2 = 0x01; EA = 1; } void Uart2() interrupt 8 using 1 { if (S2CON & S2RI) { S2CON &= ~S2RI; //Clear receive interrupt flag temp = S2BUF; //P0 show UART data } } void main() { UartInit(); while(1) { if(temp=='a') { led=0; } if(temp=='b') { led=1; } } } |
|
相关推荐
3个回答
|
|
|
求大神帮忙看看哪有问题,用串口给发数据不能实现灯的亮灭
#include #define uchar unsigned char #define S2RI 0x01 #define S2TI 0x02 ***it led=P1^1; uchar temp; void UartInit(void) //9600bps@11.0592MHz { AUXR &= 0xF7; //波特率不倍速 S2CON = 0x50; //8位数据,可变波特率 AUXR |= 0x04; //独立波特率发生器时钟为Fosc,即1T BRT = 0xDC; //设定独立波特率发生器重装值 AUXR |= 0x10; //启动独立波特率发生器 IE2 = 0x01; EA = 1; } void Uart2() interrupt 8 using 1 { if (S2CON & S2RI) { S2CON &= ~S2RI; //Clear receive interrupt flag temp = S2BUF; //P0 show UART data led=!led;//先一次发一个,看能不能收到 } } void main() { UartInit(); while(1) { if(temp=='a') { led=0; } if(temp=='b') { led=1; } } } |
|
|
|
|
|
你先用串口助手试试数据,电脑发送一个数据,单片机接收后再返回来,看看数据是不是正确的先,确定数据正确,再去找问题
|
|
|
|
|
|
谢谢,刚刚解决了,单片机跟插槽连接不好
|
|
|
|
|
只有小组成员才能发言,加入小组>>
2161 浏览 0 评论
imx6ull 和 lan8742 工作起来不正常, ping 老是丢包
4801 浏览 0 评论
4278 浏览 9 评论
3868 浏览 16 评论
4438 浏览 1 评论
4272浏览 3评论
3443浏览 0评论
1211浏览 0评论
2897浏览 0评论
3958浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-17 13:11 , Processed in 0.794028 second(s), Total 46, Slave 36 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
2433