Now that I have got my program reading the button and displaying to the LCD I can start to think about the timer. I think (but I am not sure and so will have to test this) that a timing resolution of a 200th of a second will be adequate for my purposes. This is the same rate as I used for the LED digits. If I make the clock run faster the foreground program performance will suffer. If I make the clock run slower I will not be able to tell winners from losers.
Also, I am going to need a way of displaying a number for the time taken to press the button. If I go back to one of the LED programs I should be able to modify the display function from that. I also need a way of keeping track of time. I can update a counter in the interrupt handler (as for the stop watch) and display this in the foreground process. This is a good idea. I can't spend time in the interrupt handler driving the LCD, so I will let the foreground program take care of this. Since I want to get a feel for speeds I will make the timer count up while a button is not held down. This way I can press the button up and down as quickly as I can and see what values the counter changes by.
The requirements for this next program are:
Start interrupts running at 200Hz and arrange that on timer interrupt a counter will increment when the PORTA bit 0 is set.
Requirement |
Hint |
The program must start interrupts firing at the rate of 200 per second. |
Look at program ex48.c to find out how to start interrupts rolling. Add the code to your version of setup_hardware |
The program must add one to a counter at the rate of 200 Hz, when the button on PORTA is depressed. |
The stopwatch code implemented this kind of counter in the timer interrupt. You should look at ex48.c again for this bit. |
The program must repeatedly draw the counter on the screen. |
You will need to create a function which will display a value on the LCD panel. Again, ex48.c should be the first place you look for this. |