#include<pic.

h>
#define FOSC
(20000000L)
#define RX
RCREG
#define TX
TXREG
#define rs RC0
#define rw RC1
#define enable RC2
#define lcd PORTD
#define buzzer RC4
void delay(unsigned int);
void lcd_init();
void pic_init();
void cmd(unsigned char);
void line1();
void line2();
void disp(unsigned char);
void print(const unsigned char*);
void data3(unsigned char);
void adc_read(void);
unsigned char get_serial(void);
unsigned char sci_Init(unsigned long int,unsigned char);
void data(unsigned char);
void disp1(short int);
unsigned int var1,var2;
float val;
unsigned int i,j;
//unsigned int i;
unsigned char addh,addl,lo,hi,data1,data2,trans,data2,cnt,cnt1=0,temp,temp1,b;
void main ()
{
int fflag=0,flag,first=0;
//double i;
pic_init();
delay(20);
sci_Init(9600,0);
delay(10);
lcd_init();
delay(20);
buzzer=1;
line1();
print(" GREEN HOUSE ");
//delay(100);
line2();
print("
");
delay(1000);
line1();

while(1)

print("Temperature "). RE0=1. adc_read(). b=get_serial(). delay(50). if(addl>35) // // { cmd(0x8E). disp(addl). "). "). delay(50). delay(1000). . delay(50). disp(addl). RCIF=0. print("Temperature Max "). print(" line1(). line1().{ RE0=1. print(" DEVICE1 ON RE0==0. while(!TRMT). while(!TRMT). RE1=1. RE2=1. fflag=0. line1(). addl=addl-35. delay(10). TX='1'. delay(1000). TX=temp. } } if(RB1==1) { line2(). TX=':'. while(RCIF!=1). fflag=0. while(!TRMT). fflag=0. TX='@'. if(b=='1') { line1(). cmd(0x8E). while(!TRMT). temp=addl. fflag=0.

while(!TRMT). print(" "). RCIF=0. TX='*'. RE1=1. while(RCIF!=1). cmd(0xce). line1(). delay(50). TX='1'. disp(b). delay(500). print(" "). } /*else { goto c11. while(!TRMT).print(" Light Sensor "). delay(50). b=get_serial(). while(!TRMT). fflag=0. delay(10). fflag=0. delay(1000). delay(500). . //cnt1=0. line1(). print(" DEVICE2 ON RE1==0. TX='1'. RCIF=0. fflag=0. "). delay(10). delay(50). }*/ if(b=='2') { line1(). if(RCIF==1) { b=get_serial(). while(!TRMT). } } if(RB2==1) { line2(). delay(1000). TX='#'. print("Gas Leak Detectd"). fflag=0.

1. /* asynchronous */ /* enable serial port pins */ /* enable reception */ . } } } unsigned char get_serial(void) { while(!RCIF) /* set when register is not empty */ continue. if((X>255) || (X<0)) { return 1. /* panic . delay(1000). /* set the baud rate */ SYNC = 0. return RCREG.if(b=='3') { line1().baud rate unobtainable */ } else BRGH = 0. print(" DEVICE3 ON RE2==0. SPEN = 1.1. X = (int)(FOSC/tmp) . RE2=1. unsigned char ninebits) { int X. unsigned long tmp. /* low baud rate */ } else BRGH = 1. /* high baud rate */ SPBRG = X. X = (int)(FOSC/tmp) . /* RXD9 and FERR are gone now */ } unsigned char sci_Init(unsigned long int baud. } "). if((X>255) || (X<0)) { tmp = 64UL * baud. CREN = 1. /* calculate and set baud rate register */ /* for asynchronous mode */ tmp = 16UL * baud.

enable=0. // TRISA=0X03.). /* enable the transmitter */ return 0. TXEN=1. RCIE = 1. } void pic_init() { //ADCON1=0X06. TRISA=0xFF. rw=0. SPBRG = 129.or 9-bit transmission */ ninebits?1:0. for (del=20. addl=ADRESL. er SPEN=1. // TRISB=0x00. /* no effect */ 0. TXSTA = 0X26. /* disable tx interrupts */ 0.del--. asm("NOP"). asm("NOP"). // PORTB=0x00. // PORTC=0x00.or 9-bit reception */ 1. } //20MHz-129 // reception control regist . } void adc_read(void) { unsigned char del. RCSTA = 0X90. TRISB=0xFF. delay(1). delay(25). } void data(unsigned char c) { lcd=c. ADGO=1. /* 8. /* disable rx interrupts */ ninebits?1:0. rs=1. TRISE=0x00. enable=1.// SREN TXIE RCIE TX9 RX9 TXEN = = = = = = 0. addh=ADRESH. /* 8. TRISC=0x88. while (ADGO). ADCON1 = 0x8E. // TRISC=0x00. TRISD=0X00. // TRISC=0x80. PEIE = 1. ADCON0=0x81. GIE = 1.

asm("NOP"). for(l=0.m<=29. enable=1. asm("NOP"). } void print(const unsigned char* c) { unsigned int i.l++) { for(m=0. enable=0.j++) { } } } } void cmd(unsigned char c) { lcd=c. rw=0. delay(80). enable=0. enable=1. rs=1. asm("NOP").i++) { lcd=*c. rw=0.m++) { for(j=0.m.j<=10. rs=0. delay(80). delay(80). delay(50). cmd(0x01). delay(80). delay(1). delay(80).i<16.l<=k. . } void line2() { cmd(0xC0). for(i=0.l. } void delay(unsigned int k) { int j. } void line1() { cmd(0x80). asm("NOP"). cmd(0x0C).void lcd_init() { cmd(0x38).

temp=c. data(temp2). } } void disp(unsigned char c) { unsigned char temp. data1 = data1/10. temp2+=0x30. temp2=temp%10. temp1=temp%10. //cmd(0x88). temp2+=0x30. cmd(0xc8). temp2+=0x30. temp2=temp/10.i=0. temp1+=0x30. data(temp1). temp1+=0x30. temp1=temp%10.temp3.temp1.temp2.c++. data(temp1). temp=temp/10. temp1+=0x30. data(temp2). while(data1!=0) { s[i] = data1%10. while(i>=0) { data(s[i]+0x30). temp4=temp%10. } i--. temp2=temp/10.temp1. i--. } } */ /* void disp2(unsigned char c) { unsigned char temp. . temp=c. i++. } /*void display(unsigned int data1) { int s[6]={0}. temp=temp/10. temp1=temp%10. }*/ void disp1(short int temp)// 4 digit display { int temp1. temp=temp/10.temp4. temp3=temp%10.temp2.temp2.

temp4+=0x30. data(temp2). } . data(temp3).temp3+=0x30. data(temp1). data(temp4).

Sign up to vote on this title
UsefulNot useful