stc系列单片机串口通信的总结

stc系列单片机串口通信的总结

ID:16705375

大小:22.00 KB

页数:4页

时间:2018-08-24

stc系列单片机串口通信的总结_第1页
stc系列单片机串口通信的总结_第2页
stc系列单片机串口通信的总结_第3页
stc系列单片机串口通信的总结_第4页
资源描述:

《stc系列单片机串口通信的总结》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库

1、串口通信:软件调试,在调试过程中需要使用虚拟串口助手。在编程中注意设计时钟和波特率。注意程序的串口设置和串口调试助手中串口设置相同。单串口:modecom29600,0,8,1assigncom2soutstime=0多串口:modecom29600,0,8,1assigncom2s0out0表示单片机的串口0编程:STC12介绍的方法:接收一个字节的函数和发送字符串的函数,发送字符串需要知道字符串的长度。对于接收字符串的函数,可以仿照通过调用接收一个字节的函数,写出接收字符串函数。voidWriteUart(uch

2、ar*pucData,ucharucLength){if(ucLength==0){return;}if(UartBuzy==1)return;ucSendLength=ucLength;pucSendData=pucData;SBUF=*pucSendData;UartBuzy=1;ucSendedCount=0;}ucharReadUart(void){ucharData;Data=ucRecData;ucRecData=0;returnData;}UnsignedcharRString(unsignedchar*s,unsigned

3、intlen){Unsignedinti;For(i=0;i

4、teeAfterthevictoryofthelongMarch,hehasbeentheNorthwestOfficeoftheFederationofStateenterprisesMinister,ShenmufuguSARmissions,DirectorofNingxiaCountypartyCommitteeSecretaryandrecorderoftheCountypartyCommitteeSecretary,MinistersandvoidUartIRQ(void)interrupt4{if(RI){RI=0;ucRe

5、cData=SBUF;}if(TI){TI=0;ucSendedCount++;if(ucSendedCount>=ucSendLength){UartBuzy=0;return;}else{SBUF=*(pucSendData+ucSendedCount);}}}STC15:STC15只给出了发送函数,且发送函数有瑕疵,具体见最后分析。voidUART1_ISR(void)interrupt4using1{if(RI)//接收数据{RI=0;//清除RI位}if(TI)//发送数据{TI=0;//清除TI位busy=0;//清忙标志}}

6、voidSendData(unsignedchardat){while(busy);//等待前面的数据发送完成busy=1;SBUF=dat;//写数据到UART数据寄存器}voidSendString(char*s){otherstaffoftheCentre.Duringthewar,ZhuwastransferredbacktoJiangxi,andDirectorofthenewOfficeinJingdezhen,JiangxiCommitteeSecretary.Startingin1939servedasrecorderof

7、theWestNorthOrganization,SecretaryoftheSpecialCommitteeAfterthevictoryofthelongMarch,hehasbeentheNorthwestOfficeoftheFederationofStateenterprisesMinister,ShenmufuguSARmissions,DirectorofNingxiaCountypartyCommitteeSecretaryandrecorderoftheCountypartyCommitteeSecretary,Mini

8、stersandwhile(*s)//检测字符串结束标志{SendData(*s++);//发送当前字符}}SendString()字符串函数,当遇到发送的字符串里面有0x00就会终止,实用性

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。