ADC HEADER
void delay(unsigned int value);
void lcdcmd(unsigned char value);
void lcddata(unsigned char value);
void lcdinit(void);
void lcddisplay(int row,unsigned char *str);
#define ldata PORTD
#define rs PORTBbits.RB3
#define rw PORTBbits.RB4
#define en PORTBbits.RB5
void lcddisplay(int row,unsigned char *str)
{
int k;
if (row==1)
lcdcmd(0x80);
else lcdcmd(0xC0);
for(k=0;k<16;k++)
{
if(str[k] !=0)
lcddata(str[k]);
else break;
}
while((k<16)){
lcddata(' ');
k++;
}
}
void delay(unsigned int value)
{
int i,j;
for(i=0;i<=value;i++)
for(j=0;j<=50;j++);
}
void lcdcmd (unsigned char value)
{
ldata=value;
rs=0;
rw=0;
en=1;
delay(1);
en=0;
}
void lcddata (unsigned char value)
{
ldata=value;
rs=1;
rw=0;
en=1;
delay(1);
en=0;
}
void lcdinit(void)
{
lcdcmd(0x38);
delay(1);
lcdcmd(0x0E);
delay(1);
lcdcmd(0x01);
delay(1);
lcdcmd(0x06);
delay(1);
}
PROGRAM
#include<P18F4520.h>
#include<stdio.h>
#include<stdlib.h>
#include "lcd.h"
#pragma config OSC=HS
#pragma config PWRT=OFF
#pragma config WDT=OFF
#pragma config DEBUG=OFF,LVP=OFF
#define LDATA PORTD
unsigned char text1[]={"PIC18F4520"};
unsigned char text2[]={"ADC O/P= "};
unsigned long ADCOUT;
unsigned char RD,ref[20];
void main()
{
TRISD=0x00;
TRISB=0x00;
TRISAbits.TRISA0=1;
ADCON0=0x01;
ADCON1=0x0C;
ADCON2=0x06;
lcdinit();
lcddisplay(1,text1);
lcddisplay(2,text2);
while(1)
{
ADCON0bits.GO=1;
while(ADCON0bits.DONE==1)
ADCOUT=ADRESH;
RD=ADCOUT*5/255;
sprintf(ref,"%d volt",RD);
lcddisplay(2,ref);
}
}
void delay(unsigned int value);
void lcdcmd(unsigned char value);
void lcddata(unsigned char value);
void lcdinit(void);
void lcddisplay(int row,unsigned char *str);
#define ldata PORTD
#define rs PORTBbits.RB3
#define rw PORTBbits.RB4
#define en PORTBbits.RB5
void lcddisplay(int row,unsigned char *str)
{
int k;
if (row==1)
lcdcmd(0x80);
else lcdcmd(0xC0);
for(k=0;k<16;k++)
{
if(str[k] !=0)
lcddata(str[k]);
else break;
}
while((k<16)){
lcddata(' ');
k++;
}
}
void delay(unsigned int value)
{
int i,j;
for(i=0;i<=value;i++)
for(j=0;j<=50;j++);
}
void lcdcmd (unsigned char value)
{
ldata=value;
rs=0;
rw=0;
en=1;
delay(1);
en=0;
}
void lcddata (unsigned char value)
{
ldata=value;
rs=1;
rw=0;
en=1;
delay(1);
en=0;
}
void lcdinit(void)
{
lcdcmd(0x38);
delay(1);
lcdcmd(0x0E);
delay(1);
lcdcmd(0x01);
delay(1);
lcdcmd(0x06);
delay(1);
}
PROGRAM
#include<P18F4520.h>
#include<stdio.h>
#include<stdlib.h>
#include "lcd.h"
#pragma config OSC=HS
#pragma config PWRT=OFF
#pragma config WDT=OFF
#pragma config DEBUG=OFF,LVP=OFF
#define LDATA PORTD
unsigned char text1[]={"PIC18F4520"};
unsigned char text2[]={"ADC O/P= "};
unsigned long ADCOUT;
unsigned char RD,ref[20];
void main()
{
TRISD=0x00;
TRISB=0x00;
TRISAbits.TRISA0=1;
ADCON0=0x01;
ADCON1=0x0C;
ADCON2=0x06;
lcdinit();
lcddisplay(1,text1);
lcddisplay(2,text2);
while(1)
{
ADCON0bits.GO=1;
while(ADCON0bits.DONE==1)
ADCOUT=ADRESH;
RD=ADCOUT*5/255;
sprintf(ref,"%d volt",RD);
lcddisplay(2,ref);
}
}