Countdown Timer
 
      Main           Pinout & Example           Code           Timer Applications      Other Projects  

 
The source code of the timer and a set of HEX files compiled for PIC16F690 are available below. You can either download the assembly code, adjust it to your requirements, and compile it yourself, or you can program your microcontroller with one of the precompiled HEX files. The difference between the HEX files is in the time unit that is being counted (seconds, minutes, or hours), and if Pin 10 is configured as Inv.DIG or is unused.


Countdown Timerv.1.1, 2009/09/24
Complete MPLab Projecttimer.zip
Assembly code onlytimer.asm
Precompiled HEX file - counting secondstimer_SECONDS.HEX
Precompiled HEX file - counting minutestimer_MINUTES.HEX
Precompiled HEX file - counting hourstimer_HOURS.HEX
Precompiled HEX file - seconds; Pin 10 used for LED controltimer_SECONDS_INVDIG.HEX
Precompiled HEX file - minutes; Pin 10 used for LED controltimer_MINUTES_INVDIG.HEX
Precompiled HEX file - hours; Pin 10 used for LED controltimer_HOURS_INVDIG.HEX



Setup Parameters
There are several things you can adjust in timer.asm to satisfy your requirements:

Changing the value of TIMER_DIVIDER will let you set the timer's units. The value you enter is the number of seconds per counting unit.

You can set pin 10 as an output that will always mirror the state of the DIG pin by uncommenting the #define RB7_LED_CONTROL line. If you do so, you can directly connect the DIG and Inv.DIG outputs to the LED indicator anodes for the two digits and will not have to use external components to do the multiplexing. See the example application for details.

By default, when the countdown is finished, the timer will show a blinking 00 - if you want to start it again, you will have to dial the time and press SET (in other words, this is similar to how microwave oven timers work). For some applications, however, you may often run the timer for the same period several times in a row. If this is what you need, uncomment the #define REMEMBER_INITIAL_VALUE line. This way, at the end of the countdown the timer will revert to the initial value and all you need to do to start it again will be to press SET.

When the timer is powered up it will be set to 00 and you will have to dial the desired time before starting it. You can choose the default value on power-up by setting TIMER_DEFAULT_VALUE to anything from 0 to 99. Note that you should use packed decimal - a hex number where the two digits correspond to the two decimal digits of the number you need. For example, if you want the timer to start from 15, set the value to 15 and not 0f.

Finally, if you are planning to use an oscillator with different frequency, changing TMR_LO and TMR_HI will let you adjust the timer counting speed. If you are using a crystal with very different frequency, you might have also to adjust the values of BTN_REPEAT_START and BTN_REPEAT_REINIT in order to get the buttons repeat time and rate convenient.


      Main           Pinout & Example           Code           Timer Applications      Other Projects