View previous topic :: View next topic |
Author |
Message |
ViperARG
Joined: 07 Jan 2017 Posts: 16
|
PIC12F675 INT |
Posted: Fri Jan 13, 2017 2:52 pm |
|
|
Hi dear friends =) !
I made this code for pic12f675 interrupt and I got it working but I don't know why when I press the button it won't initialize the interrupt until I switch it off. If I hold the pushbutton it won't trigger the interrupt until I leave it. Here is my code.
main.h
Code: |
#include <12F675.h>
#device ADC=16
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES NOBROWNOUT //No brownout reset
#use delay(internal=4MHz)
#use STANDARD_IO( A )
|
main.c
Code: |
#include <main.h>
#use fast_io(a)
#INT_EXT
void EXT_isr(void)
{
if ( !input(PIN_A2) == 1 ) {
output_high(PIN_A0);
delay_ms(3000);
output_low(PIN_A0);
}
}
void main()
{
enable_interrupts(INT_EXT); // Habilita la interrupción en RB0
enable_interrupts(GLOBAL); // Habilitación general de interrupción
ext_int_edge(H_TO_L); // Config. int. por flanco descendente. (L_TO_H) para ascendente
input(PIN_A2);
set_tris_a(0x4);
while(TRUE)
{
output_high(PIN_A5);
delay_ms(200);
output_low(PIN_A5);
delay_ms(200);
output_high(PIN_A4);
delay_ms(200);
output_low(PIN_A4);
delay_ms(200);
}
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jan 13, 2017 3:10 pm |
|
|
Does your button circuit look like this ? Or something else ?
In this circuit, when you press the button it puts Ground on the PIC pin.
When you don't press it, it has 5v on the pin.
Code: |
+5v
|
<
> 4.7K
< ___ Switch
To | _|_|_
PIC -----------------o o------
pin |
A2 --- GND
-
|
|
|
|
ViperARG
Joined: 07 Jan 2017 Posts: 16
|
|
Posted: Fri Jan 13, 2017 3:43 pm |
|
|
PCM programmer wrote: | Does your button circuit look like this ? Or something else ?
In this circuit, when you press the button it puts Ground on the PIC pin.
When you don't press it, it has 5v on the pin.
Code: |
+5v
|
<
> 4.7K
< ___ Switch
To | _|_|_
PIC -----------------o o------
pin |
A2 --- GND
-
|
|
Mine was pull down with a 10k resistor, now I tried pull up and it works better, sometimes it miss, and I tried with cables and another switches and does the same thing, sometimes wont register the push... so weird. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jan 13, 2017 4:34 pm |
|
|
Since you have delays in the interrupt and in main(), you will be getting
the interrupts disabled warning. (Do you have compiler warnings
enabled ?). This means you won't get interrupts for the duration of each
delay statement in main(). Your program will seem somewhat unresponsive.
See this CCS faq article for a suggested fix:
http://www.ccsinfo.com/faq.php?page=delay_in_interrupt
It uses two #use delay() statements to generate separate delay routines
for the interrupt code and the code in main(). This removes the conflict. |
|
|
|