Subversion Repositories Code-Repo

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
273 Kevin 1
#include "defines.h"
2
#include "IO.h"
3
#include "MCP23009.h"
4
 
5
void IO_Init(void) {
6
    // Set all pins to digital I/O
7
    ANSELA = 0x0;
8
    ANSELB = 0x0;
9
    ANSELC = 0x0;
10
 
11
    // Enable weak pull-up if WPU bit is set
12
    OPTION_REGbits.nWPUEN = 0;
13
 
14
    // Initialize interrupt inputs
15
    LSM303_INT_TRIS = 1;
16
    L3GD20_INT_TRIS = 1;
17
    BTN_INT_TRIS = 1;
18
 
19
    // Initialize UART pins
20
    UART_RX_TRIS = 1;
21
    UART_TX_TRIS = 0;
22
 
23
    // Initialize I2C address pins
24
    I2C_ADDR_0_TRIS = 1;
25
    I2C_ADDR_1_TRIS = 1;
26
    I2C_ADDR_2_TRIS = 1;
27
    I2C_ADDR_3_TRIS = 1;
28
    // Enable the weak-pullup on the address pins
29
    I2C_ADDR_0_WPU = 1;
30
    I2C_ADDR_1_WPU = 1;
31
    I2C_ADDR_2_WPU = 1;
32
    I2C_ADDR_3_WPU = 1;
33
 
34
    // Initialize I2C pins (dont really need to as the I2C code does it)
35
    I2C_1_CLK_TRIS = 1;
36
    I2C_1_DAT_TRIS = 1;
37
    I2C_2_CLK_TRIS = 1;
38
    I2C_2_DAT_TRIS = 1;
277 Kevin 39
 
40
    // Set the CPS pins
41
    CPS_L_TRIS = 1;
42
    CPS_R_TRIS = 1;
43
    CPS_L_ANSL = 1;
44
    CPS_R_ANSL = 1;
45
    CPS_R_WPU = 0;
46
    CPS_L_WPU = 0;
273 Kevin 47
}
48
 
49
void IO_IOC_Enable(void) {
50
    // Clear all IOC flags
51
    IOCAF = 0x0;
52
    IOCBF = 0x0;
53
 
54
    // Trigger interrupt on BTN_INT on falling edge
55
    IOCANbits.IOCAN2 = 1;
56
 
57
    // Enable IOC interrupts
58
    INTCONbits.IOCIE = 1;
59
}
60
 
61
void IO_Interrupt(void) {
62
    Reset_Board(OP_STATE_ACTIVE);
63
}