打印

大虾急救 max192

[复制链接]
1331|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
52mcu|  楼主 | 2008-3-17 21:33 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
AD, dc, TE, code, ADC
如下程序怎么也读不到ad转换的结果。请大虾拔刀相助 提供一个max192和单片机的接口例程



int ReadMax192Ad(unsigned  char channel) //channel [0--7]

   unsigned char CtrByte;//START SEL2 SEL1 SEL0 UNI/BIP  SGL/DIF  PD1 PD0
   int adcode=0;
   CtrByte=0x8e;
   CtrByte=(CtrByte&~(0x7<<4))|(channel<<4);

   CS_MAX192=0;   //chip enable 
   DelayUs(180);      //delay
   SPIRW(CtrByte);
   DelayUs(40);
   adcode=SPIRW(0x00)<<3;
    DelayUs(40);
   adcode=adcode+SPIRW(0x00)>>5; 
   DelayUs(180);
   CS_MAX192=1;//chip disable
  
   return adcode;

}

相关帖子

沙发
52mcu|  楼主 | 2008-3-25 21:39 | 只看该作者

如下程序也不行,急啊

int ReadMax192Adc(unsigned  char channel) //channel [0--7]

   unsigned char CtlByte;//START SEL2 SEL1 SEL0 UNI/BIP  SGL/DIF  PD1 PD0
   int adcode=0;
   unsigned char BitCounter;
   CtlByte=0x8f;
   CtlByte=(CtlByte&~(0x7<<4))|(channel<<4); //MAX192控制字
   CS_MAX192=1;
   PCLK =0;
   PDATA_OUT=0;
   //PDATA_IN=1;
   CS_MAX192=0;   //chip enable 

  for (BitCounter=0;BitCounter<8;BitCounter++)  //发送MAX192控制字
  {
   
    PDATA_OUT=(CtlByte & 0x80)==0?0:1;
    CtlByte  <<= 1;
    DelayUs(14); 
   
    PCLK=1; //1
    DelayUs(14);
   
    PCLK=0;//0
  }
  //DelayMs(2);
   DelayUs(24)
  PCLK =1;
  PDATA_OUT=0; 
 for (BitCounter=0;BitCounter<8;BitCounter++)  //读高八位A/D转换结果
  {
  
    PCLK=0; //0
    DelayUs(14);
   
    PCLK=1; //1
    DelayUs(14); 
    adcode <<= 1;
    if(PDATA_IN ) adcode |= 0x01;

  }
 for (BitCounter=0;BitCounter<8;BitCounter++) //读底八位A/D转换结果
  {
   
    PCLK=0; 
    DelayUs(14);
   
    PCLK=1;
    DelayUs(14); 
    adcode <<= 1;
    if(PDATA_IN ) adcode |= 0x01;
 
  }
  adcode>>=5;  //得到10位 A/D转换结果

  DelayUs(18);
   CS_MAX192=1;//chip disable
  
   return adcode;
}
 

使用特权

评论回复
板凳
ayb_ice| | 2008-3-26 12:00 | 只看该作者

多看DATASHEET...

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

157

主题

292

帖子

0

粉丝