16 bit 模数转换器
TM7705
{
/* the only pin that is programmed herefrom the 68HC11 is the /CS
and this is why the PC2 bit of PORTC is madeas
an output */
char a;
DDRC = 0x04; /* PC2 is an output the restof the port bits are inputs */
PORTC | = 0x04; /* make the /CS line high */
Writetoreg(0x20); /* Active Channel is Ain1(+)/Ain1(-),next operation aswrite to the
clock register*/
Writetoreg(0x0C); /* master clock enabled,4.9512MHz Clock, set output rate
to 50Hz*/
Writetoreg(0x10); /* Active Channel is Ain1(+)/Ain1(-),next operation aswrite to the
setup register*/
Writetoreg(0x40); /* gain = 1, bipolar mode, buffer off, clear FSYNC and perform a
Self Calibration*/
while(PORTC & 0x10); /* wait for /DRDY to go low */
for(a=0;a<NUM_SAMPLES;a++);
{
Writetoreg(0x38); /*set the next operation for 16 bit readfrom the data
register*/
Read(NUM_SAMPES,2);
}
}
Writetoreg(int byteword);
{
int q;
SPCR = 0x3f;
SPCR = 0X7f; /* this setsthe WiredOR mode(DWOM=1), Master mode(MSTR=1),
SCK idles high(CPOL=1),
/SS can be low always(CPHA=1), lowest clock
speed(slowestspeedwhich is masterclock /32 */
DDRD= 0x18; /* SCK, MOSI outputs */
q = SPSR;
q = SPDR; /* the readof the stausregisterand of the data register is neededto
clearthe interrupt which tells the userthat the data transfer is complete */
PORTC &= 0xfb; /* /CS is low */
SPDR = byteword; /* put the byte into data register*/
while(!(SPSR & 0x80));
/* wait for /DRDY to go low */
PORTC |=
0x4; /* /CS high */
}
Read(int amount, int reglength)
{
int q;
SPCR = 0x3f;
SPCR = 0x7f; /* clearthe interupt */
©Titan Micro Electronics
www.titanmec.com
-37-