0% found this document useful (0 votes)
144 views

LCD Program in Embedded C

This document contains code to display temperature and pressure readings from an ADC on an LCD screen. It defines the LCD pins and ports, takes the average of 12 ADC readings over 1 minute for temperature and pressure, converts the binary ADC outputs to decimal values, and uses printf and LCD commands to display the temperature and pressure values on the LCD screen continuously in a main loop.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
144 views

LCD Program in Embedded C

This document contains code to display temperature and pressure readings from an ADC on an LCD screen. It defines the LCD pins and ports, takes the average of 12 ADC readings over 1 minute for temperature and pressure, converts the binary ADC outputs to decimal values, and uses printf and LCD commands to display the temperature and pressure values on the LCD screen continuously in a main loop.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

TO DISPLAY TEMPERATURE AND PRESSURE FROM ADC ON THE LCD #include<stdio.h> #include<P18F452.h> #define ldata PORTD #define rs PORTEbits.

RE0 #define rw PORTEbits.RE1 #define en PORTEbits.RE2

//Set port D as data port //Set PORT E as control port

void main() { do { float k; int conversion(); temp= average_t(decimalNumber1); TRISB=0; TRISE=0; en=0; MSdelay(250); lcdcmd(0x0E); MSdelay(15); lcdcmd(0x01); MSdelay(15); lcdcmd(0x06); MSdelay(15); lcdcmd(0x80); lcddata('T'); lcdcmd(0x81); lcddata('E'); lcdcmd(0x82); lcddata('M'); lcdcmd(0x83); lcddata('P'); lcdcmd(0x85); msdelay(15); printf("%03.1f%c",temp,0*df); pres=average_p(decimalNumber2); lcdcmd(0x94); lcddata('P'); lcdcmd(0x95); lcddata('R'); lcdcmd(0x96); lcddata('E'); lcdcmd(0x97); lcddata('S'); lcdcmd(0x99); printf("%02.1f%c,pres,0*df);

}while(1); }

lcddata(unsigned char input) { ldata=input; rs=1; rw=0; MSdelay(1); en=0; } lcdcmd(unsigned char input) { ldata=input; rs=1; rw=0; MSdelay(1); en=0; } MSdelay(unsigned int itime) { unsigned inti,j; for(i=0;i<itime;i++) for(j=0;j<135;j++); } //Delay function

int conversion() { long int binaryNumber1; long int binaryNumber2; int decimalNumber1=0; int decimalNumber2=0; int j=1; int remainder; binaryNumber1=<input from adc temp> binaryNUmber2=<input from press adc> while(binaryNumber1!=0) {

//Convert binary to decimal

remainder=binaryNumber1%10; decimalNumber1=decimalNumber1+remainder*j; j=j*2; binaryNumber1=binaryNumber1/10;

} while(binaryNumber2!=0) { remainder=binaryNumber2%10; decimalNumber2=decimalNumber2+remainder*j; j=j*2; binaryNumber2=binaryNumber2/10; } return 0; } float average_t(float deci) e for temperature { float value,value1; int k=0; while(k<12) { float x=0; x=deci+x; k++; return(x); MSdelay(5000); conversion(); } value=x%12; vlaue1=value*200; return(value1); } float average_p(float deci) e for pressure { float value,value1; int k=0; while(k<12) { float x=0; x=deci+x; k++; return(x); MSdelay(5000); conversion(); } value=x%12; vlaue1=value*4; return(value1); } //Take average of 12 values over 1 minut //Take average of 12 values over 1 minut

You might also like