nakiiib
Newbie level 2
Hi. I am using this code below to use in my PIC trainer kit where PIC16F877A is used but output buzzer always turns on even if I dont give a signal or even connect the PIR sensor to that port. Can someone tell me what's wrong with this code?
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 sbit pir_in at RB7_bit; //PIR module's output pin sbit led_ind at RD0_bit; //An LED used as indicator sbit buz_out at RC1_bit; //Buzzer output sbit pir_in_Direction at TRISB7_bit; sbit led_ind_Direction at TRISD0_bit; sbit buz_out_Direction at TRISC1_bit; void init_delay(); //initial delay routine's forword declaration int i; //declare for using with for loops both in main and //in the delay routine void main() { pir_in_Direction=1; //as input led_ind_Direction=0; //as output buz_out_Direction=0; //as output led_ind=0; //initially off buz_out=0; //initially off pir_in=0; init_delay(); //1 min delay to activate the PIR module while(1) { if(pir_in==1){ buz_out=1; for( i=0;i<15;i++) //Buzzer sounds for 15 seconds { led_ind=0; Delay_ms(500); led_ind=1; Delay_ms(500); } } else { buz_out=0; led_ind=0; } } } void init_delay() { for(i=0;i<30;i++) { led_ind=1; Delay_ms(500); led_ind=0; Delay_ms(500); } led_ind=0; }
Last edited: