#include <stdint.h>
#include <xc.h>
#include "main.h"
int main()
{
// Initialize the LED. This symbol is defined in system_config.h
LED_TRIS = 0;
/* Initialize Timer 1
* Each configuration sets the MCU's oscillator to 32MHz (see the respective
* "system.c" for configuration bits). For the LED to blink
* at a rate of 1Hz, it must be toggled at 2Hz.
*
* Calculation:
* Fcy = Fosc / 2 = 16E6 [Hz]
* T1CONbits.TCKPS = 3 divides the input clock by 256.
* PR1 = Fcy[Hz] / 256 / 2[Hz] = 0x7A12;
*/
_T1IF = 0;
_T1IE = 0;
TMR1 = 0x0000;
PR1 = 0x7A12;
T1CONbits.TCKPS = 3;
T1CONbits.TON = 1;
enum
{
IDLE, BLINK_LED // Add other states here...
} demoState;
while (1)
{
switch (demoState)
{
case IDLE:
if (_T1IF == 1)
{
_T1IF = 0;
demoState = BLINK_LED;
}
// Add other idle tasks here...
break;
case BLINK_LED:
LED ^= 1; // Toggle the LED
demoState = IDLE;
break;
// Add other case states here...
default:
demoState = IDLE;
break;
}
}
return 0;
}
/*******************************************************************************
End of File
*/