Here's our first real experiment, a simple egg timer. Well, egg timer, not really, you can do a lot more with it than time your boiling eggs. At least I don't suppose you want to boil your eggs for up to 99 minutes!
The object of this experiment is to show you how software timing loops work.
A software timing loop is relatively simple because it relies completely on the processor, no external hardware is necessary.
One of the major disadvantages of a software timing loop is that the processor can't do other things while carefully counting its steps.
Later experiments will teach you how to use the Z80 CTC for instance to control the timing of the software to get a much more accurate result, regardless of the work load of the processor.
You may learn other things from this program too. For starters you may learn how to work the display and keyboard of the MPF-1. And there's some BCD arithmetic in the program too. Remember that the Z80 is actually a binary number crunching machine, it requires some extra tricks to make it deal with human readable numbers.
After you load the program into memory (filename 0002) you can start it like just about any other program on the MPF-1 by typing ADDR 1 8 0 0 GO.
The display should now show E t 3.0 0, which means that the timer is set for 3.00 minutes.
You can change the time by simply entering 4 digits in a row, including any leading zeroes.
As soon as you type the first digit you'll see something like E t 1 _ _ _, which means that you can enter the other digits on the cursor lines.
Should you make a mistake simply complete the number and start again.
You may also press the DEL key to return to the previously set time.
To make this program fool proof you can't enter the seconds field above 59 or set the time to 0.00 seconds.
Study the source code to see how I did that if you like.
You can start the countdown of the egg timer (with any value ranging from 1 second to 99 minutes and 59 seconds) by simply pressing GO.
When the timer reaches 0.00 the message - S T O P - will flash while an intermittent sound will also signal the timeout of the countdown.
Pressing almost any key now will stop the noise and return you to the preset time.
While the countdown is running you can stop the timer by pressing the STEP key (please note that STEP is spelt almost the same as STOP :).
After stopping the countdown like this you can restart it again by pressing GO.
By pressing DEL after stopping the countdown somewhere midway you reset the timer back to its preset time.
This way you can easily restart the countdown from the beginning.
I deliberately kept the program rather simple.
Therefore there is some room for improvement.
Feel free to alter the program to your liking.
Here are some things which might be improved:
Here you can download the file eggtimer.zip, which contains the source listing, the actual plain hex file, a list file and an mp3 file of the program.