سلام دوستان کسی هست یه کتابخونه خوب از adc اماده کرده باشه در اختیار من بزاره؟ :cry:
در صورت امکان از CMSIS هم استفاده نشده باشه.
در صورت امکان از CMSIS هم استفاده نشده باشه.
//adc init by:Alireza Hammamizadeh ADC Clokc=12 Mhz uint16_t LPC1768_Read_Adc( unsigned char ch ) { uint32_t data; uint16_t adcdata; switch(ch) { case 0: //LPC_PINCON->PINSEL1 &= ~(1UL<<14);/* P0.23 is GPIO */ LPC_PINCON->PINSEL1|=1<<14;//AD0.0- GPIO P0.23 break; case 1: //LPC_PINCON->PINSEL1 &= ~(1UL<<16);/* P0.24 is GPIO */ LPC_PINCON->PINSEL1|=1<<16;//AD0.1- GPIO P0.24 break; case 2: //LPC_PINCON->PINSEL1 &= ~(1UL<<18);/* P0.25 is GPIO */ LPC_PINCON->PINSEL1|=1<<18;//AD0.2- GPIO P0.25 break; case 3: //LPC_PINCON->PINSEL1 &= ~(1UL<<20);/* P0.26 is GPIO */ LPC_PINCON->PINSEL1|=1<<20;//AD0.3- GPIO P0.26 break; case 4: //LPC_PINCON->PINSEL3 &= ~(3UL<<28);/* P1.30 is GPIO */ LPC_PINCON->PINSEL3|=3<<28;//AD0.4- GPIO P1.30 break; case 5: //LPC_PINCON->PINSEL3 &= ~(3UL<<30);/* P1.31 is GPIO */ LPC_PINCON->PINSEL3|=3<<30;//AD0.5- GPIO P1.31 break; } LPC_SC->PCONP|= (1<<12);/* Enable power to ADC block */ //// adc clock=12Mhz LPC_ADC->ADCR= (1<<ch) | (2<<8) | (1<<21) ;//set chanel & prescale & enable adc LPC_ADC->ADCR &= ~(7<<24);/* stop conversion */ LPC_ADC->ADCR |= (1<<24);/* start conversion */ while (!(LPC_ADC->ADGDR & (1UL<<31)));/* Wait for Conversion end */ data = LPC_ADC->ADGDR; data= ( data >> 4 ) ;/* read converted value */ adcdata=data; LPC_ADC->ADCR &= ~(7<<24);/* stop conversion */ return (adcdata); }
دیدگاه