完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
我编写一个单片机485串口的程序。给传感器发送命令帧16进制数组11 04 00 00 00 02 73 5B,理论上单片机串口就有回应16进制数组11 04 04 00 00 00 00 AA 0A第四、五、六、七位是传感器数据位,但是我串口中断接收到的数据全是0x11,求大神解答(P2口接的是LED灯,用以判断接收到的数据是否正确)#include
#include #define uchar unsigned char #define uint unsigned int unsigned char code send[]={0x11,0x04,0x00,0x00,0x00,0x02,0x73,0x5B}; unsigned char shuzhi[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00}; uchar Rsd[8]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; ***it wei1=P0^0; ***it wei2=P0^1; ***it wei3=P0^2; ***it wei4=P0^3; uchar index=1,tt; uchar temp1,flag; void Delay(uint c) //延时10ms { uint i,j; for(i=c;i>0;i--) for(j=0;j<110;j++); } void main() { Delay(10); // SCON = 0x50; // 串口工作方式1,REN=1:允许串口接受 TMOD = 0x20; // 定时器1,模式2, TH1 = 0xfd; // 波特率9600 TL1 = 0xfd; // TR1 = 1; // 启动定时器1 EA = 1; //打开总中断 ES = 1; //打开串口中断 Delay(50); while(1) { ES = 0; //关闭串口中断 SBUF = send[0]; while(!ti); TI = 0; SBUF = send[1]; while(!TI); TI = 0; SBUF = send[2]; while(!TI); TI = 0; SBUF = send[3]; while(!TI); TI = 0; SBUF = send[4]; while(!TI); TI = 0; SBUF = send[5]; while(!TI); TI = 0; SBUF = send[6]; while(!TI); TI = 0; SBUF = send[7]; while(!TI); TI = 0; Delay(250); ES = 1; //打开串口中断 } } void ser() interrupt 4 { if(RI==1) { RI=0; temp1=SBUF; if(index==1) { Rsd[0]=temp1; index=2; } else if(index==2) { Rsd[1]=temp1; index=3; } else if(index==3) { Rsd[2]=temp1; index=4; } else if(index==4) { Rsd[3]=temp1; index=5; } else if(index==5) { Rsd[4]=temp1; index=6; } else if(index==6) { Rsd[5]=temp1; index=7; } else if(index==7) { Rsd[6]=temp1; index=8; } else if(index==8) { Rsd[7]=temp1; index=9; } if(index==9) { index=1; if(Rsd[1]==0x04) { P2=0x66; } } } } |
|
相关推荐
2个回答
|
|
|
那应该还是你的程序问题了
|
|
|
|
|
|
程序写的太差..你多研究一下写法吧,哪里有写这么死的程序的..而且你这代码也不完整
|
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
265 浏览 0 评论
【原创】【RA4M2-SENSOR开发板评测】低功耗+USB综合测试
789 浏览 0 评论
1306 浏览 2 评论
787 浏览 0 评论
【RA4M2-SENSOR开发板评测】Analogue+Timers综合测试
1587 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
16899 浏览 31 评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-1 23:37 , Processed in 0.709130 second(s), Total 73, Slave 55 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
19510