This program uses twelve inputs to trigger the individual numbers one through twelve. The inputs used are P1.0 - P1.3, P2.0 - P2.3, and P6.0 - P6.3. It also demonstrates how the outputs can be configured to turn LEDs on and off. The LED outputs are on pins P3.0 - P3.3.
If you have an Interface Board plugged into the Fox Board then the buttons on Ports P1, P2, and P6 can be used to trigger the inputs, and the LEDs connected to P3 will demonstrate the output function.
This program works on its own, but it's also designed to work as an Arduino example. This program can be loaded onto a Project Board that is then plugged into the Arduino shield. The sample files contain a separate program file (arduino_counting_to_twelve.ino) that is loaded into the Arduinio.
Download the program files: counting_to_twelve.zip
HOW THE PROGRAM WORKS
In the [device] section, we declare the SNC21120 device. This is the smallest devices that gives us access to all 16 I/O pins.
In the [key] section, we set the number of direct inputs to 16. We are only use 12 pins as inputs, but some of these inputs are on port P6, so we need to declare 16. Ports P1, P2, and P6 will be used as inputs.
In the [input_states] section, we define two input states. One is "locked_out" where all I/O pins are set to "x". This means that when the "locked_out" input state is set, all input pins will be ignored. The other state is called "enabled" where a trigger on an input pin will jump the program to corresponding label in the program, but1, but2, but3, etc.
In the [output_states] section, we define an ON state and an OFF state for each LED. For example, in the program when we set the output state to p30_on, this outputs a high voltage on pin P3.0 and the LED turns on. When we set the output state to P30_off, this outputs a low voltage on pin P3.0 and the LED turns off.
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 next line "ppdac" tells the chip that we want to use the PWM audio output. The freq=12k command sets the sample playback rate of the audio to 12 kHz. 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.
but1: This label is called any time the button connected to P1.0 is pressed. When this label is called the audio file one.wav is played. After this file plays, the program stops and the chip goes into low power mode (end command).
but2: This label is called any time the button connected to P1.1 is pressed. When this label is called the audio file two.wav is played. After this file plays, the program stops and the chip goes into low power mode (end command).
but3: - but8: Same functions as described above.
but9: This label is called any time the button connected to P6.0 is pressed. When this label is called the P30_on output state is set, which turns on the LED connected to pin P3.0. Then the audio file nine.wav is played. After this file plays, the P30_off output state is set, which turns off the LED connected to pin P3.0. The end command is called which stops the program and puts the chip into low power mode.
but10: - but12: Same functions as described for but9:.