估计是程序的问题,因为硬件电路图是抄的
#include<stdio.h>
#include<aduc841.h>
/******************************************************************
DEFINE CONTROL PINS OF ADUC841 FOR THE PURPOSE OF AD7792 CONTROL.
Customers should define the pins according to their design.
int ResetTime;
/* Set up UART */
T3CON = 0x086;
T3FD = 0x08;
SCON = 0x052;
printf("Hello\r\n");
/* PRECONFIGURE...*/
ResetTime=32;
SCLOCK=1;
CS=0; //to keep DIN=1 for 32 sclock to reset the part
DIN=1;
while(ResetTime--)
{
Delay(10);
SCLOCK=0;
Delay(10);
SCLOCK=1;
}
CS=1;
printf("Reset\r\n");
WriteToReg(0x10); //write to Communication register.The next step is writing to Configuration register.选择配置寄存器0x10
WriteToReg(0x00); //set the Configuration bipolar mode.Gain=1. 配置寄存器的高8位--双极模式
WriteToReg(0x80); //Configuration internal reference selected. 低8位--有缓冲器
WriteToReg(0x08);//write to Communication register.The next step is writing to Mode register.选择模式寄存器0x08
WriteToReg(0x20);//set the mode register as single conversion mode. 单次转换模式
WriteToReg(0x0A);//inter 64 kHZ clock.internal clock is not available at the clk pin. 内部 64k时钟不提供给clk引脚
WriteToReg(0x40);//write to Communication register.The next step is to read from Status register.读时候为状态寄存器,写时候为通信寄存器
ReadFromReg(1);
while((DataRead[0]&0x80)==0x80)//wait for the end of convertion by polling the status register RDY bit
{
WriteToReg(0x40);
ReadFromReg(1);
}
WriteToReg(0x58);//write to Communication register.The next step is to read from Data register.选择数据寄存器并且读数据寄存器0x58
ReadFromReg(2);
printf("Data:%02BX %02BX\r\n",DataRead[0],DataRead[1]);
void ReadFromReg(unsigned char nByte) // nByte is the number of bytes which need to be read
{
int i,j;
unsigned char temp;
DIN=1;
CS=0;
temp=0;
DOUT=1;
CS=0; //to keep DIN=1 for 32 sclock to reset the part
DIN=1;
while(ResetTime--)
{
Delay(10);
SCLOCK=0;
Delay(10);
SCLOCK=1;
}
CS=1;
////////////////////////////////////////////////////////////
WriteToReg(0x10); //write to Communication register.The next step is writing to Configuration register.选择配置寄存器0x10
WriteToReg(0x10); //set the Configuration bipolar mode.Gain=1. 配置寄存器的高8位--双极模式
WriteToReg(0x80); //Configuration internal reference selected. 低8位--有缓冲器
//////////////////////////////////////////////////////////////////
WriteToReg(0x28);//写io寄存器
WriteToReg(0x03); //使能和选择激励电流
for(;;)
{
//ReadAll_AD();//读取模拟接口
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
WriteToReg(0x08);//write to Communication register.The next step is writing to Mode register.选择模式寄存器0x08
WriteToReg(0x20);//set the mode register as single conversion mode. 单次转换模式
WriteToReg(0x0A);//inter 64 kHZ clock.internal clock is not available at the clk pin.内部 64k时钟不提供给clk引脚
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
WriteToReg(0x40);//write to Communication register.The next step is to read from Status register.读时候为状态寄存器,写时候为通信寄存器
ReadFromReg(1);
while((DataRead[0]&0x80)==0x80)//wait for the end of convertion by polling the status register RDY bit
{
WriteToReg(0x40);
ReadFromReg(1);
}
WriteToReg(0x58);//write to Communication register.The next step is to read from Data register.选择数据寄存器并且读数据寄存器0x58
ReadFromReg(2);
__RESET_WATCHDOG(); /* feeds the dog */
} /* loop forever */