/*******************************************************************
 * Processor:       PIC18F4520
 * Compiler:        MPLAB C18
 *
 * This file does the following....
 *
 * Author (Your name here)
 ********************************************************************/

/** Header Files ***************************************************/
#include <p18f4520.h>
#include <timers.h>

/** Configuration Bits *********************************************/
#pragma config OSC = INTIO67
#pragma config WDT = OFF
#pragma config LVP = OFF
#pragma config BOREN = OFF
#pragma config XINST = OFF

/*******************************************************************
 * Function:        void main(void)
 ********************************************************************/
#pragma code

void main(void) {
    // Run the clock at 500 kHz
    OSCCONbits.IRCF2 = 0;
    OSCCONbits.IRCF1 = 1;
    OSCCONbits.IRCF0 = 1;

    // Pin IO Setup
    ADCON1 = 0x0F;
    TRISC = 0x00;
    PORTC = 0x00;

    // Setup the time with a 1:32 prescaler
    OpenTimer0(TIMER_INT_OFF & T0_16BIT & T0_SOURCE_INT & T0_PS_1_32);

    while (1) {
        PORTC = 0x01;
        WriteTimer0(0x0000);
        // TODO: Make a 0.5 second delay
        while (ReadTimer0() < 1) {
            // Could do stuff while waiting for timer, but not needed.
        }

        PORTC = 0x02;
        WriteTimer0(0x0000);
        // TODO: Make a 1 second delay
        while (ReadTimer0() < 1);

        PORTC = 0x04;
        WriteTimer0(0x0000);
        // TODO: Make a 5 second delay
        while (ReadTimer0() < 1);

        PORTC = 0x08;
        WriteTimer0(0x0000);
        // TODO: Make a 20 second delay
        while (ReadTimer0() < 1);
        WriteTimer0(0x0000);
        while (ReadTimer0() < 1);
    }
}