Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void ADC_init( void ) {
- // Enabled the Power controler in PCONP register. According the Table 46. the 12th bit is PCADC
- LPC_SC->PCONP |= (1 << 12);
- // 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.
- LPC_PINCON->PINSEL1 &= ~(0x3 << 18); // Remove all bits, Port P0.25 gets GPIO
- LPC_PINCON->PINSEL1 |= (0x1 << 18); // Switch P0.25 to AD0.2
- // No pull-up no pull-down (function 10) on the AD0.2 pin.
- LPC_PINCON->PINMODE1 &= ~(0x3 << 18);
- LPC_PINCON->PINMODE1 |= (0x1 << 18);
- // A/D Control Register (Section 29.5.1)
- LPC_ADC->ADCR = ( 1 << 2) | // SEL=1 select channel 0~7 on AD0.2
- ( 4 << 8) | // ADC clock is 25 MHz/5
- ( 0 << 16 ) | // BURST = 0 no BURST, software controlled
- ( 0 << 24 ) | // START = 0 A/D conversion stops */
- ( 0 << 27 ) | // EDGE = 0 CAP/MAT singal falling,trigger A/D conversion
- ( 1 << 21); // PDN = 1 normal operation, Enable ADC
- // Enabling A/D Interrupt Enable Register for all channels (Section 29.5.3)
- LPC_ADC->ADINTEN = ( 1 << 8);
- // Registering the interrupt service for ADC
- NVIC_EnableIRQ( ADC_IRQn );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement