//********************************************************************************
//Author : Palak Patel(M.Tech)
//Contact No:9173211683
//Title:Temperature sensor interfacing with pic 18f
//Platform: pic18f4520
//Software:MPLAB
//********************************************************************************
#include<p18f4520.h>
#pragma config OSC = HS
#pragma config FCMEN = OFF
#pragma config IESO = OFF
#pragma config PWRT = OFF
#pragma config BOREN = OFF
#pragma config WDT = OFF
#pragma config PBADEN = OFF
#pragma config LPT1OSC = OFF
#pragma config MCLRE = ON
#pragma config STVREN = OFF
#pragma config LVP = OFF
#pragma config XINST = OFF
#define ldata PORTD
#define rs PORTCbits.RC0
#define rw PORTCbits.RC1
#define en PORTCbits.RC2
void temp_dis(void);
void MSDelay(unsigned int);
void lcdcmd(unsigned char);
void lcddata(unsigned char);
unsigned char x;
unsigned char type[5] = "TEMP";
unsigned char temp[4];
void main()
{
unsigned int x=0;
unsigned int y;
unsigned int c=0x100;
unsigned int z,x1;
unsigned char k;
float p,tmpr,f;
ADCON1=0x0E;
TRISA=0x01;
TRISD=0;
TRISC=0;
en=0;
lcdcmd(0x38); //2-lines and 5x7 matrix 8 bit initialization
MSDelay(50);
lcdcmd(0x0E); //Display on, Cursor blinking
lcdcmd(0x01); //Clear screen
lcdcmd(0x84); //Position first line 5th character
for(k=0;k<=3;k++)
{
lcddata(type[k]);
}
lcdcmd(0xC1); //Position second line 2nd character
/********************************/
ADCON0=0x00;
ADCON2=0x9C;
ADCON0bits.ADON = 1;
while(1)
{
ADCON0bits.GO=1;
while(ADCON0bits.GO==1);
x=ADRESH;
y=ADRESL;
z=(x*c)+y;
f=(z*(float)4.8875);
x1=(int)f;
temp[3] = (x1/1000)%10 + 48;
temp[2] = (x1/100)%10 + 48;
temp[1] = (x1/10)%10 + 48;
temp[0] = x1%10 + 48;
temp_dis();
MSDelay(20);
}
}
void temp_dis(void)
{
lcdcmd(0xC3);
lcddata(temp[3]);
lcddata(temp[2]);
lcddata(temp[1]);
lcddata('.');
lcddata(temp[0]);
lcddata(0x233);
lcddata('C');
}
void lcdcmd(unsigned char value)
{
ldata=value;
rs=0;
rw=0;
en=1;
MSDelay(20);
en=0;
}
void lcddata(unsigned char value)
{
ldata=value;
rs=1;
rw=0;
en=1;
MSDelay(20);
en=0;
}
void MSDelay(unsigned int itime)
{
unsigned int i,j;
for(i=0;i<=itime;i++)
for(j=0;j<=135;j++);
}
//Author : Palak Patel(M.Tech)
//Contact No:9173211683
//Title:Temperature sensor interfacing with pic 18f
//Platform: pic18f4520
//Software:MPLAB
//********************************************************************************
#include<p18f4520.h>
#pragma config OSC = HS
#pragma config FCMEN = OFF
#pragma config IESO = OFF
#pragma config PWRT = OFF
#pragma config BOREN = OFF
#pragma config WDT = OFF
#pragma config PBADEN = OFF
#pragma config LPT1OSC = OFF
#pragma config MCLRE = ON
#pragma config STVREN = OFF
#pragma config LVP = OFF
#pragma config XINST = OFF
#define ldata PORTD
#define rs PORTCbits.RC0
#define rw PORTCbits.RC1
#define en PORTCbits.RC2
void temp_dis(void);
void MSDelay(unsigned int);
void lcdcmd(unsigned char);
void lcddata(unsigned char);
unsigned char x;
unsigned char type[5] = "TEMP";
unsigned char temp[4];
void main()
{
unsigned int x=0;
unsigned int y;
unsigned int c=0x100;
unsigned int z,x1;
unsigned char k;
float p,tmpr,f;
ADCON1=0x0E;
TRISA=0x01;
TRISD=0;
TRISC=0;
en=0;
lcdcmd(0x38); //2-lines and 5x7 matrix 8 bit initialization
MSDelay(50);
lcdcmd(0x0E); //Display on, Cursor blinking
lcdcmd(0x01); //Clear screen
lcdcmd(0x84); //Position first line 5th character
for(k=0;k<=3;k++)
{
lcddata(type[k]);
}
lcdcmd(0xC1); //Position second line 2nd character
/********************************/
ADCON0=0x00;
ADCON2=0x9C;
ADCON0bits.ADON = 1;
while(1)
{
ADCON0bits.GO=1;
while(ADCON0bits.GO==1);
x=ADRESH;
y=ADRESL;
z=(x*c)+y;
f=(z*(float)4.8875);
x1=(int)f;
temp[3] = (x1/1000)%10 + 48;
temp[2] = (x1/100)%10 + 48;
temp[1] = (x1/10)%10 + 48;
temp[0] = x1%10 + 48;
temp_dis();
MSDelay(20);
}
}
void temp_dis(void)
{
lcdcmd(0xC3);
lcddata(temp[3]);
lcddata(temp[2]);
lcddata(temp[1]);
lcddata('.');
lcddata(temp[0]);
lcddata(0x233);
lcddata('C');
}
void lcdcmd(unsigned char value)
{
ldata=value;
rs=0;
rw=0;
en=1;
MSDelay(20);
en=0;
}
void lcddata(unsigned char value)
{
ldata=value;
rs=1;
rw=0;
en=1;
MSDelay(20);
en=0;
}
void MSDelay(unsigned int itime)
{
unsigned int i,j;
for(i=0;i<=itime;i++)
for(j=0;j<=135;j++);
}
No comments:
Post a Comment