/PIC Stuff/PICX_16F1829_Controller/I2C1.c |
---|
42,12 → 42,16 |
SSP1CON1 = 0x0; |
SSP1CON2 = 0x0; |
SSP1CON1bits.SSPM = 0x8; // I2C Master Mode |
if (!speed) { |
SSPADD = 0x13; // Operate at 400KHz (32MHz) |
if (speed == 0x01) { |
SSP1ADD = 0x13; // Operate at 400KHz (32MHz) |
SSP1STATbits.SMP = 1; // Disable Slew Rate Control |
} else if (speed == 0x02) { |
SSP1ADD = 0x07; // Operate at 1Mhz (32Mhz) |
SSP1STATbits.SMP = 1; // Disable Slew Rate Control |
} else { |
SSPADD = 0x4F; // Operate at 100KHz (32MHz) |
SSP1ADD = 0x4F; // Operate at 100KHz (32MHz) |
SSP1STATbits.SMP = 0; // Enable Slew Rate Control |
} |
SSP1STATbits.SMP = 1; // Disable Slew Rate Control |
SSP1CON1bits.SSPEN = 1; // Enable MSSP1 Module |
} |
/PIC Stuff/PICX_16F1829_Controller/I2C1.h |
---|
4,8 → 4,9 |
#define MAXI2C1BUF 32 |
// I2C Operating Speed |
#define I2C_400KHZ 0x0 |
#define I2C_100KHZ 0x1 |
#define I2C_100KHZ 0x0 |
#define I2C_400KHZ 0x1 |
#define I2C_1MHZ 0x2 |
// Operating State |
#define I2C_IDLE 0x1 |
/PIC Stuff/PICX_16F1829_Controller/I2C2.c |
---|
41,12 → 41,16 |
SSP2CON1 = 0x0; |
SSP2CON2 = 0x0; |
SSP2CON1bits.SSPM = 0x8; // I2C Master Mode |
if (!speed) { |
if (speed == 0x01) { |
SSP2ADD = 0x13; // Operate at 400KHz (32MHz) |
SSP2STATbits.SMP = 1; // Disable Slew Rate Control |
} else if (speed == 0x02) { |
SSP2ADD = 0x07; // Operate at 1Mhz (32Mhz) |
SSP2STATbits.SMP = 1; // Disable Slew Rate Control |
} else { |
SSP2ADD = 0x4F; // Operate at 100KHz (32MHz) |
SSP2STATbits.SMP = 0; // Enable Slew Rate Control |
} |
SSP2STATbits.SMP = 1; // Disable Slew Rate Control |
SSP2CON1bits.SSPEN = 1; // Enable MSSP2 Module |
} |
/PIC Stuff/PICX_16F1829_Controller/I2C2.h |
---|
4,8 → 4,9 |
#define MAXI2C2BUF 32 |
// I2C Operating Speed |
#define I2C_400KHZ 0x0 |
#define I2C_100KHZ 0x1 |
#define I2C_100KHZ 0x0 |
#define I2C_400KHZ 0x1 |
#define I2C_1MHZ 0x2 |
// Operating State |
#define I2C_IDLE 0x1 |
/PIC Stuff/PICX_16F1829_Controller/INTERRUPTS.c |
---|
57,14 → 57,14 |
return; |
} |
// Check to see if we have an IO interrupt |
if (INTCONbits.IOCIF) { |
// Call the handler |
IO_Interrupt(); |
// // Check to see if we have an IO interrupt |
// if (INTCONbits.IOCIF) { |
// // Call the handler |
// IO_Interrupt(); |
// |
// return; |
// } |
return; |
} |
// // Check to see if we have an interrupt on USART1 RX |
// if (PIR1bits.RC1IF) { |
// // Call the interrupt handler |
/PIC Stuff/PICX_16F1829_Controller/MCP23009.c |
---|
12,7 → 12,8 |
buffer[0] = 0x00; // Starting register address |
buffer[1] = 0xFF; // IODIR, Set all pins as inputs |
buffer[2] = 0xFF; // IPOL, Reported values are inverted |
buffer[3] = 0xFF; // GPINTEN, Enable interrupt-on-change |
// buffer[3] = 0xFF; // GPINTEN, Enable interrupt-on-change |
buffer[3] = 0x00; // GPINTEN, Disable interrupt-on-change |
buffer[4] = 0x00; // DEFVAL, IOC default values |
buffer[5] = 0x00; // INTCON, IOC compare to previous value |
buffer[6] = 0x00; // IOCON, Incrementing address, active-low interrupt cleared on GPIO read |
/PIC Stuff/PICX_16F1829_Controller/defines.h |
---|
59,6 → 59,7 |
#define CMD_QUERY_BTN 0x0A |
#define CMD_SET_LEDS 0x0B |
#define CMD_RESET 0x0C |
#define CMD_ACTIVE 0x0D |
#define OP_STATE_IDLE 0x10 |
#define OP_STATE_ACTIVE 0x20 |
111,6 → 112,7 |
void Reset_Board(uint8_t next_state); |
uint8_t Get_Last_Reset(void); |
void Check_I2C(void); |
void Idle_Animation(void); |
#endif /* DEFINES_H */ |
/PIC Stuff/PICX_16F1829_Controller/funclist |
---|
1,36 → 1,34 |
_I2C2_Interrupt_Master: CODE, 34 0 706 |
_Get_Last_Reset: CODE, 2221 0 43 |
_IO_IOC_Enable: CODE, 6042 0 6 |
_I2C1_Init: CODE, 2771 0 91 |
_I2C2_Interrupt_Master: CODE, 27 0 706 |
_Get_Last_Reset: CODE, 6101 0 43 |
_I2C1_Init: CODE, 2680 0 91 |
_I2C1_Interrupt_Slave: CODE, 3275 0 397 |
_I2C1_Read_Buffer: CODE, 2619 0 73 |
_I2C2_Init: CODE, 2862 0 91 |
_Check_I2C: CODE, 1958 0 88 |
_I2C1_Read_Buffer: CODE, 2440 0 78 |
_I2C2_Init: CODE, 2771 0 91 |
_I2C2_Interrupt_Slave: CODE, 3672 0 424 |
_I2C2_Read_Buffer: CODE, 2479 0 70 |
_IO_Interrupt: CODE, 2048 0 4 |
_main: CODE, 3064 0 211 |
_Interrupt_Enable: CODE, 6039 0 3 |
_I2C2_Master_Restart: CODE, 2692 0 79 |
i1_Reset_Board: CODE, 6054 0 8 |
_InterruptHandler: CODE, 4 0 28 |
_Read_Address: CODE, 6079 0 15 |
_I2C1_Process_Receive: CODE, 2123 0 30 |
_Interrupt_Init: CODE, 2047 0 1 |
__initialization: CODE, 2264 0 40 |
_MCP23009_Init: CODE, 2307 0 49 |
_I2C2_Process_Receive: CODE, 6036 0 3 |
_TLC59116_Init: CODE, 2549 0 70 |
_I2C2_Configure_Master: CODE, 2153 0 34 |
_I2C1_Interrupt_Handler: CODE, 6094 0 24 |
_MCP23009_Query: CODE, 2187 0 34 |
_IO_Init: CODE, 2068 0 26 |
_I2C2_Master_Send: CODE, 1958 0 83 |
_I2C1_Configure_Slave: CODE, 2094 0 29 |
_I2C2_Interrupt_Handler: CODE, 6118 0 26 |
_TLC59116_Write_All: CODE, 2953 0 111 |
_Reset_Board: CODE, 6070 0 9 |
_I2C1_Get_Status: CODE, 2356 0 61 |
_I2C1_Interrupt_Master: CODE, 740 0 663 |
_I2C2_Get_Status: CODE, 2417 0 62 |
_Idle_Animation: CODE, 1403 0 555 |
Total: 4159 |
_I2C2_Read_Buffer: CODE, 2362 0 78 |
_main: CODE, 3033 0 242 |
_Interrupt_Enable: CODE, 5870 0 3 |
_I2C2_Master_Restart: CODE, 2518 0 79 |
_InterruptHandler: CODE, 4 0 21 |
_Read_Address: CODE, 5894 0 15 |
_I2C1_Process_Receive: CODE, 2048 0 30 |
_Interrupt_Init: CODE, 2046 0 1 |
__initialization: CODE, 6009 0 23 |
_MCP23009_Init: CODE, 2123 0 46 |
_I2C2_Process_Receive: CODE, 5867 0 3 |
_TLC59116_Init: CODE, 2292 0 70 |
_I2C2_Configure_Master: CODE, 2078 0 45 |
_I2C1_Interrupt_Handler: CODE, 5909 0 24 |
_MCP23009_Query: CODE, 6064 0 37 |
_IO_Init: CODE, 5983 0 26 |
_I2C2_Master_Send: CODE, 2597 0 83 |
_I2C1_Configure_Slave: CODE, 6035 0 29 |
_I2C2_Interrupt_Handler: CODE, 5957 0 26 |
_TLC59116_Write_All: CODE, 2862 0 171 |
_Reset_Board: CODE, 5885 0 9 |
_I2C1_Get_Status: CODE, 2169 0 61 |
_I2C1_Interrupt_Master: CODE, 733 0 663 |
_I2C2_Get_Status: CODE, 2230 0 62 |
_Idle_Animation: CODE, 1396 0 562 |
Total: 4327 |
/PIC Stuff/PICX_16F1829_Controller/l.obj |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
/PIC Stuff/PICX_16F1829_Controller/main.c |
---|
75,6 → 75,7 |
} |
BTN_STATUS btns; |
LED_VALUES leds = {0x00}; |
int main(void) { |
uint8_t buffer[32]; |
104,7 → 105,7 |
i2c_slave_addr = Read_Address(); |
// Delay a bit to allow I2C lines to stabilize |
__delay_ms(1); |
__delay_ms(10); |
// Initialize I2C1 in slave mode |
I2C1_DATA i2c1_data; |
114,7 → 115,7 |
// Initialize I2C2 in master mode |
I2C2_DATA i2c2_data; |
I2C2_Init(&i2c2_data); |
I2C2_Configure_Master(I2C_400KHZ); |
I2C2_Configure_Master(I2C_1MHZ); |
// Initialize interrupts |
Interrupt_Init(); |
123,19 → 124,14 |
MCP23009_Init(&btns); |
MCP23009_Query(); |
LED_VALUES leds = {0x00}; |
TLC59116_Init(); |
// TLC59116_Write_All(&leds); |
if (op_state == OP_STATE_IDLE) { |
IO_IOC_Enable(); |
// IO_IOC_Enable(); |
Idle_Animation(); |
} else if (op_state == OP_STATE_ACTIVE) { |
while (1) { |
__delay_ms(1); |
// Read value of buttons |
MCP23009_Query(); |
// Check if an I2C message was received |
result = I2C1_Get_Status(); |
if (result) { |
142,6 → 138,8 |
length = I2C1_Read_Buffer(buffer); |
if (length == 1 && buffer[0] == CMD_RESET) { |
Reset_Board(OP_STATE_IDLE); |
} else if (length == 1 && buffer[0] == CMD_ACTIVE) { |
Reset_Board(OP_STATE_ACTIVE); |
} else if (length == 17 && buffer[0] == CMD_SET_LEDS) { |
for (i = 0; i < 16; i++) { |
leds.w[i] = buffer[i+1]; |
149,10 → 147,38 |
TLC59116_Write_All(&leds); |
} |
} |
I2C2_Master_Restart(MCP23009_ADDR, MCP23009_GPIOA, 1); |
do { |
result = I2C2_Get_Status(); |
} while (!result); |
length = I2C2_Read_Buffer(buffer); |
btns.w = buffer[0]; |
} |
} |
} |
void Check_I2C(void) { |
uint8_t buffer[32]; |
uint8_t result, length, i; |
// Check if an I2C message was received |
result = I2C1_Get_Status(); |
if (result) { |
length = I2C1_Read_Buffer(buffer); |
if (length == 1 && buffer[0] == CMD_RESET) { |
Reset_Board(OP_STATE_IDLE); |
} else if (length == 1 && buffer[0] == CMD_ACTIVE) { |
Reset_Board(OP_STATE_ACTIVE); |
} else if (length == 17 && buffer[0] == CMD_SET_LEDS) { |
for (i = 0; i < 16; i++) { |
leds.w[i] = buffer[i + 1]; |
} |
TLC59116_Write_All(&leds); |
} |
} |
} |
void Idle_Animation(void) { |
LED_VALUES leds = {0}; |
uint8_t led_direction_bar[8] = {1,0,0,0,0,0,0,0}; |
168,6 → 194,9 |
while (1) { |
// Check to see if a new message was received |
Check_I2C(); |
// Update the LEDs in the middle section |
for (i = 0; i < 8; i++) { |
// Change the LED brightness depending on its direction |
240,5 → 269,4 |
// Delay a bit to slow down the animation |
__delay_ms(1); |
} |
} |
/PIC Stuff/PICX_16F1829_Controller/nbproject/Makefile-genesis.properties |
---|
1,5 → 1,5 |
# |
#Thu Mar 13 23:42:40 EDT 2014 |
#Mon Mar 17 00:03:41 EDT 2014 |
default.languagetoolchain.dir=C\:\\Program Files (x86)\\Microchip\\xc8\\v1.20\\bin |
com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=1f98a0eed69cb2a45c12981fa9470927 |
default.languagetoolchain.version=1.20 |