jjeevan007
Full Member level 5
- Joined
- Apr 13, 2012
- Messages
- 310
- Helped
- 44
- Reputation
- 88
- Reaction score
- 43
- Trophy points
- 1,308
- Location
- bangalore
- Activity points
- 2,782
hi to all,
i am new to LPC1768, i have the io toggling and lcd program.
but now i am stuck with the adc.
please help its urgent
here is code
regards
jeevan
i am new to LPC1768, i have the io toggling and lcd program.
but now i am stuck with the adc.
please help its urgent
here is code
Code:
#include<lpc17xx.h>
void ADC_initail()
{
LPC_PINCON->PINSEL3=0xc0000000;
LPC_ADC->ADCR=0x00200120;
}
void GPIO_config()
{
LPC_PINCON->PINSEL0=0x00000000;
LPC_PINCON->PINSEL1=0x00000000;
LPC_PINCON->PINSEL2=0x00000000;
LPC_PINCON->PINSEL3=0x00000000;
LPC_PINCON->PINSEL4=0x00000000;
LPC_PINCON->PINSEL5=0x00000000;
LPC_PINCON->PINSEL6=0x00000000;
LPC_PINCON->PINSEL7=0x00000000;
LPC_PINCON->PINSEL8=0x00000000;
LPC_PINCON->PINSEL9=0x00000000;
LPC_PINCON->PINSEL10=0x00000000;
}
void delay(unsigned int m)
{
unsigned int i,j;
for(i=0;i<m;i++)
for(j=0;j<12000;j++);
}
void command(unsigned char da)
{
unsigned int val;
LPC_GPIO2->FIODIR=0X000038ff;
LPC_GPIO2->FIOCLR=0X000038ff;
delay(4);
val=da;
LPC_GPIO2->FIOSET=val;
LPC_GPIO2->FIOSET=0X00002000;
LPC_GPIO2->FIOCLR=0X00002000;
}
void dataa(unsigned char da)
{
unsigned int val;
LPC_GPIO2->FIODIR=0X000038FF;
LPC_GPIO2->FIOCLR=0X000038FF;
delay(3);
val=da;
LPC_GPIO2->FIOSET=val;
LPC_GPIO2->FIOSET=0X000002800;
LPC_GPIO2->FIOCLR=0X000002000;
}
void lcd_initail()
{
command(0x38);
command(0x0e);
command(0x06);
command(0x01);
}
int main()
{
unsigned int adc_val;
unsigned char a[4]={0};
GPIO_config();
ADC_initail();
lcd_initail();
while(1)
{
LPC_ADC->ADCR=(LPC_ADC->ADCR | 0x01000000);
while((LPC_ADC->ADGDR & 0x80000000)==0x00000000);
adc_val=(LPC_ADC->ADGDR & 0x0000fff0);
adc_val=adc_val>>4;
a[0]=adc_val%10;
adc_val=adc_val/10;
a[1]=adc_val%10;
adc_val=adc_val/10;
a[2]=adc_val%10;
adc_val=adc_val/10;
a[3]=adc_val%10;
command(0xc0);
dataa(a[3]);
dataa(a[2]);
dataa(a[1]);
dataa(a[0]);
}
}
regards
jeevan
Last edited: