|
最近在利用AD7190做数据采集,前向通道的输入电压范围为单端0-4V,在AD7190的初始化里配置AD7190为AIN1接+,AINCOM接信号地,同时选择unbuffer模式,打算参考电压为5V,所以Gain选择为1,望大虾们能否帮看下我的AD7190的初始化部分的编程是否正确,以下是我的源程序,最后利用查询方式串口传回数据,见mian()部分
#include"reg51.h"
#include"string.h"
sbit AD_DIN=P1^7;
sbit AD_RDY=P1^5;
sbit AD_DOUT=P1^5;
sbit AD_CLK=P1^6;
#define uchar unsigned char
/*********************延时函数**********************************/
void delay(unsigned int time)
{
unsigned int s;
for(s=0;s<time;s++);
}
//=============写一个字节======================//
void AD7190_Write( unsigned char temp)
{
unsigned char loop;
for(loop=0;loop<8;loop++)
{
if(temp&0x80) AD_DIN=1;
else AD_DIN=0;
AD_CLK=0;
AD_CLK=1;
temp=temp<<1 ;
}
AD_CLK=1;
AD_DIN=0;
}
//===============读一个字节==========================//
unsigned char AD7190_Read(void)
{
unsigned char recdata;
unsigned char loop;
recdata="0";
for(loop=0;loop<8;loop++)
{
AD_CLK=0;
recdata=recdata<<1;
if(AD_DOUT) recdata="recdata" +1;
AD_CLK=1;
}
return (recdata);
}
//==================AD7190初始化=================================//
void AD7190_init (void)
{
AD7190_Write(0Xff);
AD7190_Write(0Xff);
AD7190_Write(0Xff);
AD7190_Write(0Xff);
AD7190_Write(0Xff);//refer to datasheet P34 --reset
delay(100); //延时函数
while( AD_RDY);
AD7190_Write(0X10);//选择Configuration regisster(24 bit,with 3 turns)
AD7190_Write(0x80);//chop enabled
AD7190_Write(0x10);//选择AIN1 to AINCOM channel
AD7190_Write(0x08);//unbuffer model,current关闭,gain =1 ,单极性
while( AD_RDY);
AD7190_Write(0x08);//选择模式寄存器,内部零点校准(24 bit,with 3 turns)
AD7190_Write(0x88);//Internal zero-scale calibration Model
AD7190_Write(0x00);
AD7190_Write(0x01);
while( AD_RDY);
AD7190_Write(0x08);//选择模式寄存器,内部满量程校准(24 bit,with 3 turns)
AD7190_Write(0xa8);//Internal full-scale calibration Model
AD7190_Write(0x00);
AD7190_Write(0x01);
while( AD_RDY);
AD7190_Write(0x08);//选择模式寄存器(24 bit,with 3 turns)
AD7190_Write(0x08);//连续转换模式
AD7190_Write(0x00);
AD7190_Write(0x18);//Filter output data rate select
}
//========================读数据=====================//
unsigned int Read_AD7190(void)
{
unsigned long AD_result;
AD7190_Write(0x58);
AD_result= AD7190_Read();
AD_result=AD_result<<8;
AD_result= AD7190_Read()+ AD_result;
AD_result=AD_result<<8;
AD_result= AD7190_Read()+ AD_result;
return AD_result;
}
/*************************串口发送数据****************/
void uart1(long temp)
{
unsigned char c,d,e,f;
c="temp"; //最低位
d="temp">>8; //倒数第二位
e="temp">>16;
f="temp">>24;
TI=0;
SBUF=c;
while(!TI);
TI=0;
SBUF=d;
while(!TI);
TI=0;
SBUF=e;
while(!TI);
TI=0;
SBUF=f;
while(!TI);
}
void main(void)
{
long out;
AD7190_init();
//串行口的初始化;P196
SCON="0X70";
PCON="0X80";
TMOD="0x21" ;
TH1=0XF5;
TL1=0XF5;
TR1=1;//启动计数
EA="1";//开总中断
while(1)
{
while(AD_RDY);
out= Read_AD7190();
uart1(out);
}
} |
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|