EDU Demo Code: Real-Time Clock Using a Timer

Using the template code I wrote earlier, I’ve written a demo application that displays the elapsed time to the console window. From the description in the code:

This demonstrates the use of a timer and associated interrupt. In this example we’ll setup a timer to generate an interrupt every millisecond (= 1000Hz rate). In response to this interrupt, the microcontroller will execute a specific piece of code called an interrupt handler (see user_routines_fast.c). This interrupt handler will simply increment the global variables “msClock” and “Clock”. High-level user code can then access these variables to create sophisticated state machines and highly accurate sequencers. We’ll just keep the time.

The code can be found here.

Because I found MPLAB 6.3 so buggy, I updated to 6.4 (found here)](http://www.microchip.com/1010/pline/tools/picmicro/devenv/mplabi/mplab6/index.htm) which isn’t compatible with the 6.3 project file format. Consequently, you’ll need to update to 6.4 or create a new project with the project wizard if you want to re-build the code. Include all files in the .zip except ifi_library.lib. If that’s too much hassle, I’ve also included the .hex file which IFI_Loader can use.

-Kevin

I’ve updated the clock code to fix a minor timing accuracy bug. By request, I’ve created a version that includes tenths of seconds too. I’ve also converted the project files to version 6.30, making it compatible with the version of MPLAB that IFI distributes on the S/W tools CD. Enjoy. The files can be found here: http://kevin.org/frc.

-Kevin