如下是驱动,但是DRDY这个引脚一直没法是低电平?程序如下:请高手指点,
void main(void){
unsigned char i;
init();
ADCON0=0X01;
ADCON1=0X0e;
ADCON2=0Xa5;
Delay1KTCYx(40);
//TM7705初始化
PORTAbits.RA4=1;
for(i=0;i<40;i++)
{
TM7705_SCLK=0;
Delay10TCYx(2);
TM7705_SCLK=1;
Delay10TCYx(2);
}
Delay10TCYx(40);
//*********************************************************************
TM7705_write(0x20); //写通讯寄存器,选择下一步写时钟寄存器
TM7705_write(0x00);
TM7705_write(0x10); //写通讯寄存器,选择下一步写设置寄存器
// TM7705_write(0x7C); //写设置寄存器,设置增益为128,单极性,自校准,并启动AD转
TM7705_write(0x78); //写设置寄存器,设置增益为128,双极性,自校准,并启动AD转换
//*********************************************************************
while(1){
unsigned char Temp1,Temp2;
// Key_seek();
key_cnt=0;
if(!TM7705_DRY){ //等待DRDY为0
TM7705_write(0x38); //读通道0
Temp1 = TM7705_read();
Temp2 = TM7705_read();
}
}
}
//******************************************
unsigned char TM7705_read(void)
{
unsigned char data=0,i;
TM7705_SCLK=1;
for(i=0;i<8;i++)
{
TM7705_SCLK=0;
Delay10TCYx(2);
data=data<<1;
// Clr_TM7705_SCLK();
// delay_1us(); //等待数据稳定
if(TM7705_ADI)
{
data=data+1;
}
TM7705_SCLK=1;
Delay10TCYx(2);
}
TM7705_SCLK=1;
return data;
}
//******************************************
void TM7705_write(unsigned char dd)
{
unsigned char i;
TM7705_SCLK=1;
//Delay10TCYx(100);
for(i=0;i<8;i++)
{
TM7705_SCLK=0;
Delay10TCYx(2);
if(dd&0x80)
PORTAbits.RA4=1;
else
PORTAbits.RA4=0;
Delay10TCYx(2);
TM7705_SCLK=1;
Delay10TCYx(2);
dd<<=1;
}
PORTAbits.RA4=1;
TM7705_SCLK=1;
} |