1. ad control register: select the pin to be converted clkdev start mode etc.

2. ad golbal date register:the result of conversion.

3. ad status register: the status of overrun and interrupt.

4. ad interrupt enable register: enable the interrupt of ad complete.

5. ad data register: hold the result when an ad conversion is complete.


代码:

uint32_t ADCRead( uint8_t channelNum )

{

#if !ADC_INTERRUPT_FLAG

  uint32_t regVal, ADC_Data;

#endif


  /* channel number is 0 through 7 */

  if ( channelNum >= ADC_NUM )

  {

channelNum = 0; /* reset channel number to 0 */

  }

  LPC_ADC->CR &= 0xFFFFFF00;

  LPC_ADC->CR |= (1 << 24) | (1 << channelNum);

/* switch channel,start A/D convert */

#if !ADC_INTERRUPT_FLAG

  while ( 1 ) /* wait until end of A/D convert */

  {

regVal = *(volatile unsigned long *)(LPC_ADC_BASE 

+ ADC_OFFSET + ADC_INDEX * channelNum);

/* read result of A/D conversion */

if ( regVal & ADC_DONE )  //0x80000000

{

 break;

}

  }

        

  LPC_ADC->CR &= 0xF8FFFFFF; /* stop ADC now */    

  if ( regVal & ADC_OVERRUN ) /* save data when it's not overrun, otherwise, return zero */

  {

return ( 0 );

  }

  ADC_Data = ( regVal >> 6 ) & 0x3FF;

  return ( ADC_Data ); /* return A/D conversion value */

#else

  return ( channelNum ); /* if it's interrupt driven, the ADC reading is 

done inside the handler. so, return channel number */

#endif

}