3,7 → 3,7 |
|
// CONFIG1 |
#pragma config FOSC = INTOSC // Oscillator Selection (INTOSC oscillator: I/O function on CLKIN pin) |
#pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled) |
#pragma config WDTE = ON // Watchdog Timer Enable (WDT enabled) |
#pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled) |
#pragma config MCLRE = OFF // MCLR Pin Function Select (MCLR/VPP pin function is digital input) |
#pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled) |
26,6 → 26,8 |
#include "base_I2C.h" |
|
void Pins_Init(void) { |
|
|
// Set all pins to digital I/O |
ANSELA = 0x0; |
ANSELC = 0x0; |
78,6 → 80,9 |
LED_4_LAT = leds->LED_4; |
} |
|
// TODO: Set watchdog timer to reset device if no I2C messages are received every x seconds |
// TODO: Use a timer to manually PWM the LEDs |
|
int main(void) { |
uint8_t buffer[32]; |
uint8_t result, length; |
87,6 → 92,10 |
OSCCONbits.IRCF = 0xE; // Base frequency @ 8MHz |
OSCCONbits.SCS = 0b00; // System clock determined by config bits |
|
// Set watchdog timer to reset device every 1s |
// CLRWDT is issued upon receiving data over I2C |
WDTCON = 0x0A; |
|
// Initialize I/O |
Pins_Init(); |
|
104,6 → 113,7 |
do { |
result = I2C_Get_Status(); |
} while (!result); |
CLRWDT(); |
length = I2C_Read_Buffer(buffer); |
if (length == 2 && buffer[0] == CMD_SET_LEDS) { |
LED_STATUS leds; |