/* PLANTILLA PARA EL MANEJO DE INTERRUPCIONES EN C18 */
void ISR_H(void); // Prototipo de funcion de ISR_H
void ISR_L(void); // Prototipo de funcion ISR_L
/* Interrupcion de alta prioridad */
#pragma code high_vector_section=0x0008 // Vector de int de alta prioridad void high_vector (void) { _asm goto ISR_H // Direccion de salto a ISR_H _endasm } #pragma code #pragma interrupt ISR_H // Rutina de Servicio como Interrup. de alta prioridad
/* Interrupcion de baja prioridad */
#pragma code low_vector_section=0x0018 // Vector de int de baja prioridad void low_vector (void) { _asm goto ISR_L // Direccion de salto a ISR_L _endasm } #pragma code #pragma interruptlow ISR_L // Rutina de Servicio como Interrup. de baja prioridad
/* Rutina de Servicio de alta prioridad ISR_H */
void ISR_H(void) { if(INTCONbits.RBIF) // Bandera de interrupcion por cambio en RB<4:7> { INTCONbits.RBIF = 0; // Borra bandera de interrupcion por RB<4:7> --------------------- --------------------- --------------------- } if(INTCONbits.TMR0IF) // Bandera de interrupcion por TMR0 { INTCONbits. TMR0IF = 0; // Borra bandera de interrupcion por TMR0 --------------------- --------------------- --------------------- } } // Retorno de interrupcion de alta prioridad /* Rutina de Servicio de baja prioridad ISR_L */ void ISR_L(void) { if(INTCON3bits.INT2IF) // Bandera de interrupcion por cambio en RB<4:7> { INTCONbits.RBIF = 0; // Borra bandera de interrupcion por RB<4:7> --------------------- --------------------- --------------------- } if(INTCON3bits.INT1IF) // Bandera de interrupcion por TMR0 { INTCONbits. TMR0IF = 0; // Borra bandera de interrupcion por TMR0 --------------------- --------------------- --------------------- } } // Retorno de interrupcion de alta prioridad
/* A qui inicia el programa principal */
void main (void) { Configura_Puertos(); // Configura Puertos a usar Configura_Interrups(); // Configura interrupcion por RB RCONbits.IPEN = 1; // Habilita interrupciones con Prioridad INTCONbits.GIEL = 1; // Habilita todas las interrupciones de baja prioridad INTCONbits.GIEH = 1; // Habilita todas las interrupciones de alta prioridad