Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.30 KB | None | 0 0
  1. void ADC_init( void ) {
  2.  
  3.  
  4.     // Enabled the Power controler in PCONP register. According the Table 46. the 12th bit is PCADC
  5.     LPC_SC->PCONP |= (1 << 12);
  6.  
  7.     // Poti is connected to port P0.25. We have to put the port P0.25 into the AD0.2 moe for anlaoge to digital conterting.
  8.     LPC_PINCON->PINSEL1 &= ~(0x3 << 18); // Remove all bits, Port P0.25 gets GPIO
  9.     LPC_PINCON->PINSEL1 |=  (0x1 << 18); // Switch P0.25 to AD0.2
  10.  
  11.     // No pull-up no pull-down (function 10) on the AD0.2 pin.
  12.     LPC_PINCON->PINMODE1 &= ~(0x3 << 18);
  13.     LPC_PINCON->PINMODE1 |=  (0x1 << 18);
  14.  
  15.     // A/D Control Register (Section 29.5.1)
  16.     LPC_ADC->ADCR = ( 1 <<  2)  |    // SEL=1        select channel 0~7 on AD0.2
  17.                     ( 4 <<  8)  |    // ADC clock is 25 MHz/5          
  18.                     ( 0 << 16 ) |    // BURST = 0    no BURST, software controlled
  19.                     ( 0 << 24 ) |    // START = 0    A/D conversion stops */
  20.                     ( 0 << 27 ) |    // EDGE = 0     CAP/MAT singal falling,trigger A/D conversion
  21.                     ( 1 << 21);      // PDN = 1      normal operation, Enable ADC                
  22.  
  23.     // Enabling A/D Interrupt Enable Register for all channels (Section 29.5.3)
  24.     LPC_ADC->ADINTEN = ( 1 <<  8);        
  25.  
  26.     // Registering the interrupt service for ADC
  27.     NVIC_EnableIRQ( ADC_IRQn );                  
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement