Subversion Repositories Code-Repo

Rev

Rev 109 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 109 Rev 111
Line 10... Line 10...
10
    TRISAbits.TRISA5 = 1;
10
    TRISAbits.TRISA5 = 1;
11
    
11
    
12
    TRISCbits.TRISC2 = 0;
12
    TRISCbits.TRISC2 = 0;
13
    LATCbits.LATC2 = 0;
13
    LATCbits.LATC2 = 0;
14
 
14
 
15
    RPINR1 = 16; // Bind INT1 interrupt to RP2
15
    RPINR1 = 2; // Bind INT1 interrupt to RP2
16
 
16
 
17
    INTCON3bits.INT1IE = 1;     // Enable interrupt for INT1
17
    INTCON3bits.INT1IE = 1;     // Enable interrupt for INT1
18
    INTCON2bits.INTEDG1 = 0;    // Trigger on falling edge
18
    INTCON2bits.INTEDG1 = 0;    // Trigger on falling edge
19
}
19
}
20
 
20
 
21
void int1_interrupt_handler() {
21
void int1_interrupt_handler() {
22
    LATCbits.LATC2 = 1;
22
    LATCbits.LATC2 = 1;
23
    Delay10KTCYx(100);
23
    Delay10TCYx(1);
24
    LATCbits.LATC2 = 0;
24
    LATCbits.LATC2 = 0;
25
}
25
}
26
 
26
 
27
void port_b_int_init() {
27
void port_b_int_init() {
28
    port_b_prev_state = 0x0F;
28
    port_b_prev_state = 0x0F;
Line 42... Line 42...
42
    PORTBbits.RB7 = 1;
42
    PORTBbits.RB7 = 1;
43
    LATBbits.LATB4 = 1;
43
    LATBbits.LATB4 = 1;
44
    LATBbits.LATB5 = 1;
44
    LATBbits.LATB5 = 1;
45
    LATBbits.LATB6 = 1;
45
    LATBbits.LATB6 = 1;
46
    LATBbits.LATB7 = 1;
46
    LATBbits.LATB7 = 1;
47
 
-
 
48
    // Enable Port B interrupt
-
 
49
    INTCONbits.RBIE = 1;
-
 
50
}
47
}
51
 
48
 
52
void port_b_int_interrupt_handler() {
49
void port_b_int_interrupt_handler() {
53
    // Pull the new pin values
50
    // Pull the new pin values
54
    unsigned char new_state = (PORTB & 0xF0) >> 4;
51
    unsigned char new_state = (PORTB & 0xF0) >> 4;
55
 
52
 
56
    // Query which pin input value changed and send value to main()
53
    // Query which pin input value changed and send value to main()
57
    if ((new_state ^ port_b_prev_state) & 0x01) {
54
    if ((new_state ^ port_b_prev_state) & 0x01) {
58
        if (port_b_prev_state & 0x01) {
55
        if (port_b_prev_state & 0x01) {
59
            // Pin transitioned LOW -> HIGH (button released)
-
 
60
            DBG_PRINT_PORTB_INT("Port B4 LOW->HIGH\r\n");
-
 
61
            MQ_sendmsg_ToMainFromHigh(0, MSGTYPE_PORTB_4_UP, (void *) 0);
-
 
62
        } else {
-
 
63
            // Pin transitioned HIGH -> LOW (button pressed)
56
            // Pin transitioned HIGH -> LOW (button pressed)
64
            DBG_PRINT_PORTB_INT("Port B4 HIGH->LOW\r\n");
57
            DBG_PRINT_PORTB_INT("Port B4 HIGH->LOW\r\n");
65
            MQ_sendmsg_ToMainFromHigh(0, MSGTYPE_PORTB_4_DOWN, (void *) 0);
58
            MQ_sendmsg_ToMainFromLow(0, MSGTYPE_PORTB_4_DOWN, (void *) 0);
-
 
59
        } else {
-
 
60
            // Pin transitioned LOW -> HIGH (button released)
-
 
61
            DBG_PRINT_PORTB_INT("Port B4 LOW->HIGH\r\n");
-
 
62
            MQ_sendmsg_ToMainFromLow(0, MSGTYPE_PORTB_4_UP, (void *) 0);
66
        }
63
        }
67
    }
64
    }
68
    if ((new_state ^ port_b_prev_state) & 0x02) {
65
    if ((new_state ^ port_b_prev_state) & 0x02) {
69
        if (port_b_prev_state & 0x02) {
66
        if (port_b_prev_state & 0x02) {
70
            // Pin transitioned LOW -> HIGH (button released)
-
 
71
            DBG_PRINT_PORTB_INT("Port B5 LOW->HIGH\r\n");
-
 
72
            MQ_sendmsg_ToMainFromHigh(0, MSGTYPE_PORTB_5_UP, (void *) 0);
-
 
73
        } else {
-
 
74
            // Pin transitioned HIGH -> LOW (button pressed)
67
            // Pin transitioned HIGH -> LOW (button pressed)
75
            DBG_PRINT_PORTB_INT("Port B5 HIGH->LOW\r\n");
68
            DBG_PRINT_PORTB_INT("Port B5 HIGH->LOW\r\n");
76
            MQ_sendmsg_ToMainFromHigh(0, MSGTYPE_PORTB_5_DOWN, (void *) 0);
69
            MQ_sendmsg_ToMainFromLow(0, MSGTYPE_PORTB_5_DOWN, (void *) 0);
-
 
70
        } else {
-
 
71
            // Pin transitioned LOW -> HIGH (button released)
-
 
72
            DBG_PRINT_PORTB_INT("Port B5 LOW->HIGH\r\n");
-
 
73
            MQ_sendmsg_ToMainFromLow(0, MSGTYPE_PORTB_5_UP, (void *) 0);
77
        }
74
        }
78
    }
75
    }
79
    if ((new_state ^ port_b_prev_state) & 0x04) {
76
    if ((new_state ^ port_b_prev_state) & 0x04) {
80
        if (port_b_prev_state & 0x04) {
77
        if (port_b_prev_state & 0x04) {
81
            // Pin transitioned LOW -> HIGH (button released)
-
 
82
            DBG_PRINT_PORTB_INT("Port B6 LOW->HIGH\r\n");
-
 
83
            MQ_sendmsg_ToMainFromHigh(0, MSGTYPE_PORTB_6_UP, (void *) 0);
-
 
84
        } else {
-
 
85
            // Pin transitioned HIGH -> LOW (button pressed)
78
            // Pin transitioned HIGH -> LOW (button pressed)
86
            DBG_PRINT_PORTB_INT("Port B6 HIGH->LOW\r\n");
79
            DBG_PRINT_PORTB_INT("Port B6 HIGH->LOW\r\n");
87
            MQ_sendmsg_ToMainFromHigh(0, MSGTYPE_PORTB_6_DOWN, (void *) 0);
80
            MQ_sendmsg_ToMainFromLow(0, MSGTYPE_PORTB_6_DOWN, (void *) 0);
-
 
81
        } else {
-
 
82
            // Pin transitioned LOW -> HIGH (button released)
-
 
83
            DBG_PRINT_PORTB_INT("Port B6 LOW->HIGH\r\n");
-
 
84
            MQ_sendmsg_ToMainFromLow(0, MSGTYPE_PORTB_6_UP, (void *) 0);
88
        }
85
        }
89
    }
86
    }
90
    if ((new_state ^ port_b_prev_state) & 0x08) {
87
    if ((new_state ^ port_b_prev_state) & 0x08) {
91
        if (port_b_prev_state & 0x08) {
88
        if (port_b_prev_state & 0x08) {
92
            // Pin transitioned LOW -> HIGH (button released)
-
 
93
            DBG_PRINT_PORTB_INT("Port B7 LOW->HIGH\r\n");
-
 
94
            MQ_sendmsg_ToMainFromHigh(0, MSGTYPE_PORTB_7_UP, (void *) 0);
-
 
95
        } else {
-
 
96
            // Pin transitioned HIGH -> LOW (button pressed)
89
            // Pin transitioned HIGH -> LOW (button pressed)
97
            DBG_PRINT_PORTB_INT("Port B7 HIGH->LOW\r\n");
90
            DBG_PRINT_PORTB_INT("Port B7 HIGH->LOW\r\n");
98
            MQ_sendmsg_ToMainFromHigh(0, MSGTYPE_PORTB_7_DOWN, (void *) 0);
91
            MQ_sendmsg_ToMainFromLow(0, MSGTYPE_PORTB_7_DOWN, (void *) 0);
-
 
92
        } else {
-
 
93
            // Pin transitioned LOW -> HIGH (button released)
-
 
94
            DBG_PRINT_PORTB_INT("Port B7 LOW->HIGH\r\n");
-
 
95
            MQ_sendmsg_ToMainFromLow(0, MSGTYPE_PORTB_7_UP, (void *) 0);
99
        }
96
        }
100
    }
97
    }
101
    
98
    
102
    // Save the new state of pins
99
    // Save the new state of pins
103
    port_b_prev_state = new_state;
100
    port_b_prev_state = new_state;