Вы находитесь на странице: 1из 8

No external interrupt with PIC12F675??

PostPosted: Fri Jan 24, 2003 12:52 am Reply with quote


I have tried multiple methods to get an external interrupt to work with CPM
programming PIC12F675s. The interrupt flag never gets set. Example code (trying to
trigger by pulling GP2 low):

////////////////////////////////////////////////////////
//trying to make the INT external interrupt on GP2 work
//to switch state of a couple of LEDs on GP4,5
////////////////////////////////////////////////////////
#include <12f675.h>
#fuses INTRC_IO,PUT,NOWDT,NOPROTECT,NOMCLR, BROWNOUT
#use delay(clock=4000000)
//define IO pins
#bit gpio5 =0x05.5
#bit gpio4 =0x05.4
#bit gpio3 =0x05.3
#bit gpio2 =0x05.2
#bit gpio1 =0x05.1
#bit gpio0 =0x05.0
#use fast_io(a)

#byte OSCCAL = 0x90


#rom 0x3ff = {0x3470} /// input the calibration code
#int_ext
void external_handler(void)
{
gpio5=!gpio5; //instantly flip LEDs on external interrupt
gpio4=!gpio4;
delay_ms(100);
}

#int_default
void default_isr(void)
{}

main()
{
//setup i/o
set_tris_a(0b001100); //GP0,1,4,5 output; 2,3 input
gpio5=1; gpio4=0; gpio1=0; gpio0=0; //turn on LED on gp5

//set timer0 not to use GP2


setup_counters(rtcc_internal, rtcc_div_2);

//setup interrupts
enable_interrupts(int_ext);
ext_int_edge(h_to_l); //GP2 is pulled high with resistor
enable_interrupts(global);

//loop and wait for interrupt


while(true)
{
delay_ms(2500);
gpio5=!gpio5; //toggle LEDs just to show program is running
gpio4=!gpio4;
}
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 10958

Tomi
Guest

Re: No external interrupt with PIC12F675??


PostPosted: Fri Jan 24, 2003 1:53 am Reply with quote
<font face="Courier New" size=-1>Remove your delay_ call from the ISR. ITs are
disabled under execution of delay_ms() call in main() (so practically always is
disabled).

:=I have tried multiple methods to get an external interrupt to work with CPM
programming PIC12F675s. The interrupt flag never gets set. Example code (trying to
trigger by pulling GP2 low):
:=
:=////////////////////////////////////////////////////////
:=//trying to make the INT external interrupt on GP2 work
:=//to switch state of a couple of LEDs on GP4,5
:=////////////////////////////////////////////////////////
:=#include <12f675.h>
:=#fuses INTRC_IO,PUT,NOWDT,NOPROTECT,NOMCLR, BROWNOUT
:=#use delay(clock=4000000)
:=//define IO pins
:=#bit gpio5 =0x05.5
:=#bit gpio4 =0x05.4
:=#bit gpio3 =0x05.3
:=#bit gpio2 =0x05.2
:=#bit gpio1 =0x05.1
:=#bit gpio0 =0x05.0
:=#use fast_io(a)
:=
:=#byte OSCCAL = 0x90
:=#rom 0x3ff = {0x3470} /// input the calibration code
:=#int_ext
:=void external_handler(void)
:={
:=gpio5=!gpio5; //instantly flip LEDs on external interrupt
:=gpio4=!gpio4;
:=delay_ms(100);
:=}
:=
:=#int_default
:=void default_isr(void)
:={}
:=
:=main()
:={
:=//setup i/o
:=set_tris_a(0b001100); //GP0,1,4,5 output; 2,3 input
:=gpio5=1; gpio4=0; gpio1=0; gpio0=0; //turn on LED on gp5
:=
:=//set timer0 not to use GP2
:=setup_counters(rtcc_internal, rtcc_div_2);
:=
:=//setup interrupts
:=enable_interrupts(int_ext);
:=ext_int_edge(h_to_l); //GP2 is pulled high with resistor
:=enable_interrupts(global);
:=
:=//loop and wait for interrupt
:=while(true)
:={
:=delay_ms(2500);
:=gpio5=!gpio5; //toggle LEDs just to show program is running
:=gpio4=!gpio4;
:=}
:=}
:=</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 10959

Ned Israelsen
Guest

Re: No external interrupt with PIC12F675??


PostPosted: Fri Jan 24, 2003 10:22 am Reply with quote
I have removed the delay_ms call and bit flip from main() and the delay call from
the isr. So, most of the time the program should be sitting in the while(true) loop
doing nothing. Also tried different 12F675s. Still no interrupt. (Code works fine
with properly-set-up RB port change interrupt on GP3.)

:=<font face="Courier New" size=-1>Remove your delay_ call from the ISR. ITs are
disabled under execution of delay_ms() call in main() (so practically always is
disabled).
:=
:=:=I have tried multiple methods to get an external interrupt to work with CPM
programming PIC12F675s. The interrupt flag never gets set. Example code (trying to
trigger by pulling GP2 low):
:=:=
:=:=////////////////////////////////////////////////////////
:=:=//trying to make the INT external interrupt on GP2 work
:=:=//to switch state of a couple of LEDs on GP4,5
:=:=////////////////////////////////////////////////////////
#include <12f675.h>
#fuses INTRC_IO,PUT,NOWDT,NOPROTECT,NOMCLR, BROWNOUT
#use delay(clock=4000000)
//define IO pins
#bit gpio5 =0x05.5
#bit gpio4 =0x05.4
#bit gpio3 =0x05.3
#bit gpio2 =0x05.2
#bit gpio1 =0x05.1
#bit gpio0 =0x05.0
#use fast_io(a)

#byte OSCCAL = 0x90


#rom 0x3ff = {0x3470} /// input the calibration code
#int_ext
void external_handler(void)
{
gpio5=!gpio5; //instantly flip LEDs on external interrupt
gpio4=!gpio4;
delay_ms(100);
}

#int_default
void default_isr(void)
{}

main()
{
//setup i/o
set_tris_a(0b001100); //GP0,1,4,5 output; 2,3 input
gpio5=1; gpio4=0; gpio1=0; gpio0=0; //turn on LED on gp5

//set timer0 not to use GP2


setup_counters(rtcc_internal, rtcc_div_2);

//setup interrupts
enable_interrupts(int_ext);
ext_int_edge(h_to_l); //GP2 is pulled high with resistor
enable_interrupts(global);

//loop and wait for interrupt


while(true)
{
delay_ms(2500);
gpio5=!gpio5; //toggle LEDs just to show program is running
gpio4=!gpio4;
}
}

:=:=</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 10969

PCM programmer

Joined: 06 Sep 2003


Posts: 20759

View user's profile Send private message

Re: No external interrupt with PIC12F675??


PostPosted: Fri Jan 24, 2003 1:00 pm Reply with quote
:=I have tried multiple methods to get an external interrupt to work with CPM
programming PIC12F675s. The interrupt flag never gets set.
------------------------------------------------------
I think the start-up code inserted by the compiler
may not be correct. Try doing the following:

Insert these lines above main():

#byte ADCON0 = 0x1F


#byte ANSEL = 0x9F
#byte CMCON = 0x19

Insert these lines at the very beginning of main():

ADCON0 = 0; // ADC off


ANSEL = 0; // GPIO pins 0,1,2 and 4 set to all digital
CMCON = 7; // Comparators off

See if that helps.


___________________________
This message was ported from CCS's old forum
Original Post ID: 10971

Ned Israelsen
Guest

Re: No external interrupt with PIC12F675??


PostPosted: Fri Jan 24, 2003 8:31 pm Reply with quote
:=:=I have tried multiple methods to get an external interrupt to work with CPM
programming PIC12F675s. The interrupt flag never gets set.
:=------------------------------------------------------
:=I think the start-up code inserted by the compiler
:=may not be correct. Try doing the following:
:=
:=Insert these lines above main():
:=
:=#byte ADCON0 = 0x1F
:=#byte ANSEL = 0x9F
:=#byte CMCON = 0x19
:=
:=
:=Insert these lines at the very beginning of main():
:=
:=ADCON0 = 0; // ADC off
:=ANSEL = 0; // GPIO pins 0,1,2 and 4 set to all digital
:=CMCON = 7; // Comparators off
:=
:=See if that helps.

Yep. That fixed it! Thanks much!!


___________________________
This message was ported from CCS's old forum
Original Post ID: 10986
#include <main.h>
#USE FAST_IO(A)

#INT_EXT
void EXT_isr(void)
{
output_low(pin_a5);
delay_us(100);
output_high(pin_a5);
}

void main()
{

ext_int_edge(H_to_L);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
set_tris_a(0b00000110);

while(TRUE)
{
//TODO: User Code
}

Hola gente,
alguien me puede decir que diferencia existe entre estas dos interrupciones
(#int_ext/ #int_Rb), es lo mismo??
quiero medir frecuencia por un pin cualquiera (en un pic que no tenga CCP). He
logrado hacerlo, pero solo por el Pin Rb0/int, pero en el pic que quiero
usar(12f675), no tiene este pin, solo tiene "interrupt-on-change". Para utilizar
esta interrupcion la instruccion es:
#int_ext
void cap_frec(){
}
main{
ext_int_edge(2,H_TO_L); // flanco alto a bajo en rb2
enable_interrupts(INT_EXT); // habilita int-on-change en Rb2??
enable_interrupts(GLOBAL);
}
voy bien??
saludos
el pic12f675 tiene 7 fuentes de interrupciones: **ext interrup GP2/int, TMR0,**
GPIO change interrup, comparator interrup, A/D, TMR1 y EEPROM.
De estas quiero usar o la GP2/int, o GPIO change interrup.
Mi duda es
- si quiero usar la int GP2/INT debo configurar:
enable_interrupts(INT_RB);
enable_interrupts(global);
- si uso GPIO change:
ext_int_edge(1,L_TO_H);
enable_interrupts(INT_EXT);
enable_interrupts(global);
he probado amabas pero no funciona, puede ser que este mal calibrado, ya que estoy
usando el oscilador interno?? Alguien sabe como calibrar este pic??
gracias
saludos

seria algo asi:


#include <12F675.h>
#fuses INTRC,WDT
#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_A1,rcv=PIN_A0,bits=9)
#byte intcon=0x0b /*Regisro de interrupcion*/
#bit RBIE=intcon.3 /*Para limpiar flag de interrupcion!!!*/

#int_EXT
EXT_isr() {
putc ('x');
RBIE=0;
}
void main() {
float frecuencia;
restart_wdt();

set_tris_a(0b000101);
setup_timer_1(T1_INTERNAL);
enable_interrupts(INT_EXT);
//ext_int_edge(2,L_TO_H);
//enable_interrupts(INT_RB); //esta interrup seria en un pin cualquiera?
enable_interrupts(global);
RBIE=0;
while(TRUE)
{
RBIE=0;
delay_ms(500);
//calculo de frec
printf("\r\ntpo=%f ", frecuencial);
restart_wdt();
}
}
con esto intento probar que al producirce un cambio en GP2/INT produzca una
interrupcion e imprima una X, pero no me funciona, como mencione anteriormente, lo
unico que se me ocurre es la calibracion del oscilador (cdo se utiliza osc. interno
se debe calibrar). He probado lo mismo en otro pic(f876) que tambien tiene pin
interrup externa (rb/int) y funciona pero en el 12f675 no way.Alguna idea??
Saludos

Tu programa qued� asi:

#include <12F675.h>
#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_A1,rcv=PIN_A0,bits=8)
#fuses INTRC_IO,NOWDT,NOCPD,NOPROTECT,NOMCLR,PUT,NOBROWNOUT
#byte STATUS=0x03
#byte WPU=0x95
float frecuencia;

#int_EXT
void EXT_isr()
{
printf("\r\ntpo=%f ", frecuencia);
putc ('x');
printf("%C", 0x0D); //Envia "Enter"
}
void main()
{
set_tris_a(0b000101);
#asm
bsf STATUS,5 //Banco 1
movlw 0x5 //Activa la resistencia de PULL-UP
movwf WPU //en los pines GPIO_0 y GPIO_2
#endasm
ext_int_edge(L_TO_H); //Define flanco de subida (Para la acyivacion de la
interrupcion)
enable_interrupts(INT_EXT);
enable_interrupts(global);
while(TRUE)
{}
}

Te recomiendo no manipules las banderas de interrupcion ya que el compilador lo


hace por ti. Adem�s el habilitar el WDT en este programa tan sencillo no es
conveniente ya que no veo algun factor que lo pueda hacer perder del curso del
programa a no ser que sea por la fuente de alimentacion.
Si tienes alguna otra duda puedes apoyarte en el manual del uC y en las
caracteristicas del dispositivo MENU_INICIO->carpeta PICC->Suported Devices y
eliges 12F675.h y doble click.

gfp :-)

Вам также может понравиться