12,7 → 12,7 |
TRISCbits.TRISC2 = 0; |
LATCbits.LATC2 = 0; |
|
RPINR1 = 16; // Bind INT1 interrupt to RP2 |
RPINR1 = 2; // Bind INT1 interrupt to RP2 |
|
INTCON3bits.INT1IE = 1; // Enable interrupt for INT1 |
INTCON2bits.INTEDG1 = 0; // Trigger on falling edge |
20,7 → 20,7 |
|
void int1_interrupt_handler() { |
LATCbits.LATC2 = 1; |
Delay10KTCYx(100); |
Delay10TCYx(1); |
LATCbits.LATC2 = 0; |
} |
|
44,9 → 44,6 |
LATBbits.LATB5 = 1; |
LATBbits.LATB6 = 1; |
LATBbits.LATB7 = 1; |
|
// Enable Port B interrupt |
INTCONbits.RBIE = 1; |
} |
|
void port_b_int_interrupt_handler() { |
56,46 → 53,46 |
// Query which pin input value changed and send value to main() |
if ((new_state ^ port_b_prev_state) & 0x01) { |
if (port_b_prev_state & 0x01) { |
// Pin transitioned HIGH -> LOW (button pressed) |
DBG_PRINT_PORTB_INT("Port B4 HIGH->LOW\r\n"); |
MQ_sendmsg_ToMainFromLow(0, MSGTYPE_PORTB_4_DOWN, (void *) 0); |
} else { |
// Pin transitioned LOW -> HIGH (button released) |
DBG_PRINT_PORTB_INT("Port B4 LOW->HIGH\r\n"); |
MQ_sendmsg_ToMainFromHigh(0, MSGTYPE_PORTB_4_UP, (void *) 0); |
} else { |
// Pin transitioned HIGH -> LOW (button pressed) |
DBG_PRINT_PORTB_INT("Port B4 HIGH->LOW\r\n"); |
MQ_sendmsg_ToMainFromHigh(0, MSGTYPE_PORTB_4_DOWN, (void *) 0); |
MQ_sendmsg_ToMainFromLow(0, MSGTYPE_PORTB_4_UP, (void *) 0); |
} |
} |
if ((new_state ^ port_b_prev_state) & 0x02) { |
if (port_b_prev_state & 0x02) { |
// Pin transitioned HIGH -> LOW (button pressed) |
DBG_PRINT_PORTB_INT("Port B5 HIGH->LOW\r\n"); |
MQ_sendmsg_ToMainFromLow(0, MSGTYPE_PORTB_5_DOWN, (void *) 0); |
} else { |
// Pin transitioned LOW -> HIGH (button released) |
DBG_PRINT_PORTB_INT("Port B5 LOW->HIGH\r\n"); |
MQ_sendmsg_ToMainFromHigh(0, MSGTYPE_PORTB_5_UP, (void *) 0); |
} else { |
// Pin transitioned HIGH -> LOW (button pressed) |
DBG_PRINT_PORTB_INT("Port B5 HIGH->LOW\r\n"); |
MQ_sendmsg_ToMainFromHigh(0, MSGTYPE_PORTB_5_DOWN, (void *) 0); |
MQ_sendmsg_ToMainFromLow(0, MSGTYPE_PORTB_5_UP, (void *) 0); |
} |
} |
if ((new_state ^ port_b_prev_state) & 0x04) { |
if (port_b_prev_state & 0x04) { |
// Pin transitioned HIGH -> LOW (button pressed) |
DBG_PRINT_PORTB_INT("Port B6 HIGH->LOW\r\n"); |
MQ_sendmsg_ToMainFromLow(0, MSGTYPE_PORTB_6_DOWN, (void *) 0); |
} else { |
// Pin transitioned LOW -> HIGH (button released) |
DBG_PRINT_PORTB_INT("Port B6 LOW->HIGH\r\n"); |
MQ_sendmsg_ToMainFromHigh(0, MSGTYPE_PORTB_6_UP, (void *) 0); |
} else { |
// Pin transitioned HIGH -> LOW (button pressed) |
DBG_PRINT_PORTB_INT("Port B6 HIGH->LOW\r\n"); |
MQ_sendmsg_ToMainFromHigh(0, MSGTYPE_PORTB_6_DOWN, (void *) 0); |
MQ_sendmsg_ToMainFromLow(0, MSGTYPE_PORTB_6_UP, (void *) 0); |
} |
} |
if ((new_state ^ port_b_prev_state) & 0x08) { |
if (port_b_prev_state & 0x08) { |
// Pin transitioned HIGH -> LOW (button pressed) |
DBG_PRINT_PORTB_INT("Port B7 HIGH->LOW\r\n"); |
MQ_sendmsg_ToMainFromLow(0, MSGTYPE_PORTB_7_DOWN, (void *) 0); |
} else { |
// Pin transitioned LOW -> HIGH (button released) |
DBG_PRINT_PORTB_INT("Port B7 LOW->HIGH\r\n"); |
MQ_sendmsg_ToMainFromHigh(0, MSGTYPE_PORTB_7_UP, (void *) 0); |
} else { |
// Pin transitioned HIGH -> LOW (button pressed) |
DBG_PRINT_PORTB_INT("Port B7 HIGH->LOW\r\n"); |
MQ_sendmsg_ToMainFromHigh(0, MSGTYPE_PORTB_7_DOWN, (void *) 0); |
MQ_sendmsg_ToMainFromLow(0, MSGTYPE_PORTB_7_UP, (void *) 0); |
} |
} |
|