Sample Programs

This program plays a tick-tock sound effect for a selected period of time. At the end of the timeout period, a "times up" sound effect plays. There are three different "times up" sound effects in the program. The sound effect that plays is determined by which button was pressed to start the timer.
If you have an Interface Board plugged into the Fox Board then button P1.0, P1.1, or P1.2 can be used to start the timer. If not, then you will need to connect a button or switch to one of these inputs.

Download the program files: tick_tock_timer.zip


HOOK-UP DIAGRAM


CODE



HOW THE PROGRAM WORKS

In the [device] section, we declare the SNC21030 device. There is a total of five short sound effects in the program which don't take up much memory, so we can use the smallest device.

In the [key] section, we set the number of direct inputs to 3. One button is connected to pin P1.0, one button is connected to pin P1.1, and one button is connected to pin P1.2.

In the [input_states] section, we define two input states. One is "locked_out" and we set the P1.0, P1.1, and P1.2 inputs to "x". This means that when the "locked_out" input state is set, these three pins will be ignored. The other state is called "enabled" where a trigger on P1.0 will jump the program to the timer1 label, a trigger on P1.1 will jump the program to the timer2 label, and a trigger on P1.2 will jump the program to the timer3 label.

The [paths] section contains the various routines used in the program.

init: The "init" label always gets called first on power up and on reset. The first line in the init routine sets the input state to "locked_out". This disables the input pins. The freq=12k command sets the sample playback rate of the audio to 12 kHz. x0 is initialized to zero and will be used to count the number of seconds that have elapsed. x1 is set to 10 and represents the timeout period (the number of seconds before the timer goes off). We then set the "enabled" input state which enables the inputs so that the buttons are active. The end command stops the program and puts the chip into low power mode. Even though the chip is asleep, the inputs are active and can be used to wake up the chip and trigger the program.

timer1: This label is called any time the button connected to P1.0 is pressed. The x0 counter is set to zero and then the timer1_loop is called. When this routine is called the timer starts ticking. The x0 counter is incremented after each tick-tock. If the number of tick-tocks equals the timeout period, then the program jumps to the timeout1 label and the game_show_buzzer_12k sound effect plays. After this sound effect plays the program stops and the chip goes into low power mode (end command).

timer2: This label is called any time the button connected to P1.1 is pressed. The x0 counter is set to zero and then the timer2_loop is called. When this routine is called the timer starts ticking. The x0 counter is incremented after each tick-tock. If the number of tick-tocks equals the timeout period, then the program jumps to the timeout2 label and the bell_desk_12k sound effect plays. After this sound effect plays the program stops and the chip goes into low power mode (end command)

timer3: This label is called any time the button connected to P1.2 is pressed. The x0 counter is set to zero and then the timer3_loop is called. When this routine is called the timer starts ticking. The x0 counter is incremented after each tick-tock. If the number of tick-tocks equals the timeout period, then the program jumps to the timeout3 label and the cartoon_horn_12k sound effect plays. After this sound effect plays the program stops and the chip goes into low power mode (end command).