keil_examples/ADC/adc.c
/*****************************************************************************
** Function name:		ADCInit
**
** Descriptions:		initialize ADC channel
**
** parameters:			ADC clock rate
** Returned value:		None
** 
*****************************************************************************/
Function name:         ADCInit
Descriptions:          initialize ADC channel

ADC clock rate
Returned value:                None
Function name : ADCInit Descriptions : initialize ADC channel ADC clock rate Returned value : None
void ADCInit( uint32_t ADC_Clk )
{
  uint32_t i, pclkdiv, pclk;
  LPC_SC->PCONP |= (1 << 12);
  for ( i = 0; i < ADC_NUM; i++ )
  {
	ADCValue[i] = 0x0;
  }
  LPC_PINCON->PINSEL0 &= ~0x000000F0;	
  LPC_PINCON->PINSEL0 |= 0x000000A0;	
  LPC_PINCON->PINSEL1 &= ~0x003FC000;	
  LPC_PINCON->PINSEL1 |= 0x00154000;
  LPC_PINCON->PINSEL3 |= 0xF0000000;	
  LPC_PINCON->PINMODE0 &= ~0x000000F0;
  LPC_PINCON->PINMODE0 |= 0x000000A0;
  LPC_PINCON->PINMODE1 &= ~0x003FC000;
  LPC_PINCON->PINMODE1 |= 0x002A8000;
  LPC_PINCON->PINMODE3 &= ~0xF0000000;
  LPC_PINCON->PINMODE3 |= 0xA0000000;
  pclkdiv = (LPC_SC->PCLKSEL0 >> 24) & 0x03;
  switch ( pclkdiv )
  {
	case 0x00:
	default:
	  pclk = SystemFrequency/4;
	break;
	case 0x01:
	  pclk = SystemFrequency;
	break; 
	case 0x02:
	  pclk = SystemFrequency/2;
	break; 
	case 0x03:
	  pclk = SystemFrequency/8;
	break;
  }
  LPC_ADC->CR = ( 0x01 << 0 ) |  
		( ( pclk  / ADC_Clk - 1 ) << 8 ) |   
		( 0 << 16 ) | 		
		( 0 << 17 ) |  		
		( 1 << 21 ) |  		
		( 0 << 24 ) |  		
		( 0 << 27 );		 
#if ADC_INTERRUPT_FLAG
  NVIC_EnableIRQ(ADC_IRQn);
#if BURST_MODE
  LPC_ADC->INTEN = 0xFF;		
#else
  LPC_ADC->INTEN = 0x1FF;		
#endif
#endif
  return;
}
void ADCInit ( uint32_t ADC_Clk ) { uint32_t i , pclkdiv , pclk ; LPC_SC -> PCONP |= ( 1 << 12 ) ; for ( i = 0 ; i < ADC_NUM ; i ++ ) { ADCValue [ i ] = 0x0 ; } LPC_PINCON -> PINSEL0 &= ~ 0x000000F0 ; LPC_PINCON -> PINSEL0 |= 0x000000A0 ; LPC_PINCON -> PINSEL1 &= ~ 0x003FC000 ; LPC_PINCON -> PINSEL1 |= 0x00154000 ; LPC_PINCON -> PINSEL3 |= 0xF0000000 ; LPC_PINCON -> PINMODE0 &= ~ 0x000000F0 ; LPC_PINCON -> PINMODE0 |= 0x000000A0 ; LPC_PINCON -> PINMODE1 &= ~ 0x003FC000 ; LPC_PINCON -> PINMODE1 |= 0x002A8000 ; LPC_PINCON -> PINMODE3 &= ~ 0xF0000000 ; LPC_PINCON -> PINMODE3 |= 0xA0000000 ; pclkdiv = ( LPC_SC -> PCLKSEL0 >> 24 ) & 0x03 ; switch ( pclkdiv ) { case 0x00 : default : pclk = SystemFrequency / 4 ; break ; case 0x01 : pclk = SystemFrequency ; break ; case 0x02 : pclk = SystemFrequency / 2 ; break ; case 0x03 : pclk = SystemFrequency / 8 ; break ; } LPC_ADC -> CR = ( 0x01 << 0 ) | ( ( pclk / ADC_Clk - 1 ) << 8 ) | ( 0 << 16 ) | ( 0 << 17 ) | ( 1 << 21 ) | ( 0 << 24 ) | ( 0 << 27 ) ; #if ADC_INTERRUPT_FLAG NVIC_EnableIRQ ( ADC_IRQn ) ; #if BURST_MODE LPC_ADC -> INTEN = 0xFF ; #else LPC_ADC -> INTEN = 0x1FF ; #endif #endif return ; }
Function name:         ADCInit
Descriptions:          initialize ADC channel
Function name : ADCInit Descriptions : initialize ADC channel
/* Enable CLOCK into ADC controller */ /* all the related pins are set to ADC inputs, AD0.0~7 */ /* P0.2~3, A0.6~7, function 10 */ /* P0.23~26, A0.0~3, function 01 */ /* P1.30~31, A0.4~5, function 11 */ /* No pull-up no pull-down (function 10) on these ADC pins. */ /* By default, the PCLKSELx value is zero, thus, the PCLK for
  all the peripherals is 1/4 of the SystemFrequency. */ /* Bit 24~25 is for ADC */ /* SEL=1,select channel 0~7 on ADC0 */ /* CLKDIV = Fpclk / ADC_Clk - 1 */ /* BURST = 0, no BURST, software controlled */ /* CLKS = 0, 11 clocks/10 bits */ /* PDN = 1, normal operation */ /* START = 0 A/D conversion stops */ /* EDGE = 0 (CAP/MAT singal falling,trigger A/D conversion) */ /* If POLLING, no need to do the following */ /* Enable all interrupts */ /* Enable all interrupts */