#include
#include
/******************************************************************
DEFINE CONTROL PINS OF ADUC832 FOR THE PURPOSE OF AD7734 CONTROL.
Customers should define the pins according to their design.
If P0 is used as the control port, pull-up resistors should be added to each pin of P0.
******************************************************************/
sbit CS=0x0A4;
sbit DIN=0x0A5;
sbit DOUT=0x0B4;
sbit DRDY=0x0B3;
sbit RESET=0x0A6;
sbit SCLOCK=0x0A7;
int sig;
void int0_int() interrupt 0{
sig=0;
return; }
void writetoreg(unsigned char);
void readfromreg(int);
void read(int);
void main()
{
int tim;
/* Set up UART */
T3CON = 0x082;
T3FD = 0x02D;
SCON = 0x052;
tim=1000;
/* PRECONFIGURE...*/
RESET=0;
while(tim--);
RESET=1;
SCLOCK=1;
DIN=1;
DOUT=1;
CS=1;
DRDY=1;
printf("\n");
writetoreg(0x28); //write to communication register. The next step is writing to channel setup register
writetoreg(0x08); //enable the channel AIN0, the input voltage range is +5V
writetoreg(0x30); //write to communication register. The next step is writing to channel conversion time register
writetoreg(0x91); //chop enabled, and the update rate is 2534Hz
/*writetoreg(0x38);//write to communication register . The next step is writing to MODE register
writetoreg(0x82);//ADC zero-scale calibration, 24 bit mode
while(DRDY);
printf("self zero-scale calibration finished.\n");
IT0=1;
EA=1;
EX0=1;
sig=1;
while(sig);*/
/*writetoreg(0x38);//write to communication register . The next step is writing to MODE register
writetoreg(0x0C2);//channel zero-scale calibration,24 bit mode
while(DRDY);
printf("channel zeroscale calibration finished.\n");
sig=1;
while(sig);
writetoreg(0x38);//write to communication register. The next step is writing to MODE register
writetoreg(0x0D2);//system full-scale calibration
while(DRDY);
printf("channel full-scale calibration finished.\n");
sig=1;
while(sig); */
writetoreg(0x44); //read from ADC status
readfromreg(8);
printf("\n");
writetoreg(0x60); //read from channel status
readfromreg(8);
printf("\n");
writetoreg(0x68); //read from channel setup
readfromreg(8);
printf("\n");
writetoreg(0x70); //read from channel conversion
readfromreg(8);
printf("\n");
writetoreg(0x78);//read from mode register
readfromreg(8);
printf("\n");
writetoreg(0x46);//read from adc zero-scale
readfromreg(24);
printf("\n");
writetoreg(0x50);//read from channel zero-scale
readfromreg(24);
printf("\n");
writetoreg(0x58);//read from channel full-scale
readfromreg(24);
printf("\n");
writetoreg(0x38);//writing to communication register, the next step is write to MODE register
writetoreg(0x22);//continuous conversion mode