Code:
/*******************************************************************************
*
* FUNCTION: Int_1_Handler()
*
* PURPOSE: If enabled, the interrupt 1 handler is called when the
* interrupt 1/digital input 1 pin changes logic level. The
* edge that the interrupt 1 pin reacts to is programmable
* (see comments in the Initialize_Interrupts() function,
* above).
*
* CALLED FROM: user_routines_fast.c/InterruptHandlerLow()
*
* PARAMETERS: None
*
* RETURNS: Nothing
*
* COMMENTS: The PIC18F8520's RB2/INT2 pin on port b is mapped to
* interrupt 1 on the EDU-RC and digital input 1 on the
* FRC-RC [108].
*
*******************************************************************************/
//CATLIN FUCNTION
void Int_1_Handler(void)
{
//printf("int1");
if(ENCODER2 == INPUTTRUE){
//A came second so its going clockwise
// printf("TRUE \r");
directionTravelingOne = FORWARD;
}else{
// printf("FALSE subtract from varible \r");
/*b came first so its going counter clockwise*/
directionTravelingOne = BACKWARD;
clickRotationsOne--;
}
//printf("%d",clickRotations );
// this function will be called when an interrupt 1 occurs
}
/*******************************************************************************
*
* FUNCTION: Int_2_Handler()
*
* PURPOSE: If enabled, the interrupt 2 handler is called when the
* interrupt 2/digital input 2 pin changes logic level. The
* edge that the interrupt 2 pin reacts to is programmable
* (see comments in the Initialize_Interrupts() function,
* above).
*
* CALLED FROM: user_routines_fast.c/InterruptHandlerLow()
*
* PARAMETERS: None
*
* RETURNS: Nothing
*
* COMMENTS: The PIC18F8520's RB3/CCP2/INT3 pin on port b is mapped
* to interrupt 2 on the EDU-RC and digital input 2 on the
* FRC-RC [108].
*
*******************************************************************************/
//CATLIN FUNC
void Int_2_Handler(void)
{
//printf("int2");
//callPutData();
if(ENCODER1 == INPUTTRUE){
//A came second so its going clockwise
directionTravelingOne = BACKWARD;
//printf("TRUE \r");
}else{
printf("False add one to counter \r");
/*b came first so its going counter clockwise*/
directionTravelingOne = FORWARD;
clickRotationsOne++;
printf("%d", clickRotationsOne);
} // this function will be called when an interrupt 2 occurs
//printf("Encoder 1: " + directionTraveling);
//printf("Total Distance: " + clickRotations);
}
/*******************************************************************************
*
* FUNCTION: Int_3_Handler()
*
* PURPOSE: If enabled, the interrupt 3 handler is called when the
* interrupt 3/digital input 3 pin changes logic level.
*
* CALLED FROM: user_routines_fast.c/InterruptHandlerLow()
*
* PARAMETERS: RB4_State is the current logic level of the
* interrupt 3 pin.
*
* RETURNS: Nothing
*
* COMMENTS: The PIC18F8520's RB4/KBI0 pin on port b is mapped to
* interrupt 3 on the EDU-RC and digital input 3 on the
* FRC-RC [108].
*
*******************************************************************************/
//CATLIN FUNC
void Int_3_Handler(unsigned char RB4_State)
{
//printf("int3");
// printf("\n");
// printf("%d", (int) RB4_State);
if(RB4_State == 1){
if(ENCODER4 == INPUTTRUE){
//A came second so its going clockwise
directionTravelingTwo = FORWARD;
}else{
/*b came first so its going counter clockwise*/
directionTravelingTwo = BACKWARD;
clickRotationsTwo--;
}
//printf("%d",clickRotations );
}
// this function will be called when an interrupt 3 occurs
}
/*******************************************************************************
*
* FUNCTION: Int_4_Handler()
*
* PURPOSE: If enabled, the interrupt 4 handler is called when the
* interrupt 4/digital input 4 pin changes logic level.
*
* CALLED FROM: user_routines_fast.c/InterruptHandlerLow()
*
* PARAMETERS: RB5_State is the current logic level of the
* interrupt 4 pin.
*
* RETURNS: Nothing
*
* COMMENTS: The PIC18F8520's RB5/KBI1/PGM pin on port b is mapped
* to interrupt 4 on the EDU-RC and digital input 4 on the
* FRC-RC [108].
*
*******************************************************************************/
//CATLIN FUNC
void Int_4_Handler(unsigned char RB5_State)
{
// printf("\n");
//printf("%d", (int) ENCODER3);
if(RB5_State == 1){
if(ENCODER3 == INPUTTRUE){
//A came second so its going clockwise
directionTravelingTwo = BACKWARD;
}else{
/*b came first so its going counter clockwise*/
directionTravelingTwo = FORWARD;
clickRotationsTwo++;
}
}
//printf("Encoder 1: " + directionTraveling);
//printf("Total Distance: " + clickRotations);
// this function will be called when an interrupt 4 occurs
}
/*******************************************************************************
*
* FUNCTION: Int_5_Handler()
*
* PURPOSE: If enabled, the interrupt 5 handler is called when the
* interrupt 5/digital input 5 pin changes logic level.
*
* CALLED FROM: user_routines_fast.c/InterruptHandlerLow()
*
* PARAMETERS: RB6_State is the current logic level of the
* interrupt 5 pin.
*
* RETURNS: Nothing
*
* COMMENTS: The PIC18F8520's RB6/KBI2/PGC pin on port b is mapped
* to interrupt 5 on the EDU-RC and digital input 5 on the
* FRC-RC [108].
*
*******************************************************************************/
void Int_5_Handler(unsigned char RB6_State)
{
printf("int5");
// printf("\n");
// printf("%d", (int) RB4_State);
if(RB6_State == 1){
if(ENCODER6 == INPUTTRUE){
//A came second so its going clockwise
directionTravelingThree = FORWARD;
}else{
/*b came first so its going counter clockwise*/
directionTravelingThree = BACKWARD;
clickRotationsThree--;
}
//printf("%d",clickRotations );
}
// this function will be called when an interrupt 5 occurs
}
/*******************************************************************************
*
* FUNCTION: Int_6_Handler()
*
* PURPOSE: If enabled, the interrupt 6 handler is called when the
* interrupt 6/digital input 6 pin changes logic level.
*
* CALLED FROM: user_routines_fast.c/InterruptHandlerLow()
*
* PARAMETERS: RB7_State is the current logic level of the
* interrupt 6 pin.
*
* RETURNS: Nothing
*
* COMMENTS: The PIC18F8520's RB7/KBI3/PGD pin on port b is mapped
* to interrupt 6 on the EDU-RC and digital input 6 on the
* FRC-RC [108].
*
*******************************************************************************/
void Int_6_Handler(unsigned char RB7_State)
{
// printf("\n");
printf("int6");
//printf("%d", (int) ENCODER5);
if(RB7_State == 1){
if(ENCODER5 == INPUTTRUE){
//A came second so its going clockwise
directionTravelingThree = BACKWARD;
}else{
/*b came first so its going counter clockwise*/
directionTravelingThree = FORWARD;
clickRotationsThree++;
}
}
//printf("Encoder 1: " + directionTraveling);
//printf("Total Distance: " + clickRotations);
// this function will be called when an interrupt 6 occurs
}
Code:
/*******************************************************************************
* FUNCTION NAME: InterruptHandlerLow
* PURPOSE: Low priority interrupt handler
* If you want to use these external low priority interrupts or any of the
* peripheral interrupts then you must enable them in your initialization
* routine. Innovation First, Inc. will not provide support for using these
* interrupts, so be careful. There is great potential for glitchy code if good
* interrupt programming practices are not followed. Especially read p. 28 of
* the "MPLAB(R) C18 C Compiler User's Guide" for information on context saving.
* CALLED FROM: this file, InterruptVectorLow routine
* ARGUMENTS: none
* RETURNS: void
*******************************************************************************/
#pragma code
#pragma interruptlow InterruptHandlerLow save=PROD,section(".tmpdata")
void InterruptHandlerLow ()
{
unsigned char Port_B;
unsigned char Port_B_Delta;
if (INTCONbits.TMR0IF && INTCONbits.TMR0IE) // timer 0 interrupt?
{
INTCONbits.TMR0IF = 0; // clear the timer 0 interrupt flag [89]
Timer_0_Int_Handler(); // call the timer 0 interrupt handler (in interrupts.c)
}
else if (PIR1bits.TMR1IF && PIE1bits.TMR1IE) // timer 1 interrupt?
{
PIR1bits.TMR1IF = 0; // clear the timer 1 interrupt flag [92]
Timer_1_Int_Handler(); // call the timer 1 interrupt handler (in interrupts.c)
}
else if (PIR1bits.TMR2IF && PIE1bits.TMR2IE) // timer 2 interrupt?
{
PIR1bits.TMR2IF = 0; // clear the timer 2 interrupt flag [92]
Timer_2_Int_Handler(); // call the timer 2 interrupt handler (in interrupts.c)
}
else if (PIR2bits.TMR3IF && PIE2bits.TMR3IE) // timer 3 interrupt?
{
PIR2bits.TMR3IF = 0; // clear the timer 3 interrupt flag [93]
Timer_3_Int_Handler(); // call the timer 3 interrupt handler (in interrupts.c)
}
else if (PIR3bits.TMR4IF && PIE3bits.TMR4IE) // timer 4 interrupt?
{
PIR3bits.TMR4IF = 0; // clear the timer 4 interrupt flag [94]
Timer_4_Int_Handler(); // call the timer 4 interrupt handler (in interrupts.c)
}
else if (INTCON3bits.INT2IF && INTCON3bits.INT2IE) // external interrupt 1?
{
INTCON3bits.INT2IF = 0; // clear the interrupt flag [91]
Int_1_Handler(); // call the interrupt 1 handler (in interrupts.c)
}
else if (INTCON3bits.INT3IF && INTCON3bits.INT3IE) // external interrupt 2?
{
INTCON3bits.INT3IF = 0; // clear the interrupt flag [91]
Int_2_Handler(); // call the interrupt 2 handler (in interrupts.c)
}
else if (INTCONbits.RBIF && INTCONbits.RBIE) // external interrupts 3 through 6?
{
Port_B = PORTB; // remove the "mismatch condition" by reading port b
INTCONbits.RBIF = 0; // clear the interrupt flag [89]
Port_B_Delta = Port_B ^ Old_Port_B; // determine which bits have changed
Old_Port_B = Port_B; // save a copy of port b for next time around
if(Port_B_Delta & 0x10) // did external interrupt 3 change state?
{
Int_3_Handler(Port_B & 0x10 ? 1 : 0); // call the interrupt 3 handler (in interrupts.c)
}
if(Port_B_Delta & 0x20) // did external interrupt 4 change state?
{
Int_4_Handler(Port_B & 0x20 ? 1 : 0); // call the interrupt 4 handler (in interrupts.c)
}
if(Port_B_Delta & 0x40) // did external interrupt 5 change state?
{
Int_5_Handler(Port_B & 0x40 ? 1 : 0); // call the interrupt 5 handler (in interrupts.c)
}
if(Port_B_Delta & 0x80) // did external interrupt 6 change state?
{
Int_6_Handler(Port_B & 0x80 ? 1 : 0); // call the interrupt 6 handler (in interrupts.c)
}
}
if (PIR1bits.RC1IF && PIE1bits.RC1IE) // rx1 interrupt?
{
#ifdef ENABLE_SERIAL_PORT_ONE_RX
Rx_1_Int_Handler(); // call the rx1 interrupt handler (in serial_ports.c)
#endif
}
else if (PIR3bits.RC2IF && PIE3bits.RC2IE) // rx2 interrupt?
{
#ifdef ENABLE_SERIAL_PORT_TWO_RX
Rx_2_Int_Handler(); // call the rx2 interrupt handler (in serial_ports.c)
#endif
}
else if (PIR1bits.TX1IF && PIE1bits.TX1IE) // tx1 interrupt?
{
#ifdef ENABLE_SERIAL_PORT_ONE_TX
Tx_1_Int_Handler(); // call the tx1 interrupt handler (in serial_ports.c)
#endif
}
else if (PIR3bits.TX2IF && PIE3bits.TX2IE) // tx2 interrupt?
{
#ifdef ENABLE_SERIAL_PORT_TWO_TX
Tx_2_Int_Handler(); // call the tx2 interrupt handler (in serial_ports.c)
#endif
}
// *** IFI Code Starts Here***
//
// unsigned char int_byte;
// if (INTCON3bits.INT2IF && INTCON3bits.INT2IE) /* The INT2 pin is RB2/DIG I/O 1. */
// {
// INTCON3bits.INT2IF = 0;
// }
// else if (INTCON3bits.INT3IF && INTCON3bits.INT3IE) /* The INT3 pin is RB3/DIG I/O 2. */
// {
// INTCON3bits.INT3IF = 0;
// }
// else if (INTCONbits.RBIF && INTCONbits.RBIE) /* DIG I/O 3-6 (RB4, RB5, RB6, or RB7) changed. */
// {
// int_byte = PORTB; /* You must read or write to PORTB */
// INTCONbits.RBIF = 0; /* and clear the interrupt flag */
// } /* to clear the interrupt condition. */
// else
// {
// CheckUartInts(); /* For Dynamic Debug Tool or buffered printf features. */
// }
}
Thanks for whatever help you can offer. Excuse my comments of printfs that I used for debugging.