CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Someone please help

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
teongkia



Joined: 12 Apr 2007
Posts: 7

View user's profile Send private message

Someone please help
PostPosted: Sun Apr 22, 2007 11:54 pm     Reply with quote

Hi can anyone look at my code and tell me what is wrong with it?The basic operation is when I switch on the power supply, and when I supply 5V input in PIN_A4, it will enable the interrupt and triggering any sensors will trigger the siren at PIN_B5 and dial the specific number. But when I switch on the power supply, the siren(PIN_B5) has 5V output immediately without triggering any sensor.And my remote control does not work too.Anyone can help?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, TEMP;
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("ATD0166827272;\n\r");
}
//Touch sensor triggered
void SEND_CALL2()
{
   PRINTF("ATD0166827272;\n\r");   
}
//Light sensor triggered
void SEND_CALL3()
{
   PRINTF("ATD0166827272;\n\r");
}
//Door sensor triggered
void SEND_cALL4()
{
   PRINTF("ATD0166827272;\n\r");
}
//Central lock triggered
void SEND_CALL5()
{
   PRINTF("ATD0166827272;\n\r");
}




#INT_RTCC
T0()
{
      SENSOR1=INPUT(ULTRA);
      SENSOR2=INPUT(TOUCH);
      SENSOR3=INPUT(LIGHT);
      SENSOR4=INPUT(DOOR);
   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();
      }
}


//Main function
void MAIN()
{
   
     SET_RTCC(0);
     SETUP_COUNTERS(RTCC_INTERNAL,RTCC_DIV_64);
   EXT_INT_EDGE(0,H_TO_L);     
     ENABLE_INTERRUPTS(INT_RDA);
    ENABLE_INTERRUPTS(GLOBAL);
     SET_TRIS_A(0b00011111);
     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;
   
   A=0;
   B=0;
   C=0;
   D=0;
   EN=0;
     RC=0;
     UNLOCK();
     //Checking system activation
     while(1)
     {
       RC=(INPUT(REMOTE)^0);
      RC1[0]=RC;
      //Checking for rising and falling edge
      if((RC1[0]==1 && RC1[1]==0)||(RC1[0]==0 && RC1[1]==1))
      {
         EN=(EN^1);
         if(EN==1)
         {
             LOCK();
            ENABLE_INTERRUPTS(INT_RTCC);
         }
         else
         {
            UNLOCK();
            DISABLE_INTERRUPTS(INT_RTCC);
         }     
      }
      RC1[1]=RC;
   }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 23, 2007 12:23 am     Reply with quote

I didn't really look at your program design. I looked for simple problems,
and there are several of them.

The lines shown below are incorrect. You want to initialize these
variables, but you're using the wrong operator. You should use the
assignment operator, which is a single equal sign: '='
Quote:

SENSOR1==0;
SENSOR2==0;
SENSOR3==0;
SENSOR4==0;



Below, you're setting the TRIS, but you're not using "fast i/o" mode,
which is specified with a #use statement. My advice is to use
"standard i/o" mode (it's the default mode). Delete these TRIS
statements and let the compiler handle the TRIS. If you use CCS i/o
functions such as output_low(), output_high(), input(), etc., the compiler
will set the correct TRIS automatically for you.
Quote:

SET_TRIS_A(0b00011111);
SET_TRIS_B(0x01);
//SET_TRIS_C(0x0F);

In addition to that, you should use output_low() or output_high()
statements to initialize all your output pins to their preferred initial state.
For example, if you want the SIREN pin to be initially low (i.e., OFF), then
put this line of code near the start of main():
Code:
output_low(SIREN);

Do the rest of your output pins the same way. You don't have to
do anything to your input pins, because all PIC i/o pins come up
configured as inputs upon power-on reset.




Here, you're enabling RDA interrupts, but you don't have an #int_rda
interrupt service routine anywhere in your posted code. This is wrong.
Quote:

ENABLE_INTERRUPTS(INT_RDA);
ENABLE_INTERRUPTS(GLOBAL);



Here, you have an interrupt service routine for the RTCC timer, but
you don't have a line of code in main() to enable the INT_RTCC
interrupt. Perhaps you meant to type in INT_RTCC in the code above
but you typed in INT_RDA by mistake.
Quote:

#INT_RTCC
T0()
{
SENSOR1=INPUT(ULTRA);
SENSOR2=INPUT(TOUCH);
SENSOR3=INPUT(LIGHT);
SENSOR4=INPUT(DOOR);
etc.
teongkia



Joined: 12 Apr 2007
Posts: 7

View user's profile Send private message

PostPosted: Tue Apr 24, 2007 7:40 am     Reply with quote

Thanks. I tried edit the code and tested it. But there are still some problems. The first problem is without triggering the remote pin, triggering the input sensor will trigger the output siren pin. What I want is only after I trigger the remote pin, it will enable the RTCC interrupt and then triggering any of the input sensor pin will have 5V output in siren pin.
The second problem is triggering the input sensors pin would make a call through the mobile phone while sometimes not. Can you solve my problems? Thanks.

Code:

//Preprocessor
#INCLUDE <16F877A.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 REMOTE    PIN_A3
#DEFINE DOOR      PIN_A4

//Global declaration
int A,B,C,D,RC,EN;
int RC1[2];
char SENSOR1, SENSOR2, SENSOR3, SENSOR4;
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("ATD0166827272;\n\r");
}
//Touch sensor triggered
void SEND_CALL2()
{
   PRINTF("ATD0166827272;\n\r");   
}
//Light sensor triggered
void SEND_CALL3()
{
   PRINTF("ATD0166827272;\n\r");
}
//Door sensor triggered
void SEND_cALL4()
{
   PRINTF("ATD0166827272;\n\r");
}
//Central lock triggered
void SEND_CALL5()
{
   PRINTF("ATD0166827272;\n\r");
}




#INT_RTCC
T0()
{
      SENSOR1=INPUT(ULTRA);
      SENSOR2=INPUT(TOUCH);
      SENSOR3=INPUT(LIGHT);
      SENSOR4=INPUT(DOOR);
   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();
      }
}


//Main function
void MAIN()
{
   
     SET_RTCC(0);
     SETUP_COUNTERS(RTCC_INTERNAL,RTCC_DIV_64);
   EXT_INT_EDGE(0,H_TO_L);     
     ENABLE_INTERRUPTS(INT_RTCC);
    ENABLE_INTERRUPTS(GLOBAL);


     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;
   OUTPUT_LOW(SIREN);
   
   A=0;
   B=0;
   C=0;
   D=0;
   EN=0;
     RC=0;
     UNLOCK();
     //Checking system activation
     while(1)
     {
       RC=(INPUT(REMOTE)^0);
      RC1[0]=RC;
      //Checking for rising and falling edge
      if((RC1[0]==1 && RC1[1]==0)||(RC1[0]==0 && RC1[1]==1))
      {
         EN=(EN^1);
         if(EN==1)
         {
             LOCK();
            ENABLE_INTERRUPTS(INT_RTCC);
         }
         else
         {
            UNLOCK();
            DISABLE_INTERRUPTS(INT_RTCC);
         }     
      }
      RC1[1]=RC;
   }
}

ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Apr 24, 2007 8:54 am     Reply with quote

Quote:
What I want is only after I trigger the remote pin, it will enable the RTCC interrupt and then triggering any of the input sensor pin will have 5V output in siren pin.
If you don't want the RTCC interrupt to be enabled at start up... than don't call enable_interrupts(INT_RTCC) at the start of main but use disable instead.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group