电子大神的日记本,供应链专家的功夫茶盘,在这里记录、分享与共鸣。

登录以开始

AD7793驱动程序,但愿有用

#include "Ad7793.h"

 

void Dly(unsigned int di)
 {
   unsigned int di1;
   for(di1=0;di1<di;di1++);
 
 
 }

void Ad7793Reset(void)   //Ad7793复位
   {
    
    
      unsigned char i;
      SPIM_Start(SPIM_SPIM_MODE_0|SPIM_SPIM_MSB_FIRST);

      PRT1DR&=~0x80;  //cs=0
      for(i=0;i<5;i++)
       {
        while( ! (SPIM_bReadStatus() & SPIM_SPIM_TX_BUFFER_EMPTY ) );
        SPIM_SendTxData(0xff);
       }
      PRT1DR|=0x80;  //cs=1
      Dly(10);
   
    }
void Ad7793Write(unsigned char iReg,unsigned char *iTxbuff,unsigned char iLen)//将iTxbuff数据写入iAddress地址开始iLen字节
   {
      unsigned char i;
      SPIM_Start(SPIM_SPIM_MODE_0|SPIM_SPIM_MSB_FIRST);
      PRT1DR&=~0x80;  //cs=0
      Dly(500);
      while( ! (SPIM_bReadStatus() & SPIM_SPIM_TX_BUFFER_EMPTY ) );
      SPIM_SendTxData(iReg);
      Dly(100);
      for(i=0;i<iLen;i++)
       {
        while( ! (SPIM_bReadStatus() & SPIM_SPIM_TX_BUFFER_EMPTY ) );
        SPIM_SendTxData(iTxbuff[i]);
      
        }
      Dly(500); 
      PRT1DR|=0x80;  //cs=1
  
   
    }

 

void Ad7793Read(unsigned char iReg1,unsigned char *iRxbuff,unsigned char iLen1)
   {
      unsigned char i;
      unsigned char i1;
      //PRT1GS=0x4c;
      i1=iReg1|0x40;
      Dly(500);
      SPIM_Start(SPIM_SPIM_MODE_0|SPIM_SPIM_MSB_FIRST);
      PRT1DR&=~0x80;  //cs=0
      while( ! (SPIM_bReadStatus() & SPIM_SPIM_TX_BUFFER_EMPTY ) );
      SPIM_SendTxData(i1);
      Dly(100);
      SPIM_Start(SPIM_SPIM_MODE_3 | SPIM_SPIM_MSB_FIRST);
      for(i=0;i<iLen1;i++)
       {
         while( ! (SPIM_bReadStatus() & SPIM_SPIM_TX_BUFFER_EMPTY ) );
      SPIM_SendTxData(0);
         while( ! (SPIM_bReadStatus() & SPIM_SPIM_RX_BUFFER_FULL ) );  
       iRxbuff[i]=SPIM_bReadRxData();
      
        }
      Dly(100);
      PRT1DR|=0x80;  //cs=1
      //PRT1GS=0x0c;  //hz dout
   
    }

  
 
   
void InisAd7793(void)
   {
    
     unsigned char iTx[3];
   
    
     iTx[0]=0x03;
     Ad7793Write(IoReg,iTx,1);  //配置1Ma电流输出
   
     iTx[0]=0x00;
     iTx[1]=0x0A;
     Ad7793Write(ModReg,iTx,2);    //设置连续转换模式,16.7HZ
   
     iTx[0]=0x30;
     iTx[1]=0x07;
     Ad7793Write(ConfigReg,iTx,2);
     PRT1GS=0x0c;    //hz out
    
    
   
    
  
  
    }    
   

博主
bjshion@163.com
ni_labview's Blog
郑重声明: 哥姐弟妹们,我这blog转可以随便转,别像小广告一样乱贴,成为行业的“牛皮癣”,因为后面署名是ni_labview,手下留情,一切涉及
点击跳转