#include "Timers.h"

sbit LED_1 = P2^6;
sbit LED_2 = P2^7;

void main(void)
{
    // Initialise the Timers module.
    timers_init();

    // Round Robin task management, reiterative execution loop.
    while(1)
    {
        // Flash an LED output continuoulsy at 0.5Hz, 50% duty cycle.
        if (timers_is_expired_timer(0))
        {
            // Invert LED output.
            LED_1 = ~LED_1;

            // Set timer 0 to expire in 1000ms.
            timers_restart_timer(0, 1000);
        }

        // Flash another LED continuously at 1.3Hz, 33% duty cycle.
        if (timers_is_expired_timer(1))
        {
            if (LED_2)
            {
                // Turn LED on.
                LED_2 = 0;

                // Set timer 1 to expire in 250ms.
                timers_restart_timer(1, 250);
            }
            else
            {
                // Turn LED off.
                LED_2 = 1;

                // Set timer 1 to expire in 500ms.
                timers_restart_timer(1, 500);
            }
        }

        // Additional Round Robin task managed tasks.
    }
}