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

checking Sequence

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



Joined: 11 Mar 2011
Posts: 7

View user's profile Send private message

checking Sequence
PostPosted: Sat Apr 02, 2011 1:06 pm     Reply with quote

Hi

I am trying to check the sequence using if statement.
first : IR1 and IR3 goes low and IR2 and IR4 stay high
check by while loop, if it is true then go to next if statement.
second : IR1 ,IR2,IR3 and IR4 all goes low.
check by while loop, if it is true then go to next if statement.
lastly :IR1 and IR3 goes high and IR2 and IR4 stay low.

if fulfill above requirement, LCD will increment by one.
I had wrote the program but the program doesn't work.
can someone figure out the problem for me.
below is my code
Code:

#include <16f877a.h>
#use delay(clock=20000000)
#fuses hs,noprotect,nowdt,nolvp
#define use_portb_lcd TRUE
#include <lcd.c>

#define IR1 Pin_A0
#define IR2 Pin_A1
#define IR3 Pin_A3
#define IR4 Pin_A4


void main()

   int people_in = 0, people_out = 0;
   
   set_tris_a(0b00001111);
   lcd_init();

   lcd_putc("\fAutomatic Room");
   lcd_putc("\nLight Controller");
   delay_ms(5000);
   lcd_putc("\f");


display_1st :
   
   lcd_gotoxy(1,1);
   lcd_putc("People in  =  \n");
   lcd_putc("People out =  \n");
   
   lcd_gotoxy(14,1);
   printf(lcd_putc,"%3u",people_in);
       
 do{
   
if (input(IR1)==0 && input(IR3) ==0 && input(IR2)==1 && input(IR4)==1) 
{
while((input(IR1) && input(IR3)) ^ (input(IR2) && input(IR4)));    // (0 AND 0) = 0  (1 AND 1) = 1  0 XOR1 = 1= TRUE
if (input(IR1)==0 && input(IR3) ==0 && input(IR2)==0 && input(IR4)==0)
{
while((!input(IR1) && !input(IR3)) && (!input(IR2) && !input(IR4)));    // 1 AND 1 AND 1 AND 1 = 1 = TRUE
if (input(IR1)==1 && input(IR3) ==1 && input(IR2)==0 && input(IR4)==0)
            {
               people_in += 1;
               lcd_gotoxy(14,1);
               printf(lcd_putc,"%3u",people_in);
            }
             while((input(IR1) && input(IR3)) ^ (input(IR2) && input(IR4)));
         }
}
   }while(1);
}
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Apr 02, 2011 2:26 pm     Reply with quote

First error I see is that you've set A4 to be an output....

Another reason to NOT use the set_tris_x().. commands but let the compiler do it for you automatically....

It maybe easier for you to just read the port and compare to the required conditions...I know it is for me ! and less chance of getting the syntax wrong. !
ycho87



Joined: 11 Mar 2011
Posts: 7

View user's profile Send private message

PostPosted: Sat Apr 02, 2011 2:51 pm     Reply with quote

Hi temtronic

Quote:
It maybe easier for you to just read the port and compare to the required conditions...I know it is for me ! and less chance of getting the syntax wrong. !


can you tell me how to do that?
thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Apr 03, 2011 3:22 pm     Reply with quote

Quote:
can you tell me how to do that?

This program shows how to read miscellaneous port pins, and pack them
into a byte. (Or in your case, into the lower 4 bits of a byte).
Then you can just do a test (with an 'if' statement) of the byte's value.
See the following post:
http://www.ccsinfo.com/forum/viewtopic.php?t=18949&start=8
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