selvakumar c
Newbie level 4
Hi friends this is selvakumar i am interfacing ACD with LCD display, in that i am facing a problem with ADC reading
i could't get stable output in LCD display e.g For 5v analog input i get output like this- 1023,1021,1022(it does not remains constant) but
i get proper output in PROTEUS but not in real hardware .
this is my program
Any one help me to solve this problem....
Thank u..
i could't get stable output in LCD display e.g For 5v analog input i get output like this- 1023,1021,1022(it does not remains constant) but
i get proper output in PROTEUS but not in real hardware .
this is my program
Code:
#include<pic18.h> //pic18f452
#include<htc.h> //header file for delay
__CONFIG(1, OSC_HS );
__CONFIG(2, PWRT_ON & BOR_OFF & WDT_OFF);
__CONFIG(4, STVR_ON & LVP_OFF & DEBUG_OFF);
#define _XTAL_FREQ 11059200
#define rs RD0 //lcd control signal
#define rw RD1 //lcd control signal
#define en RD2 //lcd control signal
#define ld PORTB
unsigned char j=0,ad2 ;
int adc = 0;
unsigned char d1,d2,d3,d4,ad;
void delay()
{
unsigned char i,j;
for(i=0;i<150;i++)
for(j=0;j<150;j++);
}
void l_cmd(unsigned char t) //lcd command function
{
ld = t; rs=0;rw=0;en=1; __delay_ms(5); en=0;
}
void l_dt(unsigned char t) //lcd data function
{
ld = t; rs=1;rw=0;en=1; __delay_ms(5); en=0;
}
void l_init() //lcd initialization function
{
l_cmd(0x38);
l_cmd(0x00);
l_cmd(0x0c);
l_cmd(0x80);
}
void adt(unsigned char i)
{
d1 = i%10; i/=10;
d2 = i%10; i/=10;
d3 = i%10; i/=10;
d4 = i;
l_cmd(0x80);
l_dt(48+d4);
l_dt(48+d3);
l_dt(48+d2);
l_dt(48+d1);
}
void main()
{
unsigned char i;
TRISB = 0; //set portb as an output for lcd display
TRISD = 0; //set portd as an output for lcd display
TRISA = 0xff; //set porta as an input for adc
ADCON1 = 0x40; //ADFM=0(Left justified)
ADCON0 = 0x81; // ADON=1; Fosc/64 clock source
l_init();
__delay_ms(5);
l_dt('A');
delay();
while(1)
{
CHS0=0;CHS1=0;CHS2=0;GO=1; while(GO);l_cmd(0x80); adt(ADRESH); //read adc0 channel first
CHS0=1;CHS1=0;CHS2=0;GO=1; while(GO);l_cmd(0xC0); adt(ADRESH); //read adc1 channel second
CHS0=0;CHS1=1;CHS2=0;GO=1; while(GO);l_cmd(0x94); adt(ADRESH); //read adc2 channel thirt
CHS0=1;CHS1=1;CHS2=0;GO=1; while(GO);l_cmd(0xD4); adt(ADRESH); //read adc3 channel fourth
}
}
Any one help me to solve this problem....
Thank u..
Last edited by a moderator: