/PIC Stuff/PICX_16F1829_Controller/MCP23009.c |
---|
22,7 → 22,7 |
} while (!result); |
} |
uint8_t MCP23009_Query(void) { |
void MCP23009_Query(BTN_STATUS *status) { |
uint8_t buffer[2] = {MCP23009_GPIOA}; |
I2C2_Master_Send(MCP23009_ADDR, 1, buffer); |
38,5 → 38,5 |
} while (!result); |
I2C2_Read_Buffer(buffer); |
return buffer[0]; |
status->w = buffer[0]; |
} |
/PIC Stuff/PICX_16F1829_Controller/MCP23009.h |
---|
16,7 → 16,7 |
#define MCP23009_OLATA 0x0A |
void MCP23009_Init(void); |
uint8_t MCP23009_Query(void); |
void MCP23009_Query(BTN_STATUS *status); |
#endif /* MCP23009_H */ |
/PIC Stuff/PICX_16F1829_Controller/TLC59116.c |
---|
38,40 → 38,40 |
} while (!result); |
} |
void TLC59116_Write(uint8_t led, uint8_t brightness) { |
uint8_t buffer[2]; |
//void TLC59116_Write(uint8_t led, uint8_t brightness) { |
// uint8_t buffer[2]; |
// |
// buffer[0] = led + 0x02; // Register Select |
// buffer[1] = brightness; |
// |
// I2C2_Master_Send(TLC59116_ADDR, 2, buffer); |
// uint8_t result; |
// do { |
// result = I2C2_Get_Status(); |
// } while (!result); |
//} |
buffer[0] = led + 0x02; // Register Select |
buffer[1] = brightness; |
I2C2_Master_Send(TLC59116_ADDR, 2, buffer); |
uint8_t result; |
do { |
result = I2C2_Get_Status(); |
} while (!result); |
} |
void TLC59116_Write_All(uint8_t *values) { |
void TLC59116_Write_All(LED_VALUES *values) { |
uint8_t buffer[17]; |
uint8_t i; |
buffer[0] = buffer[0] = TLC59116_AUTO_INCR_ALL | TLC59116_REG_PWM0; // Register Select |
buffer[1] = values[0]; |
buffer[2] = values[1]; |
buffer[3] = values[2]; |
buffer[4] = values[3]; |
buffer[5] = values[4]; |
buffer[6] = values[5]; |
buffer[7] = values[6]; |
buffer[8] = values[7]; |
buffer[9] = values[8]; |
buffer[10] = values[9]; |
buffer[11] = values[10]; |
buffer[12] = values[11]; |
buffer[13] = values[12]; |
buffer[14] = values[13]; |
buffer[15] = values[14]; |
buffer[16] = values[15]; |
buffer[0] = TLC59116_AUTO_INCR_ALL | TLC59116_REG_PWM0; // Register Select |
buffer[1] = values->w[0]; |
buffer[2] = values->w[1]; |
buffer[3] = values->w[2]; |
buffer[4] = values->w[3]; |
buffer[5] = values->w[4]; |
buffer[6] = values->w[5]; |
buffer[7] = values->w[6]; |
buffer[8] = values->w[7]; |
buffer[9] = values->w[8]; |
buffer[10] = values->w[9]; |
buffer[11] = values->w[10]; |
buffer[12] = values->w[11]; |
buffer[13] = values->w[12]; |
buffer[14] = values->w[13]; |
buffer[15] = values->w[14]; |
buffer[16] = values->w[15]; |
I2C2_Master_Send(TLC59116_ADDR, 17, buffer); |
uint8_t result; |
/PIC Stuff/PICX_16F1829_Controller/TLC59116.h |
---|
49,8 → 49,7 |
#define TLC59116_REG_EFLAG2 0x1E |
void TLC59116_Init(void); |
void TLC59116_Write(uint8_t led, uint8_t brightness); |
void TLC59116_Write_All(uint8_t *values); |
void TLC59116_Write_All(LED_VALUES *values); |
void TLC59116_Write_BC(uint8_t brightness); |
#endif /* TLC59116_H */ |
/PIC Stuff/PICX_16F1829_Controller/defines.h |
---|
63,12 → 63,12 |
struct { |
unsigned BTN_L_N :1; |
unsigned BTN_L_E :1; |
unsigned BTN_L_S :1; |
unsigned BTN_L_W :1; |
unsigned BTN_R_E :1; |
unsigned BTN_R_N :1; |
unsigned BTN_R_E :1; |
unsigned BTN_R_S :1; |
unsigned BTN_R_W :1; |
unsigned BTN_L_S :1; |
unsigned BTN_L_W :1; |
}; |
uint8_t w; |
} BTN_STATUS; |
75,28 → 75,27 |
typedef union { |
struct { |
unsigned LED_A :1; |
unsigned LED_B :1; |
unsigned LED_C :1; |
unsigned LED_D :1; |
unsigned LED_1 :1; |
unsigned LED_2 :1; |
unsigned LED_3 :1; |
unsigned LED_4 :1; |
unsigned LED_5 :1; |
unsigned LED_6 :1; |
unsigned LED_7 :1; |
unsigned LED_8 :1; |
unsigned LED_N :1; |
unsigned LED_E :1; |
unsigned LED_S :1; |
unsigned LED_W :1; |
}; |
uint8_t w[2]; |
} LED_STATUS; |
uint8_t LED_0; |
uint8_t LED_1; |
uint8_t LED_2; |
uint8_t LED_3; |
uint8_t LED_4; |
uint8_t LED_5; |
uint8_t LED_6; |
uint8_t LED_7; |
uint8_t LED_N; |
uint8_t LED_W; |
uint8_t LED_E; |
uint8_t LED_S; |
uint8_t LED_A; |
uint8_t LED_B; |
uint8_t LED_C; |
uint8_t LED_D; |
} single; |
uint8_t w[16]; |
} LED_VALUES; |
void Pins_Read(BTN_STATUS *btns); |
void Leds_Write(LED_STATUS *leds); |
void Idle_Animation(void); |
#endif /* DEFINES_H */ |
/PIC Stuff/PICX_16F1829_Controller/funclist |
---|
1,28 → 1,29 |
_I2C2_Interrupt_Master: CODE, 27 0 706 |
_I2C1_Init: CODE, 3486 0 78 |
_I2C1_Interrupt_Slave: CODE, 3738 0 358 |
_I2C2_Init: CODE, 3647 0 91 |
_I2C2_Interrupt_Slave: CODE, 1332 0 424 |
_I2C2_Read_Buffer: CODE, 3416 0 70 |
_main: CODE, 1756 0 113 |
_Interrupt_Enable: CODE, 2043 0 3 |
_I2C1_Init: CODE, 2886 0 91 |
_I2C1_Interrupt_Slave: CODE, 3275 0 397 |
_I2C2_Init: CODE, 1955 0 91 |
_I2C2_Interrupt_Slave: CODE, 3672 0 424 |
_I2C2_Read_Buffer: CODE, 2733 0 70 |
_main: CODE, 2977 0 127 |
_Interrupt_Enable: CODE, 2169 0 3 |
_InterruptHandler: CODE, 4 0 21 |
_Read_Address: CODE, 3239 0 51 |
_I2C1_Process_Receive: CODE, 2961 0 10 |
_Interrupt_Init: CODE, 2046 0 1 |
__initialization: CODE, 2981 0 11 |
_MCP23009_Init: CODE, 3149 0 41 |
_I2C2_Process_Receive: CODE, 2971 0 10 |
_TLC59116_Init: CODE, 3346 0 70 |
_I2C2_Configure_Master: CODE, 3115 0 34 |
_I2C1_Interrupt_Handler: CODE, 3013 0 22 |
_MCP23009_Query: CODE, 3190 0 49 |
_I2C2_Master_Send: CODE, 3564 0 83 |
_I2C1_Configure_Slave: CODE, 3087 0 28 |
_I2C2_Interrupt_Handler: CODE, 3035 0 26 |
_TLC59116_Write_All: CODE, 1869 0 112 |
_I2C2_Master_Recv: CODE, 3290 0 56 |
_I2C1_Interrupt_Master: CODE, 733 0 599 |
_Pins_Init: CODE, 3061 0 26 |
_I2C2_Get_Status: CODE, 1981 0 62 |
Total: 3155 |
_Read_Address: CODE, 2438 0 51 |
_I2C1_Process_Receive: CODE, 2184 0 10 |
_Interrupt_Init: CODE, 3 0 1 |
__initialization: CODE, 2333 0 27 |
_MCP23009_Init: CODE, 2397 0 41 |
_I2C2_Process_Receive: CODE, 2194 0 10 |
_TLC59116_Init: CODE, 2663 0 70 |
_I2C2_Configure_Master: CODE, 2363 0 34 |
_I2C1_Interrupt_Handler: CODE, 2204 0 24 |
_MCP23009_Query: CODE, 2545 0 56 |
_I2C2_Master_Send: CODE, 2803 0 83 |
_I2C1_Configure_Slave: CODE, 2304 0 29 |
_I2C2_Interrupt_Handler: CODE, 2252 0 26 |
_TLC59116_Write_All: CODE, 3104 0 171 |
_I2C2_Master_Recv: CODE, 2489 0 56 |
_I2C1_Interrupt_Master: CODE, 733 0 663 |
_Pins_Init: CODE, 2278 0 26 |
_I2C2_Get_Status: CODE, 2601 0 62 |
_Idle_Animation: CODE, 1396 0 559 |
Total: 3929 |
/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 |
---|
74,16 → 74,6 |
return ret; |
} |
// Function to read button status into a data structure |
void Pins_Read(BTN_STATUS *btns) { |
} |
// Function to write led values from the data structure |
void Leds_Write(LED_STATUS *leds) { |
} |
int main(void) { |
uint8_t buffer[32]; |
uint8_t result, length; |
118,29 → 108,119 |
Interrupt_Enable(); |
TLC59116_Init(); |
MCP23009_Init(); |
uint8_t leds[16] = {0x00, 0x00, 0x00, 0x00, |
0x00, 0x00, 0x00, 0x00, |
0x10, 0x10, 0x10, 0x10, |
0x10, 0x10, 0x10, 0x10}; |
TLC59116_Write_All(leds); |
BTN_STATUS btns; |
LED_VALUES leds = {0x00, 0x00, 0x00, 0x00, |
0x00, 0x00, 0x00, 0x00, |
0x00, 0x00, 0x00, 0x00, |
0x00, 0x00, 0x00, 0x00}; |
MCP23009_Init(); |
TLC59116_Write_All(&leds); |
// Check for received data over I2C |
Idle_Animation(); |
// Check for received data over I2C1 |
while (1) { |
uint8_t btn_value = MCP23009_Query(); |
MCP23009_Query(&btns); |
uint8_t i; |
for (i = 0; i < 8; i++) { |
if ((btn_value >> i) & 0x1) { |
leds[i] = 0x00; |
if ((btns.w >> i) & 0x1) { |
leds.w[i] = 0x00; |
} else { |
leds[i] = 0x10; |
leds.w[i] = 0x20; |
} |
} |
TLC59116_Write_All(leds); |
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}; |
uint8_t led_direction_dir[8] = {1,0,0,0}; |
uint8_t led_direction_ind[8] = {1,0,0,0}; |
uint8_t led_8_high_thres = 0x80; // Max brightness of the middle section |
uint8_t led_8_next_thresh = 0x40; // Threshold to start the next LED |
uint8_t led_4_high_thres = 0x80; // Max brightness of the side sections |
uint8_t led_4_next_thresh = 0x74; // Threshold to start the next LED |
uint8_t i, next_led; |
for (i = 0; i < 16; i++) leds.w[i] = 0x00; |
while (1) { |
// Update the LEDs in the middle section |
for (i = 0; i < 8; i++) { |
// Change the LED brightness depending on its direction |
if (led_direction_bar[i] == 1) { |
leds.w[i]++; |
} else if (led_direction_bar[i] == 2) { |
leds.w[i]--; |
} |
// Change direction if peak brightness is reached |
// When the brightness reaches a middle threshold, start |
// increasing the brightness of the next LED |
if (led_direction_bar[i] == 1 && leds.w[i] == led_8_high_thres) { |
led_direction_bar[i] = 2; |
} else if (led_direction_bar[i] == 1 && leds.w[i] == led_8_next_thresh) { |
next_led = (i == 7) ? 0 : i + 1; |
led_direction_bar[next_led] = 1; |
} else if (led_direction_bar[i] == 2 && leds.w[i] == 0x00) { |
led_direction_bar[i] = 0; |
} |
} |
// Update the LEDs in the right section |
for (i = 0; i < 4; i++) { |
// Change the LED brightness depending on its direction |
if (led_direction_dir[i] == 1) { |
leds.w[i+8]++; |
} else if (led_direction_dir[i] == 2) { |
leds.w[i+8]--; |
} |
// Change direction if peak brightness is reached |
// When the brightness reaches a middle threshold, start |
// increasing the brightness of the next LED |
if (led_direction_dir[i] == 1 && leds.w[i+8] == led_4_high_thres) { |
led_direction_dir[i] = 2; |
} else if (led_direction_dir[i] == 1 && leds.w[i+8] == led_4_next_thresh) { |
next_led = (i == 3) ? 0 : i + 1; |
led_direction_dir[next_led] = 1; |
} else if (led_direction_dir[i] == 2 && leds.w[i+8] == 0x00) { |
led_direction_dir[i] = 0; |
} |
} |
// Update the LEDs in the left section |
for (i = 0; i < 4; i++) { |
// Change the LED brightness depending on its direction |
if (led_direction_ind[i] == 1) { |
leds.w[i+12]++; |
} else if (led_direction_ind[i] == 2) { |
leds.w[i+12]--; |
} |
// Change direction if peak brightness is reached |
// When the brightness reaches a middle threshold, start |
// increasing the brightness of the next LED |
if (led_direction_ind[i] == 1 && leds.w[i+12] == led_4_high_thres) { |
led_direction_ind[i] = 2; |
} else if (led_direction_ind[i] == 1 && leds.w[i+12] == led_4_next_thresh) { |
next_led = (i == 3) ? 0 : i + 1; |
led_direction_ind[next_led] = 1; |
} else if (led_direction_ind[i] == 2 && leds.w[i+12] == 0x00) { |
led_direction_ind[i] = 0; |
} |
} |
// Write the LED values to the controller |
TLC59116_Write_All(&leds); |
// Delay a bit to slow down the animation |
__delay_ms(1); |
} |
} |
} |
/PIC Stuff/PICX_16F1829_Controller/nbproject/Makefile-default.mk |
---|
74,7 → 74,7 |
.build-conf: ${BUILD_SUBPROJECTS} |
${MAKE} ${MAKE_OPTIONS} -f nbproject/Makefile-default.mk dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1829_Controller.${IMAGE_TYPE}.${OUTPUT_SUFFIX} |
MP_PROCESSOR_OPTION=16F1829 |
MP_PROCESSOR_OPTION=16LF1829 |
# ------------------------------------------------------------------------------------ |
# Rules for buildStep: compile |
ifeq ($(TYPE_IMAGE), DEBUG_RUN) |
/PIC Stuff/PICX_16F1829_Controller/nbproject/Makefile-genesis.properties |
---|
1,5 → 1,5 |
# |
#Sun Jan 26 16:29:53 EST 2014 |
#Fri Feb 28 00:28:10 EST 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 |
/PIC Stuff/PICX_16F1829_Controller/nbproject/configurations.xml |
---|
36,7 → 36,7 |
<conf name="default" type="2"> |
<toolsSet> |
<developmentServer>localhost</developmentServer> |
<targetDevice>PIC16F1829</targetDevice> |
<targetDevice>PIC16LF1829</targetDevice> |
<targetHeader></targetHeader> |
<targetPluginBoard></targetPluginBoard> |
<platformTool>PICkit3PlatformTool</platformTool> |
132,6 → 132,7 |
<property key="ToolFirmwareFilePath" |
value="Press to browse for a specific firmware version"/> |
<property key="ToolFirmwareOption.UseLatestFirmware" value="true"/> |
<property key="firmware.download.all" value="false"/> |
<property key="hwtoolclock.frcindebug" value="false"/> |
<property key="memories.aux" value="false"/> |
<property key="memories.bootflash" value="false"/> |