Hi all,
I am doing a sensor project. I'm used LDR to detect the sunlight and Ir sensor to detect the movement of the human body..
I have 2 conditions in order to ON the LED.
First: LDR must detect the room is dark
Second: Ir sensor detect the user
Result: Counter increase the number of user + ON the LED.
LDR detect the room is dark + Ir sensor detect the user --> Counter increase ( cnt++) -->= ON the light.
Otherwise,
LDR detect the room is light + Ir sensor detect the user --> Counter ++, but the light still OFF.
Then, to exit the room...
Led ON --> user pass by the sensor+press the exit button+count-- (if count == 0 --> OFF the light.
But, i have a problem... i'm using the coding below...
Hope someone can help me on this coding.
Tq.
/* =======================
INFRA_RED
KiT = Chip-877
CPU = PIC16F877
LANG = MikroC
XTAL = 20Mhz
STATUS = V2 = join InfraRED with 7-SEG counting
======================= */
#define DOOR1_IN PORTC.F1
#define DOOR2_OUT PORTC.F2
// ========================
/* 7 6 5 4 3 2 1 0
PORTA X X g f DP c b a
PORTE X X X X X X d e */
/* C_Cathode PA0 = a
PA4 = f PA1 = b
PA5 = g PA2 = c
PE0 = e PA3 = dp
PE1 = d NC */
const char
SLED_A[10]={0x17,0x06,0x23,0x27,0x36,0x35,0x35,0x07,0x37,0x37};
const char SLED_E[10]={0x03,0x00,0x03,0x02,0x00,0x02,0x03,0x00,0x03,0x02};
// ========================
void main(){
char cnt, ten, exit, value;
TRISC = 0x0F;
TRISB = 0; /* set PORTB = ALL outputs */
PORTB = 0; /* turn off ALL LEDs */
// =====================================
TRISA = 0; /* set PORTA as ALL outputs */
TRISE = 0; /* set PORTE as ALL outputs */
PORTA = 0b11000000;
PORTE = 0b11111100;
cnt = 0;
ten = 0;
exit = 1; // exit button is high --> no press
value = 1; // LDR detect the room is light
// =====================================
for( ;; ){
value = PORTE.F0;;
if (value == 0) // if LDR detect the room is dark
{
cnt++;
}
else
{
cnt--;
}
if ( cnt != 0 ) PORTB = PORTB | 0x08;
PORTA = SLED_A[cnt];
PORTE = SLED_E[cnt];
Delay_ms(250);
PORTA = 0b11000000;
PORTE = 0b11111100;
exit = PORTD.F1;; // exit button
if ( !DOOR1_IN ){ // if user x pass by the sensor
PORTB = 0x01; // light remain ON
if ( exit == 0 ) cnt--; // if user press exit button --> exit==0
else cnt++; // cnt still increase
}
else if ( DOOR1_IN ) PORTB = 0x00;
if ( cnt == 10 ){ cnt = 0;
ten = 1; }
if ( cnt == 0xFF ) cnt = 0;
}
}
I am doing a sensor project. I'm used LDR to detect the sunlight and Ir sensor to detect the movement of the human body..
I have 2 conditions in order to ON the LED.
First: LDR must detect the room is dark
Second: Ir sensor detect the user
Result: Counter increase the number of user + ON the LED.
LDR detect the room is dark + Ir sensor detect the user --> Counter increase ( cnt++) -->= ON the light.
Otherwise,
LDR detect the room is light + Ir sensor detect the user --> Counter ++, but the light still OFF.
Then, to exit the room...
Led ON --> user pass by the sensor+press the exit button+count-- (if count == 0 --> OFF the light.
But, i have a problem... i'm using the coding below...
Hope someone can help me on this coding.
Tq.
/* =======================
INFRA_RED
KiT = Chip-877
CPU = PIC16F877
LANG = MikroC
XTAL = 20Mhz
STATUS = V2 = join InfraRED with 7-SEG counting
======================= */
#define DOOR1_IN PORTC.F1
#define DOOR2_OUT PORTC.F2
// ========================
/* 7 6 5 4 3 2 1 0
PORTA X X g f DP c b a
PORTE X X X X X X d e */
/* C_Cathode PA0 = a
PA4 = f PA1 = b
PA5 = g PA2 = c
PE0 = e PA3 = dp
PE1 = d NC */
const char
SLED_A[10]={0x17,0x06,0x23,0x27,0x36,0x35,0x35,0x07,0x37,0x37};
const char SLED_E[10]={0x03,0x00,0x03,0x02,0x00,0x02,0x03,0x00,0x03,0x02};
// ========================
void main(){
char cnt, ten, exit, value;
TRISC = 0x0F;
TRISB = 0; /* set PORTB = ALL outputs */
PORTB = 0; /* turn off ALL LEDs */
// =====================================
TRISA = 0; /* set PORTA as ALL outputs */
TRISE = 0; /* set PORTE as ALL outputs */
PORTA = 0b11000000;
PORTE = 0b11111100;
cnt = 0;
ten = 0;
exit = 1; // exit button is high --> no press
value = 1; // LDR detect the room is light
// =====================================
for( ;; ){
value = PORTE.F0;;
if (value == 0) // if LDR detect the room is dark
{
cnt++;
}
else
{
cnt--;
}
if ( cnt != 0 ) PORTB = PORTB | 0x08;
PORTA = SLED_A[cnt];
PORTE = SLED_E[cnt];
Delay_ms(250);
PORTA = 0b11000000;
PORTE = 0b11111100;
exit = PORTD.F1;; // exit button
if ( !DOOR1_IN ){ // if user x pass by the sensor
PORTB = 0x01; // light remain ON
if ( exit == 0 ) cnt--; // if user press exit button --> exit==0
else cnt++; // cnt still increase
}
else if ( DOOR1_IN ) PORTB = 0x00;
if ( cnt == 10 ){ cnt = 0;
ten = 1; }
if ( cnt == 0xFF ) cnt = 0;
}
}