wazzaw
Newbie level 4
hi i am new to microcontrollers.
i have a project to do which is a light saving sensor that is during the day all light should be off, and during night only when there is people in the room,it will light.
to detect someone entering and someone leaving i have used 2 motion sensors( 2 photocells with laser beam) but the problem is in the mikroC program
the 2 sensors are connected to PORTC.F4 and PORTC.F5 output PORTB, i am using pic16F877A the program i wrote is:
int COUNTER=0;
void main() {
ADCON1=0 ;
TRISB=0b00000000;
TRISC=0b11111111;
PORTB=0;
while (1){
if(PORTC.F4==0 && PORTC.F5==0)
PORTB=0;
if (PORTC.F4==1){
delay_ms(10000);
if (PORTC.F5==1){
COUNTER=COUNTER+1;}
}
else if (PORTC.F5==1){
delay_ms(10000);
if (PORTC.F4==1){
COUNTER=COUNTER-1;}
}
if (COUNTER>=1)
PORTB=1;
}
}
thanks for help in advance.
i have a project to do which is a light saving sensor that is during the day all light should be off, and during night only when there is people in the room,it will light.
to detect someone entering and someone leaving i have used 2 motion sensors( 2 photocells with laser beam) but the problem is in the mikroC program
the 2 sensors are connected to PORTC.F4 and PORTC.F5 output PORTB, i am using pic16F877A the program i wrote is:
int COUNTER=0;
void main() {
ADCON1=0 ;
TRISB=0b00000000;
TRISC=0b11111111;
PORTB=0;
while (1){
if(PORTC.F4==0 && PORTC.F5==0)
PORTB=0;
if (PORTC.F4==1){
delay_ms(10000);
if (PORTC.F5==1){
COUNTER=COUNTER+1;}
}
else if (PORTC.F5==1){
delay_ms(10000);
if (PORTC.F4==1){
COUNTER=COUNTER-1;}
}
if (COUNTER>=1)
PORTB=1;
}
}
thanks for help in advance.