This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

im facing a problem with adc in lpc 2138.

The output is varying continously in my lcd even there is no change in the adc input.i want a code to display the output in lcd.please give any suggestions to my code.

#include <lpc21xx.h> /* LPC2200 definitions */
#include <stdio.h> /* standard I/O .h-file */
//#define VREF 3
int i,j; long val,adc_val; unsigned char d1=0,d2=0,d3=0,d4=0,d5=0,d6=0;

//extern void init_serial (void);

void delay(void);
void adc_init(void);
void adc_read(void);

void data(void);
void lcddata(unsigned char c);
void lcdcmd(unsigned char c);
void lcdinit(void);
void lcddisplay(unsigned char *ptr);
void message(unsigned char k,unsigned char *ptr1);

int main()
{ PINSEL0=0X00000000;
PINSEL1=0X00400000;
IODIR0=0X70000000;
IODIR1=0X00ff0000;

lcdinit();
delay();
//lcdcmd(0x01);
//delay(1000);
message(0x80,"ir measurement"); adc_init(); while(1)
{ adc_read();
data();
delay();
} }

void adc_init(void)
{ //PINSEL1=0x01000000;
ADCR&=0x00000000;
VPBDIV = 0x02; /*Set the Pclk to 30 Mhz */
ADCR|= 0x00210601;
}

void adc_read(void)
{

ADCR|= 0x01000000; /* Start A/D Conversion */
delay();
delay();
delay();

while ((ADDR & 0x80000000) == 0); /*Wait for the conversion to complete */
val=ADDR;
adc_val = ((val>> 6) & 0x00FF); /*Extract the A/D result */
}

void delay(void)
{ for(i=0;i<=75;i++)
for(j=0;j<=1000;j++);
}

void lcddata(unsigned char c)
{ IOCLR1=0x00ff0000;
IOSET0=0x10000000; // rs =1 p0.28
IOCLR0=0x20000000; // rw =0 p0.29
IOSET0=0x40000000; // en=1 p0.30
IOSET1 = c<<16;
delay();
IOCLR0=0x40000000; //en=0 p0.30
}

void lcdcmd(unsigned char c)
{ IOCLR1=0x00ff0000;
IOCLR0=0x10000000; // rs =0 p0.28
IOCLR0=0x20000000; // rw =0 p0.29
IOSET0=0x40000000; // en=1 p0.30
IOSET1 = c<<16;
delay();
IOCLR0=0x40000000; //en=0 p0.30
} void lcdinit()
{ lcdcmd(0x38);
delay();
lcdcmd(0x01);
delay();
lcdcmd(0x0c);
delay();
//lcdcmd(0x01);
//delay();
lcdcmd(0x80);
delay();
}

void lcddisplay(unsigned char *ptr)
{ while(*ptr)
{ lcddata(*ptr);
ptr++;
} }

void message(unsigned char k,unsigned char *ptr1)
{ lcdcmd(k);
delay();
lcddisplay(ptr1);
}

void data(void)
{

d1=adc_val/10;
d2=adc_val%10;
d3=d1/10;
d4=d1%10;

//d5=d3/10;
//d6=d3%10;

lcdcmd(0xc0); delay(); lcddata(d3+0x30);
//lcddata(d6+0x30);
lcddata(d4+0x30);
lcddata(d2+0x30);

}

Parents
  • 1) Debug to find out if the "varying" data you see are correctly captured or not.
    2) Debug to find out if the "varying" data you see are correctly displayed or not.
    3) Decide if you need to implement software filtering as low-pass filter.
    4) Decide if you need to improve the voltage reference or better filter the supply voltages to reduce noise.

Reply
  • 1) Debug to find out if the "varying" data you see are correctly captured or not.
    2) Debug to find out if the "varying" data you see are correctly displayed or not.
    3) Decide if you need to implement software filtering as low-pass filter.
    4) Decide if you need to improve the voltage reference or better filter the supply voltages to reduce noise.

Children