.#include <ADUC816.H>
#include <stdio.h>

void main (void)
{
/*-----------------------------------------------
Configure the serial port
-----------------------------------------------*/
SCON  = 0x50;
TMOD |= 0x20;
TH1   = 0xFA;
TR1   = 1;
TI    = 1;
PCON |= 0x80;

/*-----------------------------------------------
Configure the A/D to sequentially convert each
input channel.
-----------------------------------------------*/
  ADC0CON = 0x07;
  SF = 0x0D;


while (1)
  {
  unsigned int conv_val;

/*-----------------------------------------------
Start a conversion and wait for it to complete.
-----------------------------------------------*/
  ADCMODE |= 0x22;								 /*Enables Primary ADC*/
  while (RDY0 != 1);
  RDY1 = 0;										/*Ready bit for PRIMARY ADC	 */

/*-----------------------------------------------																	  
Read A/D data and print it out.
-----------------------------------------------*/
  conv_val = ADC0M | ((ADC0H) << 8);

  
  printf ("Primary ADC Channel 3 = %urn", conv_val);
  }

}