System Timers Module
This design forms the core of the syncronization for many AVR projects.
It provides a uniform way to manage multiple processes that run simultainiously.

The module uses Timer0 and CTC function to generate 1ms and 10ms TIC flags. There are four of each flag, but this is easily changed and other levels of granularity can be added.

A process that uses a TIC flag resets it (consumes it). A process can then generate its own timing using a counter that's based on the granularity of the TIC flag.

Psudeo Code Example: Simple 1 second timer
Main()
  call tic_init           ; set up Timer0 control bits.
  enable interrupts
  call Initalize_1_Second_Timer   ; set up delay counter.
  loop:
  call Timer_Service
  // Do other stuff
  jump back to loop

Initialize_1_Second_Timer()
  Count_Down = 100     ; set for 10ms * 100 = 1 second
  return

Timer_Service() ;Called continously from service loop in main()
  If Time_TIC = 1       ;Time_TIC is one of the four tic_10ms flags
    clear Time_TIC to 0
    decrement Count_Down
    if Count_Down = 0
      Reset Count_Down to 100
      .. Do some thing that needs to be done each second ..
  return

Code with example service

sys_timers.asm

main.asm

led_switch.asm