最近用TLC549做A/D~bit0总是0....盼指点

[复制链接]
2057|1
 楼主| aceice 发表于 2008-11-17 14:43 | 显示全部楼层 |阅读模式
//置IO口为高,输入状态<br />ADCOUT&nbsp;=&nbsp;1;<br />SCLK&nbsp;=&nbsp;0;<br />//启动转换<br />ADCCS&nbsp;=&nbsp;0;<br />NOP();<br />//bit7不需要时钟<br />if(ADCOUT)<br />&nbsp;&nbsp;&nbsp;&nbsp;rbyte&nbsp;=&nbsp;rbyte&nbsp;+&nbsp;0x01;<br />else&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;rbyte&nbsp;=&nbsp;rbyte&nbsp;+&nbsp;0x00;<br />rbyte&nbsp;=&nbsp;rbyte&nbsp;&lt&lt&nbsp;1;<br />//读取bit6~bit0<br />for(i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt&nbsp;7;&nbsp;i++)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;SCLK&nbsp;=&nbsp;1;<br />&nbsp;&nbsp;&nbsp;&nbsp;NOP();<br />&nbsp;&nbsp;&nbsp;&nbsp;//下降沿读取数据<br />&nbsp;&nbsp;&nbsp;&nbsp;SCLK&nbsp;=&nbsp;0;<br />&nbsp;&nbsp;&nbsp;&nbsp;if(ADCOUT)<br />&nbsp;&nbsp;&nbsp;&nbsp;rbyte&nbsp;=&nbsp;rbyte&nbsp;+&nbsp;0x01;<br />&nbsp;&nbsp;&nbsp;&nbsp;else&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;rbyte&nbsp;=&nbsp;rbyte&nbsp;+&nbsp;0x00;<br />&nbsp;&nbsp;&nbsp;&nbsp;rbyte&nbsp;=&nbsp;rbyte&nbsp;&lt&lt&nbsp;1;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />}<br />//需要第8个时钟<br />SCLK&nbsp;=&nbsp;1;<br />NOP();<br />SCLK&nbsp;=&nbsp;0;<br />//开始下次转换<br />ADCCS&nbsp;=&nbsp;1;<br />--------------------------------------------------<br />完全按照datasheet时序要求来的,Vref+&nbsp;=&nbsp;4V;Vref-&nbsp;=&nbsp;0;<br />是不是比较电压有关?
zhaoyu2005 发表于 2008-11-20 11:06 | 显示全部楼层

应该先移位再加

你先加后移位,最后移位当然是0了,还有从C语言看<br />else&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;rbyte&nbsp;=&nbsp;rbyte&nbsp;+&nbsp;0x00;<br />有点多余,<br />不过不知道这样写是不是直接译成rlc&nbsp;命令
您需要登录后才可以回帖 登录 | 注册

本版积分规则

374

主题

2182

帖子

0

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