Manjuhb
Newbie level 6
Hi
I'am very new to the PIC programming. I have written a program to give 20 min of delay when an switch is pressed. I have connected an switch with active high signal to the INT pin of the PIC16F676 pin and I have connected an buzzer to RC1 port, connected a transistor to RC5 port to turn on the relay. Intention of this program is when switch is pressed relay should turn on till 20 min then it should go off by turning on the buzzer for 10SEC.
Here my problem is even though I did not press the switch the relay is turning on ie RC5 is going high. When I turn on the PCB after one min relay will turning on automatically ie External Interrupt is triggering I guess. Please help me with this problem.
Here is the code written by me.... Plz don't mind if code has to much unnecessary instruction.
I'am very new to the PIC programming. I have written a program to give 20 min of delay when an switch is pressed. I have connected an switch with active high signal to the INT pin of the PIC16F676 pin and I have connected an buzzer to RC1 port, connected a transistor to RC5 port to turn on the relay. Intention of this program is when switch is pressed relay should turn on till 20 min then it should go off by turning on the buzzer for 10SEC.
Here my problem is even though I did not press the switch the relay is turning on ie RC5 is going high. When I turn on the PCB after one min relay will turning on automatically ie External Interrupt is triggering I guess. Please help me with this problem.
Here is the code written by me.... Plz don't mind if code has to much unnecessary instruction.
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 #include <16F676.h> #use delay (clock=4000000) #fuses INTRC,NOWDT,PUT,NOMCLR,PROTECT,CPD,BROWNOUT #BIT RA2 = 0x05.2 #BIT RC1 = 0x07.1 #BIT RC5 = 0x07.5 #BIT GIE = 0x0B.7 #BIT TMR1IF = 0x0C.0 #BIT INTEDG = 0x81.6 #BIT INTE = 0x0B.4 #BIT PEIE= 0x0B.6 #BIT INTF= 0x0B.1 #BIT TMR1IE=0x8C.0 #BIT TMR1ON=0x10.0 #BYTE T1CON =0x10 long i; // 16 bit void init(VOID); #INT_TIMER1 void timer1_isr() { i++; IF (i == 2400) { setup_timer_1 (T1_DISABLED); TMR1ON = 0; RC5 = 0; RC1 = 1; delay_ms (10000); RC1 = 0; TMR1IF = 0; INTF = 0; clear_interrupt (INT_EXT); enable_interrupts(INT_EXT); INTE = 1; } } #INT_EXT void EXT_isr() { i = 0; setup_timer_1 (T1_INTERNAL|T1_DIV_BY_8); T1CON = 0x30; TMR1ON = 1; INTF = 0; clear_interrupt (INT_EXT); INTE = 0; Disable_interrupts(INT_EXT); RC5 = 1; set_timer1 (0); } void main(VOID) { delay_ms (1000); //power up delay init (); clear_interrupt (INT_EXT); clear_interrupt(int_timer1); EXT_INT_EDGE(L_TO_H); INTEDG = 1; enable_interrupts(global); enable_interrupts(INT_EXT); enable_interrupts (INT_TIMER1); GIE = 1; PEIE = 1; TMR1IE = 1; INTE = 1; setup_timer_1 (T1_DISABLED); WHILE (1) { } } void init(VOID) { RC5 = 0; RC1 = 0; INTF = 0; TMR1IF = 0; set_tris_a (0x04); set_tris_c (0x00); }