09 – PICAXE Programming Editor Tutorial

Learn how to use the PICAXE Programming Editor by writing your first program to perform the following task: Switch the red LED on for 0.5 seconds (500 ms) and switch it off for a second (1000ms) and keep on doing that as long as the school experimenter board is switched on.



 

Open the PICAXE Programming Editor software by clicking PIXAXE Programming Editor Icon under Start<All Programs<Revolution Education<PICAXE Programming Editor program folder.

The PICAXE Programming editor will open with the options page.

Select the PICAXE-08M mode in the options form and click the ‘OK’ button.

The editor start-up with new program window already opened and you can start typing in your program in this window. Type in the following commands:

main:                                                        ;This is a label called main
           symbol RED_LED = 0                ;Rename port 0 to RED_LED
           high RED_LED                            ;Switch on the red LED

What do you see in the editor window? The editor keeps record of the Variables, Constants and Labels as can be seen in the right window.

Let’s program this piece of code into the experimenter board and try it out. Plug the cable into the experimenter board and the serial port on your computer. Switch on the experimenter board and click the program button to program the microcontroller, and click the OK button when it is uploaded.

The red LED is switched on and it stays switched on the whole time because that is exactly what the program tells it to do. The program start at the main label and then it renames port 0 so that we can understand it better in the program. At the next line of code the red LED is switched on and then the program finishes leaving the red LED switched on. 

Add the following line of code and program the microcontroller again.
         low RED_LED                                    ;Switch off the red LED

This time the red LED doesn’t come on at all, why is that? Well the red LED is switched on and then it is switched off again but it happen so fast that the red LED is switched off before it can even light up. To rectify that we need to pause the program after the red LED is switched on so that we can see that. 

 Add the following line of code just after the high command and program the microcontroller again.
         pause 500                                           ;Pause 0.5 seconds (500ms)

Now the red LED lights up for 0.5 seconds and then it is switched off again but it only happens once and we want to do it continuously. To do that we must start at the beginning again after the program has finished. The goto command is used to create a loop back to the beginning of the program. Add the following lines of code to pause the program after the red LED is switched off and to loop back to the beginning again.
       pause 1000                                          ;Pause 1 second (1000ms)
       goto main                                             ;Loopback to the beginning

Now everything works and the red LED is switched on and off continuously. This means that the program never stops as soon as it finishes it starts at the beginning again.

The final program is:

main:                                                      ;This is a label called main
            symbol RED_LED = 0             ;Rename port 0 to RED_LED
            high RED_LED                         ;Switch on the red LED
            pause 500                                 ;Pause 0.5 seconds (500ms)
            low RED_LED                          ;Switch off the red LED
            pause 1000                               ;Pause 1 second (1000ms)
            goto main                                  ;Loopback to the beginning

It is a good idea to save all your programs for future reference by clicking the save button and giving it a name.