这是我人生的第一个程序-8251,渴望大家给予指导!

[复制链接]
 楼主| ccjchen 发表于 2007-3-8 10:54 | 显示全部楼层 |阅读模式
我现在使用了简单的三线通信,即8251的rxd通过max232后与电脑的txd相连,8251的txd通过max232后与电脑的rxd相连;接地信号相连;然后是电脑自己的rts,cts相连,dsr,dtr相连;8251自己的rts,cts相连,dsr,dtr相连;8251的其他引脚都有信号,为什么txd还是没信号?不能发也不能收,用过去的汇编却通信正常。<br />#define&nbsp;_TEST_C_<br />#include&nbsp;&quot;reg52.h&quot;<br />#include&nbsp;&quot;stdlib.h&quot;<br />#include&nbsp;&quot;absacc.h&quot;<br />#include&nbsp;&quot;intrins.h&quot;<br />#include&nbsp;&quot;test.h&quot;<br />#include&nbsp;&quot;math.h&quot;<br />#define&nbsp;uchar&nbsp;unsigned&nbsp;char<br />#define&nbsp;uint&nbsp;&nbsp;unsigned&nbsp;int<br />#define&nbsp;COM8251&nbsp;XBYTE[0x8701]<br />#define&nbsp;DAT8251&nbsp;XBYTE[0x8700]<br />uchar&nbsp;data_temp[10]={0xAA,0x10,0x22,0x32,0x00};<br />&nbsp;uchar&nbsp;m=0,n=0,k;&nbsp;&nbsp;uchar&nbsp;s;<br />void&nbsp;&nbsp;wait(uchar&nbsp;p,q);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />void&nbsp;main(void)&nbsp;<br />{&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;wait(11,82);//8251工作速度慢,每送一个控制字,等待一会儿延时2ms<br />&nbsp;&nbsp;&nbsp;&nbsp;COM8251&nbsp;=&nbsp;0x00;<br />&nbsp;&nbsp;&nbsp;&nbsp;wait(11,82);<br />&nbsp;&nbsp;&nbsp;&nbsp;COM8251&nbsp;=&nbsp;0x00;<br />&nbsp;&nbsp;&nbsp;&nbsp;wait(11,82);<br />&nbsp;&nbsp;&nbsp;&nbsp;COM8251&nbsp;=&nbsp;0x00;<br />&nbsp;&nbsp;&nbsp;&nbsp;wait(11,82);<br />&nbsp;&nbsp;&nbsp;&nbsp;COM8251&nbsp;=&nbsp;0x40;//以上为8251复位部分<br />&nbsp;&nbsp;&nbsp;&nbsp;wait(11,82);<br />&nbsp;&nbsp;&nbsp;&nbsp;COM8251&nbsp;=&nbsp;0x4e;//9600baud,1停止位,无校验,8位数据,X16<br />&nbsp;&nbsp;&nbsp;&nbsp;wait(11,82);<br />&nbsp;&nbsp;&nbsp;&nbsp;COM8251&nbsp;=&nbsp;0x37;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;while(1)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DAT8251&nbsp;=&nbsp;data_temp[m];//写&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m++;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(m==4)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m&nbsp;=&nbsp;0;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br />void&nbsp;&nbsp;wait(uchar&nbsp;p,q)<br />{<br />&nbsp;&nbsp;&nbsp;uchar&nbsp;&nbsp;i,j;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//(2*j+3)*i+4<br />&nbsp;&nbsp;&nbsp;for&nbsp;(i=p;i&gt0;i--)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(j=q;j&gt0;j--);<br />}<br /><br />
mxh0506 发表于 2007-3-8 12:21 | 显示全部楼层

有点问题

看程序你的8251应该是挂在数据总线上的,它必须能配合总线的时序才行<br />何来速度慢需要等2ms之说?
 楼主| ccjchen 发表于 2007-3-8 12:56 | 显示全部楼层

我把延时去了,照样不能收发啊

我的8251控制字写的对吗,还有while里面的小发送程序写的对吗
 楼主| ccjchen 发表于 2007-3-8 16:06 | 显示全部楼层

这种情况怎么回事?

发送时8251TXD有正确波形,可是从max232出来后,就没有波形了。&nbsp;开始时用万用表测试,max232各引脚电压完全正常。从max232出来以后,应该波形一样,只是幅度变化啊?<br /><br />
 楼主| ccjchen 发表于 2007-3-8 22:50 | 显示全部楼层

谢谢各位大哥大姐们的帮助

出来了,他妈的电脑com口是坏的,别的没问题&nbsp;<br />谢谢各位兄弟姐妹的关心和帮助<br /><br />
您需要登录后才可以回帖 登录 | 注册

本版积分规则

175

主题

446

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部

175

主题

446

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部