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.

Check my C code for PIC16F877 which is used in car security system

Status
Not open for further replies.

teongkia

Newbie level 2
Joined
Apr 10, 2007
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,293
Hi I have this code. I tried it out in microcontroller but didn't work. I am currently having a car security project. What I want is when any of the sensor is triggered (high voltage in input pin), it will have high voltage in output siren pin and call the predefined owner's number. Can anyone check for it and let me know what is the problem?Thanks.
Code:
//Preprocessor
#INCLUDE <16F877.H>
#FUSES HS,NOWDT,NOLVP
#USE DELAY(clock=12000000)
#USE RS232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

//Define pin
#DEFINE SIREN     PIN_B5
#DEFINE CL1   PIN_B4
#DEFINE CL2       PIN_B3
#DEFINE ULTRA   PIN_A0
#DEFINE TOUCH     PIN_A1
#DEFINE LIGHT     PIN_A2
#DEFINE DOOR      PIN_A3
#DEFINE REMOTE  PIN_A4

//Global declaration
int A,B,C,D,RC,EN;
int RC1[2];
char SENSOR1, SENSOR2, SENSOR3, SENSOR4, SENSOR5, TEMP;
char P[4];
char S[51];

//Sound siren
void SIREN_ON()
{
   OUTPUT_HIGH(SIREN);
   DISABLE_INTERRUPTS(INT_RTCC);
}
//Unlock doors
void UNLOCK()
{
   OUTPUT_HIGH(CL1);
   OUTPUT_LOW(CL2);
}
//Lock doors
void LOCK()
{
   OUTPUT_LOW(CL1);
   OUTPUT_HIGH(CL2);
}

//Ultrasonic sensor triggered
void SEND_CALL1()
{
   PRINTF("ATD0123456789;\n\r");
}
//Touch sensor triggered
void SEND_CALL2()
{
   PRINTF("ATD0123456789;\n\r");   
}
//Light sensor triggered
void SEND_CALL3()
{
   PRINTF("ATD0123456789;\n\r");
}
//Door sensor triggered
void SEND_cALL4()
{
   PRINTF("ATD0123456789;\n\r");
}
//Central lock triggered
void SEND_CALL5()
{
   PRINTF("ATD0123456789;\n\r");
}




#INT_RTCC
T0()
{
      SENSOR1=INPUT(ULTRA);
      SENSOR2=INPUT(TOUCH);
      SENSOR3=INPUT(LIGHT);
      SENSOR4=INPUT(DOOR);
      SENSOR5=INPUT(CL1);
   if(SENSOR1)
      {
         SEND_CALL1();
         SIREN_ON();
      }
      else if(SENSOR2)
      {
         SEND_CALL2();
         SIREN_ON();
      }
      else if(SENSOR3)
      {
         SEND_CALL3();
         SIREN_ON();
      }
      else if(SENSOR4)
      {
         SEND_CALL4();
         SIREN_ON();
      }
   else if(SENSOR5)
   {
      SEND_CALL5();
      SIREN_ON();
   }
}

#INT_RDA
SERIAL()
{
   //Optional   
   if(kbhit())
   {
      TEMP=GETC();
      if(A<50)
      {
         S[A]=TEMP;
         A++;
      }
      else
      {
         A=0;
         S[A]=TEMP;
         A++;
      }
   }
   DELAY_MS(100);
   return A,S;
}

//Main function
void MAIN()
{
   
     SET_RTCC(0);
     SETUP_COUNTERS(RTCC_INTERNAL,RTCC_DIV_64);
   EXT_INT_EDGE(0,H_TO_L);     
   ENABLE_INTERRUPTS(INT_EXT);
     ENABLE_INTERRUPTS(INT_RDA);
    ENABLE_INTERRUPTS(GLOBAL);
    ENABLE_INTERRUPTS(INT_RTCC);
     SET_TRIS_A(0x3F);
     SET_TRIS_B(0x01);
   //SET_TRIS_C(0x0F);
   SET_TRIS_D(0x00);

     DELAY_MS(5000);

   PRINTF("\n\rATZ\n\r");
   DELAY_MS(500);
     PRINTF("\n\rAT\n\r");
   DELAY_MS(500);
   PRINTF("\n\rAT+CNMI=2,3,0,0,0\n\r");
   DELAY_MS(500);
   
   SENSOR1==0;
     SENSOR2==0;
     SENSOR3==0;
     SENSOR4==0;
     SENSOR5==0;
   A=0;
   B=0;
   C=0;
   D=0;
   EN=0;
     RC=0;
     UNLOCK();

}
 

pic16f877 light sensor

Pls indicate the compiler you are using and if possible pls attach the diagram so that I can try it in proteus.
 

kbhit c++ pic16f877

I'm using CCS C Compiler. The input devices are sensors while output devices are MAX232 which connected to my Sony Ericsson T630 and also siren. Hope you can help me out. Thanks.[/img]
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top