/**
 * Interrupts are used to read buttons and increment / decrement the counter on the display.
 */
#include <main.h>
/**
 * Set the length of the list to loop up till.
 * In practice this sets the maximum number the 8 LEDs can represent in binary to 128
 */
#define LIST_LEN 128

unsigned int counter = 0;

#INT_RTCC
void RTCC_isr(void)
{
  /* If the first button is pressed, increment the counter */
  if (input(button_1) == 1){counter++;}
  /* If the second button is pressed, decrement the counter */
  else if (input(button_2) == 1){counter--;}
  if ((counter > LIST_LEN - 1) | (counter < 0)) {counter = 0;}
  output_b(counter);
  clear_interrupt(int_rtcc);
}

void main()
{
  /**
   * Enable the use of interrupts so the execution
   * of the program is non-blocking.
   */
  setup_timer_0(RTCC_INTERNAL | RTCC_DIV_256 | RTCC_8_BIT);
  enable_interrupts(INT_RTCC);
  enable_interrupts(GLOBAL);

  while (TRUE)
  {
  }
}