void AD(void)
{
uint w_cfr=0xa802;//配置寄存器
uchar i=0;
uchar j=0;
uchar k=0;
uchar m=0;
uint addata_temp1[11]={0x0000};
ulint addata_sum1=0x00000000;
uint addata_temp2[11]={0x0000};
ulint addata_sum2=0x00000000;
DDRB=0X17;
PORTB=0XF9;//初始化spi端口
delay_1ms(5);
//SDI读数据,AD1
PORTB&=~(1<<PB0);//CS置'0'
for(i=0;i<16;i++)
{
w_cfr=w_cfr<<i;
PORTB|=(1<<PB1);//SCLK置'1'
PORTB|=((uchar)((w_cfr&0x8000)>>13));//将w_cfr送sdi
PORTB&=~(1<<PB1);//SCLK置'0'
}
if(getb(PINE,4)==0) delay_us(5);
PORTB|=(1<<PB0);//CS置'1'
delay_1ms(5);
//转换模式00
for(k=0;k<6;k++)
{
for(m=0;m<11;m++)
{
PORTB&=~(1<<PB0);//CS置'0'
for(j=0;j<16;j++)
{
temp_ch[k]=temp_ch[k]<<j;
PORTB|=(1<<PB1);//SCLK置'1'
PORTB|=((uchar)((temp_ch[k]&0x8000)>>13));//将temp_ch[k]的选择通道数据送sdi
addata_temp1[m]|=getb(PINB,3);//读sdo
addata_temp1[m]=addata_temp1[m]<<(15-j);
PORTB&=~(1<<PB1);//SCLK置'0'
}
if(getb(PINE,4)==0) delay_us(5);
PORTB|=(1<<PB0);//CS置'1'
}
for(m=1;m<11;m++)
{
addata_sum1=addata_sum1+addata_temp1[m];
}
temp_ad1[k]=(uint)((double)addata_sum1/10);
}
//AD2
PORTB&=~(1<<PB4);//CS置'0'
for(i=0;i<16;i++)
{
w_cfr=w_cfr<<i;
PORTB|=(1<<PB1);//SCLK置'1'
PORTB|=((uchar)((w_cfr&0x8000)>>13));//将w_cfr送sdi
PORTB&=~(1<<PB1);//SCLK置'0'
}
if(getb(PINE,4)==0) delay_us(5);
PORTB|=(1<<PB4);//CS置'1'
delay_1ms(5);
//转换模式00
for(k=0;k<6;k++)
{
for(m=0;m<11;m++)
{
PORTB&=~(1<<PB4);//CS置'0'
for(j=0;j<16;j++)
{
temp_ch[k]=temp_ch[k]<<j;
PORTB|=(1<<PB1);//SCLK置'1'
PORTB|=((uchar)((temp_ch[k]&0x8000)>>13));//将temp_ch[k]的选择通道数据送sdi
addata_temp2[m]|=getb(PINB,3);
addata_temp2[m]=addata_temp2[m]<<(15-j);
PORTB&=~(1<<PB1);//SCLK置'0'
}
if(getb(PINE,4)==0) delay_us(5);
PORTB|=(1<<PB4);//CS置'1'
}
for(m=1;m<11;m++)
{
addata_sum2=addata_sum2+addata_temp2[m];
}
temp_ad2[k]=(uint)((double)addata_sum2/10);
}
}
//请问谁用过TLC3578,如果用过可以给我讲讲吗?qq:836625592 |