Hi, I have started to program with lpc1768. In an example code in keil. I see that in this function it defines the pin P0.25 both GPIO and AD0.2, is it possible? Also I cant figure out how does this code configure GPIO for P0.25 by '= ~(3<<18)'
void ADC_init (void) { LPC_PINCON->PINSEL1 &= ~(3<<18); /* P0.25 is GPIO */ LPC_PINCON->PINSEL1 |= (1<<18); /* P0.25 is AD0.2 */ LPC_SC->PCONP |= (1<<12); /* Enable power to ADC block */ LPC_ADC->ADCR = (1<< 2) | /* select AD0.2 pin */ (4<< 8) | /* ADC clock is 25MHz/5 */ (1<<21); /* enable ADC */ LPC_ADC->ADINTEN = (1<< 8); /* global enable interrupt */ NVIC_EnableIRQ(ADC_IRQn); /* enable ADC Interrupt */ }
The pin can't be both. But the two assigns is there because the first assign uses &~ which can only clear flags. And the second assign uses | which can only set flags. And to get the value 01 from any previous value, you need both a clear and a set operation. Most sample code tends to assume that the registers have the default reset value which normally is 00 - and then no clear is needed. But a robust code should handle any combination of original bit values.