We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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);
}
what kind of filters should i use to make my sensor output stable.so that my adc output should not vary continously.
is any thing can be changed in the code (i.e conversion from binary to decimal).so that i can stable my output.
You can reduce the noise by software filtering. But note that bad filtering in hardware will probably result in not just noise by also significant scale/offset errors.
Note that I didn't ask how you connected your sensor to the ADC. I asked how you filtered the reference voltage for the ADC, and how this 3.3V is isolated from the 3.3V VCC that powers the processor.
You really, really, should take a look at GND/VREF/VCC and try to make them as stable as possible.
Filter caps on VCC - very, very close to the processor GND/VCC pins. Filter caps on VREF - and inductors in series with the signal after it splitted off from VCC.
Have you compared your design with available reference designs? You can find the schematics for the Keil boards on this site.