aadebola5
Newbie level 4
please can anyone assist me by going through this code, the LED is to come on when the switch is on and the pir sensor detects motion.. this is the code
//all these # below set up the PIC
//#include <16F877A.h>
//#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //Highspeed Osc > 4mhz
#FUSES PUT //Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#use delay(clock=20000000) // Sets crystal oscillator at 20 megahertz
#use rs232(baud=9600, xmit=PIN_C6, invert) //Sets up serial port output pin & baud rate
#define PIR_SENSOR PIN_A0
#define RED_LED PIN_B7
#define sw PIN_A1
void main()
{
set_tris_a(0xff);
set_tris_b(0x00);
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_INTERNAL);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
while(true)
{ set_adc_channel(0);
delay_us(20);
if(PIR_SENSOR==0 && sw==0){
output_high(PIN_B7);
}
else{
output_low(PIN_B7);
}
}
}
//all these # below set up the PIC
//#include <16F877A.h>
//#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //Highspeed Osc > 4mhz
#FUSES PUT //Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#use delay(clock=20000000) // Sets crystal oscillator at 20 megahertz
#use rs232(baud=9600, xmit=PIN_C6, invert) //Sets up serial port output pin & baud rate
#define PIR_SENSOR PIN_A0
#define RED_LED PIN_B7
#define sw PIN_A1
void main()
{
set_tris_a(0xff);
set_tris_b(0x00);
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_INTERNAL);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
while(true)
{ set_adc_channel(0);
delay_us(20);
if(PIR_SENSOR==0 && sw==0){
output_high(PIN_B7);
}
else{
output_low(PIN_B7);
}
}
}