| |||||
Technical Support Support Resources
Product Information | C51: A/D EXAMPLES FOR THE ADUC812Information in this article applies to:
QUESTIONAre there any examples for the Analog Devices ADuC812 A/D converter? ANSWERYes. The following example code programs and reads the A/D for that device.
#include <ADUC812.H>
#include <stdio.h>
void main (void)
{
unsigned char chan_2_convert;
/*-----------------------------------------------
Configure the serial port to run at 300 Baud.
Yeah, this is really slow!
-----------------------------------------------*/
SCON = 0x50;
TMOD |= 0x20;
TH1 = 0xA0;
TR1 = 1;
TI = 1;
/*-----------------------------------------------
Configure the A/D to sequentially convert each
input channel.
-----------------------------------------------*/
ADCCON1 = 0x7C; // 0111 1100
while (1)
{
unsigned int conv_val;
unsigned char channel;
/*-----------------------------------------------
Start a conversion and wait for it to complete.
-----------------------------------------------*/
chan_2_convert = (chan_2_convert + 1) % 8;
ADCCON2 = (ADCCON2 & 0xF0) | chan_2_convert;
SCONV = 1;
while (ADCCON3 & 0x80);
/*-----------------------------------------------
Read A/D data and print it out.
-----------------------------------------------*/
channel = ADCDATAH >> 4;
conv_val = ADCDATAL | ((ADCDATAH & 0x0F) << 8);
printf ("ADC Channel %bu = 0x%4.4X\r\n", channel, conv_val);
}
}
MORE INFORMATIONYou may download this complete ADuC812 example for µVision2 from the Keil web site. SEE ALSOLast Reviewed: Thursday, September 22, 2005 | ||||
| |||||