Sample Programs

This program fades an LED in and out continuously. If you have an Interface Board plugged into the Fox Board then LED P3.3 will fade in and out. If not, then you will need to connect an LED to pin P3.3.

Download the program files: LED_fade.zip


HOOK-UP DIAGRAM


CODE



HOW THE PROGRAM WORKS

In the [device] section, we declare the SNC21030 device. Since there in no audio in this program, we can use the smallest device.

In the [key] section, we set the number of direct inputs to 1. This program runs on its own without any input triggers, but we need always need to declare at least one input.

In the [input_states] section, we define an input state called "locked_out" and we set the P1.0 input to "x". This means that when the "locked_out" input state is set, pin P1.0 will be ignored.

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. In this program, the init path sets register X0 to zero, enables pin P3.3 for PWM output (pwmio_en4 command), and then jumps to the "fade_in" label.

fade_in: This routine begins by setting the PWM output to the value in X0. This is followed by a 10 millisecond delay. The next line compares the number stored in X0 to the constant 255. If X0 is equal to 255 then the program jumps to the "fade_out" label. If it is not equal to 255, the program continues on to the next line. The next line increments the value in X0 by 1, and then the program jumps back to the "fade_in" label.

fade_out: This routine begins by setting the PWM output to the value in X0. This is followed by a 10 millisecond delay. The next line compares the number stored in X0 to the constant 0. If X0 is equal to 0 then the program jumps to the "fade_in" label. If it is not equal to 0, the program continues on to the next line. The next line decrements the value in X0 by 1, and then the program jumps back to the "fade_out" label.

In this manner, the program executes the fade_in loop until X0 reaches 255, and executes the fade_out routine until X0 reaches 0. With each change in X0, the PWM output is set to the value in X0. The program alternates between these two routines continuously.