Hello,
I am currently working with LPC1788 of NXP,in that I entered into ADC peripheral with single channel for learning purpose.
For displaying the ADC converted data I am using the following code with PCLK as 12MHZ and ADC_CLK as same 12MHZ. And using display device as 16*2 LCD.
//Main func.
int main()
{
unsigned int res;
LPC_SC->PCONP |=(1<<15); //Power up the GPIO's
LPC_SC->PCLKSEL |= (1<<3); //Adding clkdiv value with the default value in PCLKSEL
LPC_GPIO0->DIR |=(7<<4) | (1<<16);//Assigning command lines and P0.16 as o/p
LPC_GPIO2->DIR |=(0xFF<<0); //Assigning data lines as o/p
LPC_GPIO1->DIR |=(1<<14); //Assigning P1.14 as o/p
LPC_GPIO0->CLR |=(1<<16);
LPC_GPIO1->CLR |=(1<<14);
lcd_init(); //Initiating lcd
adc_init();
lcd_string("ADC IN LPC1788");
lcd_cmnd(0xc0);
while(1)
{
res= adc_read();
delay(2);
conversion(res);
}
return TRUE;
}
//adc_read func.
int adc_read()
{
unsigned int adc_result,ADC_Data;
LPC_ADC->CR &= ~(0xFF<<0); //clearing the Channel already used ADC1 in SEL bit of CR
LPC_ADC->CR |= (1 << 24) | (1 << channelNum); // switch channel using SEL,start A/D convert
while(1)
{
adc_result = LPC_ADC->DR[channelNum];
if(adc_result & ADC_DONE)
{
break;
}
}
LPC_ADC->CR &= ~(7<<24); // stop ADC now (i.e.)CR[26:24]=000
ADC_Data = ( adc_result >> 4 ) & 0xFFF; //Getting adc converted result from 4th to 15th bit of DR
return ( ADC_Data );
}
//conversion func.
conversion(unsigned int val)
{
unsigned int m,n,o,p;
m=(val/1000);
n=(val%1000)/100;
o=(val%100)/10;
p=(val%100)%10;
lcd_data(m+0x30);
lcd_data(n+0x30);
lcd_data(o+0x30);
lcd_data(p+0x30);
}
But with this above code the ADC is working properly in simulation,but failed to work in core board and ADC value is not get displaying in LCD.
Can anybody give suggestions for this..:sad: