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.

checking sequence using If statement

Status
Not open for further replies.

beckhamho

Junior Member level 1
Joined
Apr 15, 2010
Messages
16
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,411
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 XOR 1 = 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); 
}
 

Hi andre_teprom,

ok,basically my stuff works like this:
IR1,IR2,IR3 and IR4 is always in high stage(1).
I wan to write a program when:
IR1 and IR3 goes low(0) , IR2 and IR4 stay high(1)
then check by while loop,if TRUE then goes to next if statement
IR1, IR2, IR3 and IR4 = 0
check by while loop again, if true then goes to next if statement
IR1 and IR3 goes high, IR2 and IR4 stay low.
if the sequence is correct, then only +1.
 

Instead of using all that
if (input(IR1)==0 && input(IR3) ==0 && input(IR2)==1 && input(IR4)==1)
you can use (I assume PINA is the read input reg, but may be different in pic )
if (PINA & 0b00011011)=0b00010010...

and then
instead of
if (input(IR1)==0 && input(IR3) ==0 && input(IR2)==0 && input(IR4)==0)
use
if (PINA & 0b00011011)=0b00000000...

Alex
 

Hi alexan_e,
Thanks for the reply.
how about the while loop?
while((input(IR1) && input(IR3)) ^ (input(IR2) && input(IR4)));
should be no problem?
 

i think ur do while logic is correct.
Now u just test LCD section is working properly.
For that just delete the below code in ur program just after the 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 XOR 1 = 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)


Then introduce a delay of about 1s instead of the above code. Then check LCD.

If its working then debug the LOGIC section . Otherwise debug the LCD section.

Actually u should confirm that input(IR1) represent 1st PIN of PORTA .
in hightech c compiler , it is RA0, RA1, RA2, RA3 etc which represent porta bits.
But i think this may be different for different compilers..

In ur compiler if "Pin_A0" represent first bit of PORT A , then u defined
#define IR1 Pin_A0
#define IR2 Pin_A1
#define IR3 Pin_A3
#define IR4 Pin_A4

Now in ur program instead of using IR1, IR2 etc u had used input(IR1),input(IR2) etc.
I am not sure, but just check it.
 
Last edited:

Hi alexan_e,
Thanks for the reply.
how about the while loop?
while((input(IR1) && input(IR3)) ^ (input(IR2) && input(IR4)));
should be no problem?

You can simplify that too

but what is the value you want, the following is true in two cases
while((input(IR1) && input(IR3)) ^ (input(IR2) && input(IR4))); // (0 AND 0) = 0 (1 AND 1) = 1 0 XOR 1 = 1= TRUE
while((input(IR1) && input(IR3)) ^ (input(IR2) && input(IR4))); // (1 AND 1) = 1 (0 AND 0) = 0 1 XOR 0 = 1= TRUE

Alex
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top