Intellecta Technologies Pty Ltd

for PICAXE education, Roland CAM, Techsoft CAD, Intellecta control, Atmel, Arm and Microchip education

Controlling lights

Turning on and off the two lights on the Control 7 is the simplest first programming example. You will learn how to define your program with the flowchart, convert to BASIC code and download to the Control 7 device.

The steps are defined and broken down into the appropriate stages including a better way to set up the output values in your program..


Step 1

Start the Programming Editor from the Windows program menu items.

picaxe starting screen02

Step 2

You have to set up the system to match the PICAXE microcontroller supplied in the Control 7. It is an 18X device and it is important to use this device because it has different options in comparison to other devices.

Select the Options item

picaxe options screen select

Step 3

Select the 18X Device in the Options window.

 

picaxe options screen

Step 4

There are three methods of entering your instructions or program. You can use a BASIC text entry, flowchart or logic symbols.

Go to the File>New>New Flowchart menu item to select the flow chart method.

 

picaxe flowchart start

Step 5

You will see a work area with a start icon in the centre. You have to select, place and link the appropriate flow chart icons from the tool bar.

These flowchart symbols are divided intro specific families such as outputs, if comparisons, delay functions, subroutines and others.

 

picaxe flowchart starting screen
picaxe flowchart toolbar02

Step 6

It is important to document your work with labels and other techniques otherwise you will get lost.

It is very useful to give a functional name to a connection on the microcontroller so you can follow the ideas.

This is easy with the Flowchart symbol table where you can enter these details.

Select Flowchart>Flowchart Symbol Table to enter a table area.

Enter names as see in the table. You can set up your own names but make sure that these are descriptive and related to labels or functions on the board.

You can see that the labels for the motor are related to the original schematic.

 

picaxe flowchart symbol table
picaxe flowchart symbol table entry

Step 7 - YOUR FIRST PROGRAM

You will now set up your first program that turns on and off the leds that correspond to LIGHT1 and LIGHT2.

1. Move to the OUT symbol on the tool bar.

You will see another set of icons that have HIGH, LOW labels,

2. Select the High icon. You will see a box with the internal label of MOTOR1P. This box defaults to the label allocated to line 0. Note that LIGHT1 and LIGHT2 are on output 4 and output 5.

You have to change this label to match the LIGHT1 or LIGHT2 label,

Click on the high MOTOR1P icon and you will see a new window pop up at the lower left of the screen.

Select LIGHT1 or LIGHT2 from this area.

Place the following icons:

high LIGHT1 - turns ON Light1

low LIGHT2 - turns OFF LIGHT2

pause 1000 - get from the DELAY menu

low LIGHT1 - turns OFF Light1

high LIGHT2 - turns ON Light2

Use the line function to join the base of the last pause to the start icon.

What have you achieved?

You have set up a flow chart that sets up the alternate flashing of LIGHT1 and LIGHT2.

picaxe flowchart symbol placement
picaxe flowchart 102

Step 8

It is very useful to test your program prior to downloading it to the device.

The Programming Editor has a simulate option when you enter your program via the flowchart.

Select this by clicking on the Simulate Menu item OR clicking on the function 4 key.

You will see the Input.outputs window flash as well as red-lined icons corresponding to the steps in the program.

picaxe flowchart simulation
simulation

Step 9

The flowchart entry is a good starting point for your understanding of the elements of programming and managing programming.

However, the real power is in the BASIC code that is represented by the flowchart.

Select the Flowchart>Convert Flowchart to BASIC option or press F5.

You will see a new window with the text representation of your flowchart.

 

Flowchart to basic

Light flash program basic code02

ANALYSIS OF THE PROGRAM

There are three important areas in this BASIC language representation of your program.

SYMBOLS:

Here is the house-keeping part of your program. This area will be very important in all your programming projects because this area allows you to do global changes if your change your devices.

Labels:

Main and label_36 are defined points in your program.

Code:

This is the BASIC language and looks similar to your flow chart symbols.


Step 9

It is very easy to download your program but make sure you have the following in place.

1. Programming cable connected to the serial port on the computer and plugged into the download socket.

2. Power supply turned ON and plugged into the socket. Make sure that the voltage is at least 7.5V.

Click on the download arrow and your should see the Downloading program window pop up.

You will see the lights flash on and off on the Control 7.

 

downloading
flashing light

Problems with your program

It is very easy to put in High and Low commands except when you have to control a number of devices. This method leads to problems and errors.

Designers of microcontrollers usually bundle lines into groups of 8 called PORTS and you can address the port with one statement such as LET PORT = 0 to make all the lines low or LET PORT = 255 to make them high.

For example, the schematic of the ATMEL microcontroller shows ports labelled PA0,PA1 etc, PB0, PB1 etc and Ports D and C.

These ports can be grouped into functions to make the design easier.

It is easier to see the actual high and low values if we use a binary representation.

These following examples show you how to use the PINS command.

8535construction

pins statement

Using the PINS command

The plan is to turn on and off LIGHTS1 and LIGHT2. which correspond to output 4 and output 5.

Since these are on a port you can turn on output 4 by using the fourth position in a binary number which is 16 ( 2 to the power of 4).

Similarly, 32 makes OUTPUT 5 go ON.

Question: What value makes 4 and 5 both come ON???

Enter the following flowchart and convert to BASIC. Note that it would be really useful to enter numbers in a binary format.

 

pins command

Using the PINS command - second example.

Here the plan is to cycle the outputs so that all the leds light up.

It is easy with the PINS command where a value is sent to the PINS command and then incremented.

SInce each Output is on a binary level, this value must be doubled every time.

Also, it would be useful to stop at a vale of 64 and then start again.

second program flowchart
second program
[Home] [About] [News] [Events] [Products] [CAD] [CAM] [Control] [Mechatronics] [Science] [Materials] [Support] [Map] [Contact]

PICMicro & Microchip logo are registered trademarks of Microchip Technology Inc. AZ. Atmel AVR & Atmel logo are registered trademarks of Atmel Corporation. CA. Philips Logo is a registered trademark of Philips Semiconductor Inc & Philips SA, Netherlands. Picaxe is a registered Trade mark of Microchip. Intellecta is a registered trademark of Intellecta Technologies. All other logos and trademarks are the property of their respective owners.  Revision Date June2006

© 1997- 2006 Intellecta Technologies - All rights reserved - email: supportatintellectadotnet