Pages created and updated by Terry Sturtevant Date Posted: January 31, 2018

CP316: Microprocessor Systems and Interfacing

Timers and Counters


Microcontroller timers can typically operate as a timer or a counter. A timer outputs a signal after a specified interval of time. A counter counts the number of pulses (by counting rising or falling edges) for a particular input signal. The timing signal will be monitored using an oscilloscope driven from Port C.



  1. Modify one of your LED programs from the last lab (new project) to turn the left LED on/off every second, i.e. on for one second, off for one second. (Hint: You may find timer0_delay.asm helpful. It identifies three sections which you have to modify.) Structure the program so that you have one subroutine that measures 1/100 of a second based on timer0. You should have another subroutine that calls the .01 second routine the appropriate number of times to get the required timing.

  2. Check GROUND and VDD pins on the header to make absolutely sure you understand the header pin numbering. Verify your timing for the previous program using the oscilloscope.

    Demonstration - demonstrate and explain the operation of your program.

  3. If you wanted to change the timing of the above program to turn the left LED on/off every two seconds, there are three different ways to change the timing.
    • You could change the counting routine that calls the timing routine.
    • You could change the timing routine to run twice as long.
    • You could reconfigure the timer to run twice as slow

    Implement the three techniques. Note the changes that have to be made to the base program in your lab notebook. Verify the timing for each implementation using the oscilloscope. Comment on the respective accuracy of each technique.

    Demonstration - demonstrate the operation of all three techniques.

  4. Modify your program from question 1 of this lab (new project) to turn the left LED on/off every 1.5 seconds based on timer1. (Hint: You may find timer1_delay.asm helpful, or you may prefer to adapt your existing timer0 program.) Verify your timing using the oscilloscope.

    Demonstration - demonstrate and explain the operation of your program.

  5. Although RC0, RC3, and RC5 are connected as inputs to the DAC, the DAC does not drive any of these pins. These pins can be used by expansion circuitry and, at worst, the only consequence would be erratic output voltages appearing on the DAC outputs. Use the DAC datasheet, MAX522, to determine the function of the CS pin on the DAC.

  6. Setup the signal generator to produce a 0-5V square wave and verify the signal using the scope.
    Demonstration - demonstrate your 0-5V signal, and demonstrate location of pin1 on the header.

    You may not proceed to next task until the lab supervisor gives his OK.

  7. Write a program to demonstrate the use of timer1 as a counter. Use the information from the previous steps to provide a suitable input signal without harming the DAC.
    (Hint: You may find counter1.asm helpful. It identifies sections which you have to modify.) Demonstration - demonstrate and explain the operation of your program.

  8. Make a macro to initiallize timer 1 and add it to your include file. How much flexability can you put into the macro compared to doing all of the configuration in your main program? Adjust your main program accordingly.
    Demonstration - demonstrate the revised code in operation.
Creative Commons License

Information on this site which is produced by Terry Sturtevant is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 Canada License.


To view pdf documents, you can download Adobe Acrobat Reader .
get Acrobat Reader
If you need to update a browser, you might try Firefox which is Get Firefox!
Since this page uses cascading style sheets for its layout, it will look best with a browser which supports the specifications as fully as possible.

If you are looking for an office package, with a word processor, spreadsheet, etc., you might try LibreOffice which is Get LibreOffice!

Go to the main page for the Department of Physics and Computer Science.

Valid XHTML 1.1

Valid CSS!

(Level AA)

Wilfrid Laurier University