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 CCS Technical Support

Clarification on my code

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



Joined: 12 Apr 2010
Posts: 27

View user's profile Send private message

Clarification on my code
PostPosted: Fri Aug 27, 2010 11:22 am     Reply with quote

Can someone check whether this code is true or not...the situation is for 2 sensor. The sensor alert from 1 to 2 will result = increment 1 while if the sensor 2 followed by 1 will result = decrement 1. The objective is to make the entire system operate as the counter increase, except if the counter equal to zero...the output will be low. Sorry for my weakness... I had try to solve it...but still don't what the problem.

Can someone help me?
Code:

#include <16F877A.H>
#device ADC=10
#FUSES HS,NOWDT,NOPROTECT,NOLVP //high speed osci >4Mhz, No watch dog timer,
#USE DELAY(CLOCK=20000000) //must use if not cannot use delay_ms, instruct the microcontroller's speed
//#include <stdio.h>

#include "E:\note ngaji\FYP\stuff last sem\code\Batu\brum\Flexlcd2.c"

#define      LED1     PIN_D7
#define      LED2     PIN_D6
#define      exit     PIN_C7
#define      exit2    PIN_C6
#define      zero     PIN_C5
void main(void)
{

int  inout_counter=0,PIR1,PIR2,in,out;
int16 counter1;
//unsigned char ole;
//int v;

lcd_init();
lcd_putc("\fcounter people:\n");

while(1)
{        PIR1=0;
          PIR2=0;
          in=0;
          out=0;
          lcd_gotoxy(1,2);
          printf(lcd_putc,"%d",inout_counter);



{
         PIR1 = input(PIN_D5);
          PIR2 = input(PIN_D4);


               if(PIR1==1)
          {
            output_high(exit);  // indication sensor 1 alert
            for(counter1=10000;counter1>0;counter1--)
            {
               PIR2 = input(PIN_D4);
               delay_ms(1);
               if(PIR2==1)
               in=1;


            }
            if(in==1)
            inout_counter++;

          }

          else if(PIR2==1)
          {
            output_high(exit2);  //indication sensor 2 alert
            for(counter1=10000;counter1>0;counter1--)
            {
               PIR1 = input(PIN_D5);
               delay_ms(1);
               if(PIR1==1)
               out=1;


            }
            if(out==1)
            inout_counter--;
          }

               if(inout_counter>0)
          {
           output_high(LED1);   //desired output
           output_low(LED2);
         }


          else
          {
          output_high(LED2);
         output_low(LED1);
            output_low(exit);
         output_low(exit2);
         output_high(zero);  // to indicate all system off..
}


}
}
}
ckielstra



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

View user's profile Send private message

PostPosted: Fri Aug 27, 2010 12:16 pm     Reply with quote

First a few general remarks. You are getting low response because your code is difficult to read:
- Set your editor to use spaces instead TAB characters. The TAB character is a different size on many systems and now the layout of your code is jumping around.
- Be consequent in the usage of small and capital letters. Common practice is to write only constants in all capital words. Variables are then in all small letters or a combinations of capitals and small letters.

so good:
Code:
#define      LED1     PIN_D7
int  inout_counter=0,in,out;
bad:
Code:
#define      exit     PIN_C7
int  PIR1,PIR2;


Then a real problem:
Code:
            for(counter1=10000;counter1>0;counter1--)
            {
                pir2 = input(SENSOR2);
                delay_ms(1);
                if (pir2==1)
                    in=1;
            }
10,000 times 1ms = 10 seconds.
Your detection is busy for 10 seconds before it can start detecting a new person.... You didn't mention the distance between the two sensors, but this seems like a long time.

If you still have problems, then describe what you are seeing. What actions do you make and what is the response to the LEDs and display?
delifadzli



Joined: 12 Apr 2010
Posts: 27

View user's profile Send private message

PostPosted: Fri Aug 27, 2010 7:43 pm     Reply with quote

Both sensors will be placed at the door, one at the entry of the door and the other one just behind it.

The action that I planned:

The sensor 1 will be off first before checking for sensor 2.
The same goes for decrement action.

The problem is, if the sensor 1 detected, the output will go low.

What I want is, the system only respond to the counter value. If counter = 0, the LED1 off, else it will on (Counter>0 , LED1 ON).

Then, for this one:
Code:

#define exit  PIN_C7

int PIR1, PIR2;

I don't understand. Sorry for my weakness.
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