keil_examples/ADC/adc.c
/*****************************************************************************
** Function name:		ADCRead
**
** Descriptions:		Read ADC channel
**
** parameters:			Channel number
** Returned value:		Value read, if interrupt driven, return channel #
** 
*****************************************************************************/
Function name:         ADCRead
Descriptions:          Read ADC channel

Channel number
Returned value:                Value read, if interrupt driven, return channel
Function name : ADCRead Descriptions : Read ADC channel Channel number Returned value : Value read if interrupt driven return channel
uint32_t ADCRead( uint8_t channelNum )
{
#if !ADC_INTERRUPT_FLAG
  uint32_t regVal, ADC_Data;
#endif
  if ( channelNum >= ADC_NUM )
  {
	channelNum = 0;		
  }
  LPC_ADC->CR &= 0xFFFFFF00;
  LPC_ADC->CR |= (1 << 24) | (1 << channelNum);	
#if !ADC_INTERRUPT_FLAG
  while ( 1 )			
  {
	regVal = LPC_ADC->DR[channelNum];
	if ( regVal & ADC_DONE )
	{
	  break;
	}
  }	
  LPC_ADC->CR &= 0xF8FFFFFF;	    
  if ( regVal & ADC_OVERRUN )	
  {
	return ( 0 );
  }
  ADC_Data = ( regVal >> 4 ) & 0xFFF;
  return ( ADC_Data );	
#else
  return ( channelNum );	
#endif
}
uint32_t ADCRead ( uint8_t channelNum ) { #if ! ADC_INTERRUPT_FLAG uint32_t regVal , ADC_Data ; #endif if ( channelNum >= ADC_NUM ) { channelNum = 0 ; } LPC_ADC -> CR &= 0xFFFFFF00 ; LPC_ADC -> CR |= ( 1 << 24 ) | ( 1 << channelNum ) ; #if ! ADC_INTERRUPT_FLAG while ( 1 ) { regVal = LPC_ADC -> DR [ channelNum ] ; if ( regVal & ADC_DONE ) { break ; } } LPC_ADC -> CR &= 0xF8FFFFFF ; if ( regVal & ADC_OVERRUN ) { return ( 0 ) ; } ADC_Data = ( regVal >> 4 ) & 0xFFF ; return ( ADC_Data ) ; #else return ( channelNum ) ; #endif }
Function name:         ADCRead
Descriptions:          Read ADC channel
Function name : ADCRead Descriptions : Read ADC channel
/* channel number is 0 through 7 */ /* reset channel number to 0 */ /* switch channel,start A/D convert */ /* wait until end of A/D convert */ /* read result of A/D conversion */ /* stop ADC now */ /* save data when it's not overrun, otherwise, return zero */ /* return A/D conversion value */ /* if it's interrupt driven, the ADC reading is 
							done inside the handler. so, return channel number */