我写了个TI公司的TLC2543的AD芯片程序,怎么猜不到数值(采集里部满量程无反应)??请大神帮忙看看哪有问题???
sbit _CS=P3^5;
sbit CLOCK=P3^6;
sbit EOC=P3^7;
sbit D_IN=P2^4;
sbit D_OUT=P2^3;
unsigned char i=0;
void t100()
{ uchar i;
for(i=0;i<100;i++)
{}
}
unsigned int read2543(uchar port) //CON_WORD为选择的通道,为0--10
{
uint data ad;
uchar data i;
uchar data al=0,ah=0;
CLOCK=0;
_CS=0;
port<<=4;
for(i=0;i<4;i++)
{
D_IN=(bit)(port&0x80);
CLOCK=1;
CLOCK=0;
port<<=1;
}
D_IN=0;
for(i=0;i<8;i++)
{
CLOCK=1;
CLOCK=0;
}
_CS=1;
delay();
_CS=0;
for(i=0;i<4;i++)
{
D_OUT=1;
CLOCK=1;
ah<<=1;
if(D_OUT)ah|=0x01;
CLOCK=0;
}
for(i=0;i<8;i++)
{
D_OUT=1;
CLOCK=1;
al<<=1;
if(D_OUT) al|=0x01;
CLOCK=0;
}
_CS=1;
ad=(uint)ah;
ad<<=8;
ad|=al;
return(ad);
}
//读取平均值,形参:采集端口 ,采集次数
unsigned int avr_values(uchar port,uchar times)
{ unsigned int sum=0,average=0;
unsigned int get_values[]=0;
for(i=0;i<times;i++)
{
get_values[i]=read2543(port);
sum=sum+get_values[i];
}
average=sum/times;
return average;
} |