beckhamho
Junior Member level 1
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
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);
}