Rev 150 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
#include "defines.h"#include "interrupts.h"#include "uart.h"#include "i2c.h"#include "spi.h"#include "adc.h"#include "timers.h"//----------------------------------------------------------------------------// Note: This code for processing interrupts is configured to allow for high and// low priority interrupts. The high priority interrupt can interrupt the// the processing of a low priority interrupt. However, only one of each type// can be processed at the same time. It is possible to enable nesting of low// priority interrupts, but this code is not setup for that and this nesting// is not enabled.void Interrupt_Init() {// Peripheral interrupts can have their priority set to high or low// Decide on the priority of the enabled peripheral interrupts (0 is low, 1 is high)// High priority interruptsIPR1bits.RC1IP = 1; // USART1 RX interruptIPR1bits.TX1IP = 1; // USART1 TX interrupt// IPR3bits.RC2IP = 1; // USART2 RX interruptIPR1bits.SSPIP = 1; // I2C interruptIPR3bits.SSP2IP = 1; // MSSP2 (SPI2) interrupt// Low priority interrupts// INTCON2bits.TMR0IP = 0; // Timer0 interruptIPR1bits.TMR1IP = 0; // Timer1 interrupt// IPR2bits.TMR3IP = 0; // Timer 3 interrupt// IPR1bits.ADIP = 0; // ADC interupt// INTCON2bits.RBIP = 0; // Port B interrupt// INTCON3bits.INT1IP = 0; // INT1 interrupt// Enable Port B interrupt// INTCONbits.RBIE = 1;// Enable interrupt for INT1// INTCON3bits.INT1IE = 1;}void Interrupt_Enable() {// Peripheral interrupts can have their priority set to high or low.// Enable both high-priority interrupts and low-priority interruptsRCONbits.IPEN = 1;INTCONbits.GIEH = 1;INTCONbits.GIEL = 1;}void Interrupt_Disable() {RCONbits.IPEN = 0;INTCONbits.GIEH = 0;INTCONbits.GIEL = 0;}// Set up the interrupt vectorsvoid InterruptHandlerHigh();void InterruptHandlerLow();#pragma code InterruptVectorLow = 0x18void InterruptVectorLow(void) {_asmgoto InterruptHandlerLow //jump to interrupt routine_endasm}#pragma code InterruptVectorHigh = 0x08void InterruptVectorHigh(void) {_asmgoto InterruptHandlerHigh //jump to interrupt routine_endasm}//----------------------------------------------------------------------------// High priority interrupt routine// this parcels out interrupts to individual handlers#pragma code#pragma interrupt InterruptHandlerHighvoid InterruptHandlerHigh() {// We need to check the interrupt flag of each enabled high-priority interrupt to// see which device generated this interrupt. Then we can call the correct handler.// // Check to see if we have an SPI2 interrupt// if (PIR3bits.SSP2IF) {// // Call the handler// SPI2_Recv_Interrupt_Handler();//// // Clear the interrupt flag// PIR3bits.SSP2IF = 0;//// return;// }// Check to see if we have an I2C interruptif (PIR1bits.SSPIF) {// Call the handlerI2C_Interrupt_Handler();// Clear the interrupt flagPIR1bits.SSPIF = 0;return;}// Check to see if we have an interrupt on USART1 RXif (PIR1bits.RC1IF) {// Call the interrupt handlerUART1_Recv_Interrupt_Handler();// Clear the interrupt flagPIR1bits.RC1IF = 0;return;}#ifndef _DEBUG // Disable UART1 TX interrupt for debug mode (using printf)// Check to see if we have an interrupt on USART1 TXif (PIR1bits.TX1IF) {// Call the interrupt handlerUART1_Send_Interrupt_Handler();// Clear the interrupt flagPIR1bits.TX1IF = 0;return;}#endif// // Check to see if we have an interrupt on USART2 RX// if (PIR3bits.RC2IF) {// DBG_PRINT_INT("INT: UART2 RX\r\n");// // Call the interrupt handler// uart_2_recv_interrupt_handler();//// // Clear the interrupt flag// PIR3bits.RC2IF = 0;// }}//----------------------------------------------------------------------------// Low priority interrupt routine// this parcels out interrupts to individual handlers#pragma code#pragma interruptlow InterruptHandlerLow// This works the same way as the "High" interrupt handlervoid InterruptHandlerLow() {// // Check to see if we have an interrupt on INT1// if (INTCON3bits.INT1IF) {// DBG_PRINT_INT("INT: INT1\r\n");// int1_interrupt_handler();//// INTCON3bits.INT1IF = 0;// }// // Check to see if we have an interrupt on any port B inputs <4:7>// if (INTCONbits.RBIF) {// DBG_PRINT_INT("INT: Port B\r\n");// port_b_int_interrupt_handler();//// INTCONbits.RBIF = 0;// }// // Check to see if we have an interrupt on timer 0// if (INTCONbits.TMR0IF) {// DBG_PRINT_INT("INT: Timer 0\r\n");// // Call the handler// timer0_interrupt_handler();//// // Clear this interrupt flag// INTCONbits.TMR0IF = 0;// }// Check to see if we have an interrupt on timer 1if (PIR1bits.TMR1IF) {// Call the interrupt handlerTimer1_Interrupt_Handler();// Clear the interrupt flagPIR1bits.TMR1IF = 0;}// // Check to see if we have an interrupt on timer 3// if (PIR2bits.TMR3IF) {// DBG_PRINT_INT("INT: Timer 3\r\n");// timer3_interrupt_handler();//// PIR2bits.TMR3IF = 0;// }// // Check to see if we have an interrupt on ADC// if (PIR1bits.ADIF) {// // Call the interrupt handler// ADC_Interrupt_Handler();//// // Clear the interrupt flag// PIR1bits.ADIF = 0;// }}