Autor Tema: interrupciones con hitech picc  (Leído 3546 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado black_flowers

  • PIC18
  • ****
  • Mensajes: 450
interrupciones con hitech picc
« en: 11 de Octubre de 2008, 17:23:35 »
hola, he visto numerosos ejemplos de cómo tratar las interrupciones con ccs  pero ninguno con hitech picc. ¿cómo puedo tratar interrupciones con hitech picc? ¿puede ser así?:

interrupt ISR ()
{
// aquí compruebo cual ha sido el motivo de la interrupcion
}

void main() {
}

Desconectado arcachofo

  • PIC16
  • ***
  • Mensajes: 126
    • Foro para usuarios Linux.
Re: interrupciones con hitech picc
« Respuesta #1 en: 12 de Octubre de 2008, 15:16:10 »
Ejemplo:
Código: [Seleccionar]
#include <pic.h>

/*
 * Interrupt demo for PIC; wait for button press on RB0/INT,
 * turn on a relay on another port bit for a period of time.
 * For simplicity here, literal constants are used, usually these
 * should be calculated with compile-time arithmetic.
 */

#define RELAY RB4 // use this bit to drive relay

static unsigned int relay_timer; // timer value for relay driver

void
main(void)
{
/* setup stuff */

RELAY = 1; // ensure relay is off before enabling output
TRISB = 0x03; // Port B bits 7 and 6 are output

OPTION = 0b00000111;
TRISB = 0b00000011;

RBPU = 0; // Use internal pullups
T0IE = 1; // Enable interrupt on TMR0 overflow
INTEDG = 1; // falling edge trigger the interrupt
INTE = 1; // enable the external interrupt
GIE = 1; // Global interrupt enable
for(;;){
CLRWDT(); // Idly kick the dog
}
}

static void interrupt
isr(void) // Here be interrupt function - the name is unimportant.
{
if(T0IF) { // timer interrupt
PORTB ^= 4;
if(relay_timer){// is the relay timer running?
relay_timer--; // decrement it
PORTB |= 8;
}else{
RELAY = 1; // turn the relay off
PORTB &= ~8; // toggle a bit to say we're alive
}
T0IF = 0; // clear the interrupt flag
}
if(INTF) { // did we see a button press?
RELAY = 0; // turn the relay on
relay_timer = 16; // start the timer - 16 timeouts ~ 1 second
INTF = 0; // clear the interrupt
}
}

Pero el static no es obligatorio... el ejemplo anterior biene en la instalción del Hi-tech PICC, en el manual biene esto:

Código: [Seleccionar]
int tick_count;
void interrupt tc_int(void)
{
    if (T0IE && T0IF) {
        T0IF=0;
        ++tick_count;
    }
}

Osea que tal como tú decías, yo estoy empezando a echarle un ojo a esto, así que no te puedo decir más...
« Última modificación: 12 de Octubre de 2008, 15:25:35 por arcachofo »


 

anything