
Timer 1 initialisation
START
Enable timer 1 interrupts
Set timer 1 to mode 8-bit auto-reload
Load timer value 6 (i.e. count of 250 ms) into timer register
Enable microcontroller interrupts
Turn on timer 1
END
Timer 1 interrupt service routine
START
IF (int_rate*250) ms has elapsed THEN
Complement speaker output
ENDIF
END
Program Listing
The full program listing is shown in Fig. 4.6. When the program starts a
variable called count is set to 0 and the speaker is turned o. Timer 1 is then
initialized with the int_rate=2 so that interrupts are generated every 500 ms, i.e.
an output frequency of 1 kHz. The state of the push-button switch is then
checked. If the