Temperature and Pressure Sensor part 2 (C++ code)
Voltage regulator:
It is used to regulate the
voltage. We are using 7805which gives us 5 voltage at output that is supply to
microcontroller.
These ripples
can be removed by using voltage regulator it provides us regulated constant
voltages. The purpose of a
voltage regulator is to keep the voltage in a circuit relatively close to a
desired value. Voltage regulators are one of the most common electronic
components, since a power supply frequently produces raw current that would
otherwise damage one of the components in the circuit. Voltage regulators have
a variety of specific functions, depending on their particular application
Buzzer, Oscillor and capacitors:
We
are using buzzer if the input value in greater than the room temperature. We
are using 8MHz oscillator and 2 capacitors of 30 microf.
Keypad:
We are using 3x4 keypad in this
project to enter digits.
Potentiometer:
This is used for variable
resistance.
C code:
#include
#pragma
config OSC = HS, OSCS = OFF
#pragma
config PWRT =OFF,LVP =OFF
#pragma
config DEBUG = OFF, STVR = OFF
#pragma
config WDT=OFF
#define
ldata PORTD
#define
rs PORTCbits.RC5
#define
rw PORTCbits.RC6
#define
en PORTCbits.RC7
far
rom const char mycom[] = {0x01,0x06,0x0C,0x80,'\0'};
far
rom const char mydata13[]="Temperature and\0";
far
rom const char mydata14[]="Pressure Sensor\0";
far
rom const char mydata15[]="PreSet Temp: \0";
far
rom const char mydata10[]="Temperature: \0"; //0=end of stirng
far
rom const char mydata2[]="Pressure: \0";
far
rom const char Unit[]="kPa \0";
void
LCDMSDelay(unsigned int);
void
lcddata(unsigned char);
void
lcdcmd(unsigned char);
void
MSDelay(unsigned char);
unsigned
char RBIF_ISR();
void
code_enter();
void
chk_isr ();
unsigned
char z ,cod, code[4] , temp[4], x , i , m ,l, a , b,j ,g, o,cnt=0;
unsigned
int nol ,noh , nom , nohh ,c, d, e, h, f, L, p;
unsigned
char keypad [4][3]={0x31,0x32,0x33,
0x34,0x35,0x36,
0x37,0x38,0x39,
'*',0x30,'#'};
void
chk_isr ();
#pragma
code my_hiprio_int =0x0008
void
my_hiprio_int(void)
{
_asm
GOTO
chk_isr
_endasm
}
#pragma
code
#pragma
interrupt chk_isr
void
chk_isr ()
{
if
(INTCONbits.RBIF==1)
RBIF_ISR
();
}
#pragma
code
unsigned char L_Byte,H_Byte;
unsigned char Bin_Temp,Bin_Pres,m;
unsigned char z,y = 'l';
void
main (void)
{
i=1;
TRISAbits.TRISA0=1;
TRISD=0;
TRISC=0;
TRISB=0xF0;
PORTB=0xF0;
PORTCbits.RC2 = 0;
TRISAbits.TRISA0=1;
TRISAbits.TRISA1=1;
TRISAbits.TRISA3=1;
en=0;
LCDMSDelay(150);
lcdcmd(0x38);
LCDMSDelay(150);
for(z=0;mycom[z]!='\0';z++)
{
lcdcmd(mycom[z]);
LCDMSDelay(10);
}
lcdcmd(0x8F);
for(z=0;mydata13[z]!='\0';z++)
{
lcdcmd(0x07);
lcddata(mydata13[z]);
MSDelay(60);
}
lcdcmd(0x01);
lcdcmd(0x8F);
for(z=0;mydata14[z]!='\0';z++)
{
lcdcmd(0x07);
lcddata(mydata14[z]);
MSDelay(60);
}
lcdcmd(0x01);
for(z=0;mycom[z]!='\0';z++)
{
lcdcmd(mycom[z]);
LCDMSDelay(50);
}
lcdcmd(0x01);
for(z=0;mydata15[z]!='\0';z++)
{
lcddata(mydata15[z]);
MSDelay(6);
}
MSDelay(700);
for(j=0;j<2 j="" o:p="">2>
{
code_enter();
}
for(z=0;mycom[z]!='\0';z++)
{
lcdcmd(mycom[z]);
LCDMSDelay(10);
}
MSDelay(250);
for(z=0;mydata10[z]!='\0';z++)
{
lcddata(mydata10[z]);
MSDelay(6);
}
lcdcmd(0xC0);
LCDMSDelay(10);
for(z=0; mydata2[z]!= '\0';z++)
{
lcddata(mydata2[z]);
MSDelay(3);
}
while(1)
{
lcdcmd(0x8C);
LCDMSDelay(3);
ADCON0=0x81;
ADCON1=0x85;
MSDelay(10);
ADCON0bits.GO=1;
while(ADCON0bits.DONE==1);
L_Byte=ADRESL;
H_Byte=ADRESH;
L_Byte>>=2;
L_Byte&=0x3F;
H_Byte<<=6;
H_Byte&=0xC0;
Bin_Temp= L_Byte|H_Byte;
z=Bin_Temp;
l=Bin_Temp;
l=Bin_Temp/10;
l=l+48;
lcddata(l);
Bin_Temp=Bin_Temp%10;
l=Bin_Temp+48;
MSDelay(1);
lcddata(l);
lcdcmd(0x8F);
MSDelay(1);
lcddata('C');
ADCON0bits.GO=0;
if(code[1] > z/10)
PORTCbits.RC2=1;
else
{
if(code[1] == z/10)
if(code[2] > (z % 10))
PORTCbits.RC2 = 1;
else;
}
MSDelay(9);
lcddata(l);
MSDelay(9);
lcdcmd(0xCA);
LCDMSDelay(3);
ADCON0=0x89;
ADCON1=0x80;
MSDelay(1);
ADCON0bits.GO=1;
while(ADCON0bits.GO==1);
L_Byte=ADRESL;
H_Byte=ADRESH;
L_Byte>>=2;
L_Byte&=0x3F;
H_Byte<<=6;
H_Byte&=0xC0;
Bin_Pres= L_Byte|H_Byte;
m=Bin_Pres;
m=Bin_Pres/100;
m=m+48;
lcddata(m);
Bin_Pres=Bin_Pres%100;
m=Bin_Pres/10;
m=m+48;
MSDelay(1);
lcddata(m);
m=Bin_Pres%10;
m=m+48;
lcddata(m);
MSDelay(1);
for
(z=0;Unit[z]!='\0';z++)
{
lcddata(Unit[z]);
MSDelay(1);
}
ADCON0bits.GO=0;
}}
void
lcdcmd(unsigned char value)
{
ldata= value;
rs=0;
rw=0;
en=1;
MSDelay(10);
en=0;
}
void
lcddata(unsigned char k)
{
ldata= k;
rs=1;
rw=0;
en=1;
MSDelay(10);
en=0;
}
void MSDelay(unsigned char itime)
{
unsigned char i;
unsigned char j;
for(i=0;i
for(j=0;j<165 j="" o:p="">165>
}
void LCDMSDelay(unsigned int itime)
{
unsigned int i,j;
for(i=0;i
for(j=0;j<135 j="" o:p="">135>
}
void code_enter()
{
INTCON2bits.RBPU=0;
while (PORTB !=0xF0)
{};
INTCONbits.RBIE=1;
INTCONbits.GIE=1;
while(!x)
{};
code[i]=x;
lcddata(code[i]);
code[i]
= code[i] - 48;
x=0;
i++;
MSDelay(15);
}
unsigned
char RBIF_ISR()
{
unsigned
char temp , COL=0, ROW=4 ;
temp=PORTB;
temp
^=0xF0;
if
(!temp) return;
while
(temp<<=1) COL++;
PORTB
= 0xFE;
if(PORTB
!=0xFE)
ROW=0;
else
{
PORTB
= 0xFD;
if(PORTB
!=0xFD)
ROW=1;
else
{
PORTB
= 0xFB;
if(PORTB
!=0xFB)
ROW=2;
else
{
PORTB
= 0xF7;
if(PORTB
!=0xF7)
ROW=3;
}
}
}
if(ROW<4 o:p="">4>
x=keypad
[ROW][COL];
MSDelay(250);
while(PORTB
!=0xF0) PORTB=0xF0;
INTCONbits.RBIF=0;
}
Applications
of Sensors:
Sensors
are used in everyday objects such as touch-sensitive elevator buttons and lamps
which dim or brighten by touching the base. There are also innumerable
applications for sensors of which most people are never aware. Applications
include cars, machines, aerospace, medicine, manufacturing and robotics. Some
more applications are in
ü
Pump/motor controller
ü
Level indicator
ü
Medical diagnostics
ü
Pressure switching
ü
Barometers
ü
Altimeters
Project
Cost:
Sr. No.
|
Componets
|
Rs/-
|
1
|
Pic18F452
|
360/-
|
2
|
LM35
|
65/-
|
3
|
3-Potentio Meter
|
15/-
|
4
|
Base for Pic18F452
|
50/-
|
5
|
16x2 LCD
|
450/-
|
6
|
3x4 Keypad
|
150/-
|
7
|
Buzzer
|
10/-
|
8
|
Voltage Regulator 7805
|
10/-
|
9
|
MPx2100
|
350/-
|
10
|
Battery
|
90/-
|
11
|
PCB
|
60/-
|
12
|
FeCl3
|
200/-
|
13
|
Slodering wire, paste
|
100/-
|
14
|
Oscillator,Capacitors
|
30/-
|
15
|
Total Cost
|
1940/-
|
0 comments:
Confused? Feel Free To Ask
Your feedback is always appreciated. We will try to reply to your queries as soon as time allows.