CSEP567 PreLab 3: “Programming in C”

Objectives

The goal of this lab is to introduce various features and modules of the ATmega16 while introducing how to program the microcontroller using C.

Reading / Helpful Hints

Resources

Tasks

  1. Read the link about bypass capacitors.
  2. Implement a counter in C that counts at 1Hz from '00' to '59' using Timer 1's output compare interrupt for timing. Documentation for the avr-gcc compiler is available at http://www.nongnu.org/avr-libc/user-manual/index.html   From that link, go to the modules section and then the Interrupts and Signals entry. Remember, when writing the interrupt handler routine, you'll want to minimize the amount of code in it. Interrupt handlers are meant to be very fast, and do only the work that is critical to do right at that instant. There is no way that anyone will be able to notice if your LEDs update even a few milliseconds late, so the LED update code should not be in the handler.
  3. Implement the stop-start button (pin 18) so that pressing the button will cause the counter to toggle between counting or halting. The left (tens digit) decimal point should indicate whether the counter is running by being on when the counter is running and off when the counter is stopped. We have provided some sample code for debouncing a button. You should setup the timer to sample the button at 5ms intervals. Remember that if you push the button and hold it for a long time it should only register as a single push.
  4. Implement the up-down button (pin 19) so pressing the button will change the direction of counting. The decimal point on the right (ones digit) should be on when counting up and be off when counting down. Note that even when the counter is stopped, the system should still process an up-down button press by immediately updating the direction and decimal point state. \

Code

Question

Question 1: What is the purpose of the bypass capacitors? Why might they be useful for this lab?

Question 2: When and why should you use the type qualifier "volatile"? (Hint: it related to the optimization of a compiler)

Turn-in

Please complete the prelab individually. Please turn-in your commented C code along with the answers to the two questions at the beginning of next weeks lab.