I have a problem my code to adc value in lcd using pic 16f877a

Status
Not open for further replies.

thunaivendan

Member level 3
Joined
Apr 19, 2013
Messages
61
Helped
0
Reputation
0
Reaction score
1
Trophy points
1,288
Location
Chennai, Tamil Nadu, India
Visit site
Activity points
1,732
#include<pic.h>
#include<string.h>
__CONFIG(0x3f72);
#ifndef _XTAL_FREQ
#define _XTAL_FREQ 20000000
#endif
#define DATA PORTD
#define RS RE1
#define EN RE2
#define lcd_strobe(){EN=1;__delay_us(160);EN=0;}
void lcd_cmd(unsigned char);//LCD display function
void lcd_dat(unsigned char);
void lcd_disp(const char *);
void lcd_num(unsigned char);
void main()
{
TRISA=0x01;
PORTA=0x01;
ADCON0=0x80;//choose fosc/32//choose ch1()//Taq>1.6us
ADCON1=0x8e;//AN0 only has analog pin
TRISD=0x00;
PORTD=0x00;
TRISE=0x00;
PORTE=0x00;
lcd_cmd(0x38);
lcd_cmd(0x38);
lcd_cmd(0x38);
lcd_cmd(0x38);
lcd_cmd(0x0E);
lcd_cmd(0x01);
lcd_cmd(0x0c);
lcd_cmd(0x80);
while(1)
{
//unsigned char val[20]="ADC VALUE:";
unsigned int adc, adc_value_h,adc_value_l,adc_value;
lcd_disp("ADC VALUE:");//Passing String
lcd_cmd(0x80);
__delay_ms(1000);
ADON=1;
//GO_DONE=1;
// __delay_us(20);
while(GO_DONE)//checking adc conversion
__delay_us(20);// ADIF=0;
adc_value_h=ADRESH;// adc_value_h=adc_value_h<<8;
adc_value_l=ADRESL;
adc=adc_value_h<<8;
adc_value=(adc)|adc_value_l;
adc_value=(unsigned char)(adc_value*204.8);//adc conversion
lcd_num(adc_value);
}
}
void lcd_cmd(unsigned char cmd)
{
DATA=cmd;
RS=0;
lcd_strobe();
}
void lcd_dat(unsigned char dat)
{
DATA=dat;
RS=1;
lcd_strobe();
}
void lcd_disp(const char *val)
{
while(*val!='\0')
{
lcd_dat(*val++);
//val++;
}
}
void lcd_num(unsigned char adc_val)
{
unsigned char a,b,c,d;
a=((adc_val/100)+0x30);
lcd_dat(a);
lcd_cmd(0xC0);
b=(((adc_val/10)%10)+0x30);
lcd_dat(b);
lcd_cmd(0xC2);
c=(((adc_val%10)%10)+0x30);
lcd_dat(c);
lcd_cmd(0xC3);

}
in this code no..error..but it cant show in lcd,proteus..any one help me whats the solution for this..thank in advance
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…