Keil Logo

C51: A/D EXAMPLES FOR THE ADUC812


Information in this article applies to:

  • C51 Version 6.03
  • µVision2 Version 2.07

QUESTION

Are there any examples for the Analog Devices ADuC812 A/D converter?

ANSWER

Yes. 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 INFORMATION

You may download this complete ADuC812 example for µVision2 from the Keil web site.

SEE ALSO

Last Reviewed: Thursday, February 4, 2010


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.