搜索
bottom↓
回复: 2

LTC1867读不回AD

[复制链接]

出0入0汤圆

发表于 2013-3-27 12:09:49 | 显示全部楼层 |阅读模式
求各路大神,帮看下程序。运行后读出的数据都不正确。用51读取LTC1867采集的电压。
#include<reg52.h>
sbit cs=P2^0;
sbit sck=P2^1;
sbit SDI=P2^2;
sbit SD0=P2^3;
//unsigned int high_byte;          
unsigned int vale;          
unsigned int read_high_byte();
unsigned char read_low_byte();
void delay(unsigned int x);
  void UART_Init();     
void UART_Send_Byte(unsigned char mydata);
void main()
{
UART_Init();
cs=0;

cs=1;
delay(1);
cs=0;
//high_byte=(read_high_byte())<<8;   
//vale=high_byte+read_low_byte();
UART_Send_Byte(read_high_byte());
UART_Send_Byte(read_low_byte());
while(1);
}
void delay(unsigned int x)
{
        unsigned char i;
        while(x--){
                for(i=0;i<100;i++);
        }
}
unsigned int read_high_byte()
{
  unsigned char i;
  unsigned char date,high_byte;
  date=0x88;
  sck=0;
for(i=0;i<8;i++)
{
  SDI=((date<<i)&0x80);  
sck=1;
if(SD0) high_byte|=(0x80>>i);
  delay(2);
  sck=0;
  delay(2);
}
return high_byte;
}

unsigned char read_low_byte()
{
   unsigned int i,low_byte=0;
sck=0;
for(i=0;i<8;i++)
{
  sck=1;
  delay(10);
  if(SD0) low_byte|=(0x80>>i);          
sck=0;
  delay(10);
}

// high_byte=high_byte<<8;   
// high_byte+=low_byte;
return low_byte;
}

  void UART_Init()     
{
        TMOD=0x20;                                                    //定时器T1使用工作方式2
        TH1=0xfd;                                                     //设置初值
        TH0=0xfd;
        TR1=1;                                                      //开始计时
                SM0=0;
                SM1=1;                 //设置串口为方式1
                REN=1;                 //接受使能
                EA=1;                 //打开总中断开关
                ES=1;                 //打开串口中断开关
}
void UART_Send_Byte(unsigned char mydata)       
{
ES=0;
TI=0;
SBUF=mydata;
while(!TI);
TI=0;
ES=1;
}

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

阿莫论坛20周年了!感谢大家的支持与爱护!!

你熬了10碗粥,别人一桶水倒进去,淘走90碗,剩下10碗给你,你看似没亏,其实你那10碗已经没有之前的裹腹了,人家的一桶水换90碗,继续卖。说白了,通货膨胀就是,你的钱是挣来的,他的钱是印来的,掺和在一起,你的钱就贬值了。

出0入0汤圆

 楼主| 发表于 2013-3-28 08:44:54 | 显示全部楼层
自己顶下,这程序可以用的

出0入0汤圆

发表于 2013-3-28 09:04:31 | 显示全部楼层
                                                        
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-10-3 09:36

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表