Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

hi i have problem in this code anyone help me ,thanks...

Status
Not open for further replies.

rajendiran.g

Newbie level 1
Newbie level 1
Joined
Dec 10, 2013
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
4
Code:
#include<pic.h>
#include "delay.c"

//declaration

__CONFIG(0x3f72);    	 //select HS oscillator,Enable(PWRTE,BOREN)



#define pirsensor RB7   	// PIR sensor
#define intruder RB6    //IR sensor

#define Relay1 RD0 	 // for light 

#define Relay2 RD1 	 // for motor

#define alarm RD2    	// Alarm


#define RS RE0		//Define RE0 as Register Select pin
#define RW RE1		//Define RE1 as Read/Write pin
#define EN RE2		//Define RE2 as LCD Enable pin


unsigned char msg_a[]=  {"  SMART HOUSE  "};
unsigned char msg_a1[]= {"   KARUNYA   "};

unsigned char msg1[]  = {" !!!  HUMAN  !!!"};	 //man
unsigned char msg11[] = {"!!!!! DETECTION !!!!"};



unsigned char msg4[]  = {"  INTRUDER  "};	 //thift
unsigned char msg41[] = {" DETECTION "};


unsigned char msg5[]  = {" ....TEMP....."};	 //temp
unsigned char msg51[] = {".....EXCEED... "};

unsigned char msg6[]  = {" .....FIRE ..... "};	 //fire
unsigned char msg61[] = {"  DETECTION  "};



void DelayMs(unsigned int del);	



unsigned char T,X      // variable for temp,fire

unsigned char temp(void);


void Serial_init(void); 

void lcdinit(void);			//LCD initialization Function
void lcdclr(void);			//LCD Clear Function			
void lcdcomd(unsigned char);		//LCD Command Declaring Fucntion
void lcddata(unsigned char);		//LCD Data Display Fucntion



unsigned char msg[]={" Smart House          "};



void lcdinit()
	{	
		int i;
		unsigned char command[]={0x38,0x0c,0x06};

		for(i=0;i<3;i++)
		  	{
			lcdcomd(command[i]);	//2x16 LCD, Display data from Left to right
			DelayMs(2);
			}
    }

void lcdclr()
	{
		lcdcomd(0x01);				//Clear Display Screen
		DelayMs(2);
	}                   
		
void lcdcomd(unsigned char cmd)
{	
	RS=0;							
	RW=0;
	EN=1;
	DATA=cmd;						//Move the command function through PORTB
	DelayMs(3);
	EN=0;	
}

void putch(unsigned char byte) 
{				
		RS=1;
		RW=0;
		EN=1;
		DATA=byte;					//Move the Data through PORTB
		DelayMs(3);
		EN=	0;
}




void main() 
{
int i=0,j=0,k=0,OFF = 0,set =1;

	TRISD = 0x00;
	TRISB = 0xff;
	PORTD = 0x00;
	PORTB = 0x00;
	RBPU = 0;
	
	TRISA=0xff;		
  	TRISE  = 0;
   	PORTE = 0;
	
	

	TRISC=0xc7; 
	PORTC=0x02; 
	
  	ADCON1=0x00;	
	INTCON=0xc0;
	Relay1 = 0;
	Relay2 = 0;

	Serial_init();	
	DelayMs(10);

 	while(1)
 	{		
		T=temp();		
		X=fire();
		y=intruder();
	        TMR2ON=0;
		
		if(T > 30) 
		{
			temp_disp();
			DelayMs(250);
			
		          temp	=	CCP1CON & 0x0c;
			CCP1CON	=	temp | 0x00;
			CCPR1L	=	0x7d;
			n 		= 	1;
		}
    		
		while(TXIF==0);

		TXREG = 0xB1;
		DelayMs(1000);
		TXREG = T;	
		DelayMs(1000);

	
		TXREG = 0xB2;
		DelayMs(1000);
		TXREG = X;
		DelayMs(1000);
	
	         TXREG = 0xB3;
		DelayMs(1000);
		TXREG = Y;
		DelayMs(1000);
		

		if(fire==1)
		{
			TXREG = 0xAB;
			DelayMs(1000);
			TXREG = 0xB6;
			DelayMs(1000);

		        fire_disp();
		}

		if(intruder==1)
		{
			TXREG = 0xB4;
			DelayMs(1000);
			TXREG = 0xCC;
			DelayMs(1000);
			
		}
		
		
		if(pirsensor == 0)
		{
			TXREG = 0xB8;
			DelayMs(1000);
			TXREG = 0xCC;
			DelayMs(1000);
			
		}
	
	
 	}
}












	// while(1)
	   
		if(pirsensor == 1)   	//no man  
			{
				for(i=0;i<300;i++)
				{
					DelayMs(250);
					if(sensor == 0)
					{
						break;
					}
				}
				if(i == 300)
				{
					i=0;
					Transmit('S');
					for(j=0;j<400;j++)
					{
						DelayMs(250);
					}
					Relay1 = 0;
					Relay2 = 0;
					OFF = 1;
					set = 1;
				}
			}

		if(pirsensor == 0 && OFF == 1)	//man
		{
			Relay1 = 1;
                        DelayMs(250);


 			Relay2 = 0; 

                        PIR_disp();
			
		}
	   		
	 };





        if(intruder == 1)
		{ 
			Relay1 = 0;
                        DelayMs(250);
			Relay2 = 1; 
                        DelayMs(250);

                        intruder_disp();

				
			
		}
		
		






void Serial_init()
{
   	TRISC=0xc0;					//RC7,RC6 set to usart mode(INPUT)
	TXSTA=0x24;					//Transmit Enable
	SPBRG=64;					//9600 baud at 10Mhz
	RCSTA=0x90;					//Usart Enable, Continus receive enable
	TXREG='0';
}

//Analog To digital Initialization





unsigned char temp()
{
	ADCON0=0x41;
	DelayMs(1);
	ADGO=1;
   	while(ADGO==1);
	return ADRESH;
}

unsigned char fire()
{
	ADCON0=0x49;
	DelayMs(1);
	ADGO=1;
   	while(ADGO==1);
	return ADRESH;
}



unsigned char intruder()
{
	ADCON0=0x51;
	DelayMs(1);
	ADGO=1;
   	while(ADGO==1);
	return ADRESH;
}

void DelayMs(unsigned int del)
{
	unsigned int x=248,y;
	while(del>0)
	{
		y=x;
		while(y>0)
		y--;
		del--;
	}
}





void temp_disp()
{
     
		lcdcomd(ROW0);
		for(j=0;j<15;j++)
		{
			lcd_disp(msg5[j]);
			DelayMs(2000);
		}
		lcdcomd(ROW1);
		for(j=0;j<15;j++)
		{
			lcd_disp(msg51[j]);
		    DelayMs(2000);
		}
}


void fire_disp()
{
      //lcdcomd(0X01);
		lcdcomd(ROW0);
		for(j=0;j<15;j++)
		{
			lcd_disp(msg6[j]);
			DelayMs(2000);
		}
		lcdcomd(ROW1);
		for(j=0;j<15;j++)
		{
			lcd_disp(msg61[j]);
		    DelayMs(2000);
		}voice = 0;
}

void PIR_disp()
{
	
		lcdcomd(ROW0);
		for(j=0;j<15;j++)
		{
			lcd_disp(msg1[j]);
			DelayMs(2000);
		}
		lcdcomd(ROW1);
		for(j=0;j<15;j++)
		{
			lcd_disp(msg11[j]);
		    DelayMs(2000);
		}
}

void intruder_disp()
{
		lcdcomd(ROW0);
		for(j=0;j<15;j++)
		{
			lcd_disp(msg4[j]);
			DelayMs(2000);
		}
		lcdcomd(ROW1);
		for(j=0;j<15;j++)
		{
			lcd_disp(msg41[j]);
		    DelayMs(2000);
		}
}
 
Last edited by a moderator:

Hi, while seeing your code, i found some mistakes you did.

In main() function, you have set TRISC and PORTC bits for some reason and you changed them in Serial_Init() function. If you want to set or clear a particular bit in a register, you can use the below method.

Code:
//This code explains how to clear particular bit in a 16-bit register.
int Temp = 0xA5A5;            //Initial value of Temp.
Serial_print(Temp);            //Print this initial value for clarification.
Temp &= ~(0x0505);          //Now, clear bits 0, 2, 8 and 10.
Serial_print(Temp);            //Now, print the Temp variable.

Code:
//This code explains how to set particular bit in a 16-bit register.
int Temp = 0x0000;            //Initial value of Temp.
Serial_print(Temp);            //Print this initial value for clarification.
Temp |= 0x0505;          //Now, set bits 0, 2, 8 and 10.
Serial_print(Temp);            //Now, print the Temp variable.

Also, please tell me why you use the below function?
Code:
if(fire==1)    //you have already created a function "fire()".. did you forget to put "()" in this if condition??
{
TXREG = 0xAB;
DelayMs(1000);
TXREG = 0xB6;
DelayMs(1000);

fire_disp();
}

Please post the compilation error log here.
 
Last edited:
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top