/*LPG LECKAGE DETECTION AND AUTO CALLING TO SELECTED PHONES
* FINAL YEAR PROJECT
* AMERICAN INTERNATIONAL UNIVERSITY-BANGLADESH
* MD. SHAKHAWAT HOSSEN (ID: 08-11488-2)
* MCU-PIC16RF690
*/
#include<pic.h>
#include<htc.h>
#define _XTAL_FREQ 4000000
__CONFIG (INTIO & WDTDIS & PWRTEN & MCLREN & UNPROTECT & UNPROTECT & BORDIS & IESODIS & FCMDIS);
#define LCD PORTC
#define rs RB4
//#define rw RB5
#define en RB5
#define t 10
void LCD_ini(unsigned char com);
void LCD_data(unsigned char cha);
void main(){
//OSCCON=01100010; //4MHz internal
ANSEL=0x03; // RA0 & RA1 are Analog.
ANSELH=0; //Rest of pins are digital.
// Comparator Block
TRISA0=1; // Ref input of Comparator.
TRISA1=1; //Input of Comparator.
TRISA2=0; //Output of Comparator.
TRISA5=0;
TRISA4=0;
C1CH0=0; //To select -V pin out of 4
C1CH1=0; // Here 00 pin(RA1) select
C1R=0; //Select Referance pin(RA0)
C1ON=1; //To ON the Comparator.
C1POL=1; //To invert the comparator result.
C1OE=1; //To eneble RA2 for getting result
//Comparator Block
//LCD Block
TRISC=0x00; // define output
TRISB=0x00; //define O/P
//LCD Block
int i,relay=1,count=1;
RB6=0; // Relay switch.
RB7=0; //LED blinking.
LCD_ini(0x38); //8 bit mode .
LCD_ini(0x0C); //Display on Cursor off.
LCD_ini(0x80); //Set DDRAM & Cursor position on display
while(1){
if(C1OUT==0){
relay=1;
count=1;
RB7=0; //LED blinking
RB6=0; // Relay switch.
LCD_ini(0x80); //Set DDRAM & Cursor position on display .
unsigned char j[]="GAS NOT FOUND... ";
for (int i=0 ; i <(sizeof j) ;i++){
LCD_data( j[i]);
__delay_ms(t);
}
LCD_ini(0xC0); // Start at 2nd row.
unsigned char m[]=" ############# ";
for (int i=0 ; i <(sizeof m) ;i++){
LCD_data(m[i]);
__delay_ms(t);
}
}
if(C1OUT==1){
RB7=1; //LED blinking
LCD_ini(0x80); //Set DDRAM & Cursor position on display .
unsigned char k[]=" GAS FOUND !! ";
for (int i=0 ; i <(sizeof k) ;i++){
LCD_data(k[i]);
__delay_ms(t);
}
LCD_ini(0xC0); //Start at 2nd row.
RB7=0; //LED blinking
unsigned char n[]=" Calling ............. !! ";
for (int i=0 ; i <(sizeof n) ;i++){
LCD_data(n[i]);
__delay_ms(t);
}
if(relay<=2){
RB6=1; // Relay switch.
relay++;
__delay_ms(50*t);
RB6=0; // Relay switch.
}
if(count==40) {
relay=1;
count=1;
}
count++;
}
}
}
void LCD_ini(unsigned char com){
LCD=com;
en=1;
rs=0;
//rw=0;
__delay_ms(t);
en=0;
__delay_ms(t);
}
void LCD_data(unsigned char cha){
LCD=cha;
en=1;
rs=1;
//rw=0;
__delay_ms(t);
en=0;
__delay_ms(t);
rs=0;
}