PICAXE is a neat entry-level microcontroller system that is relatively cheap to get started with. The chip is programmed with a simple serial connection and the BASIC development environment is free! PICAXE has some excellent educational applications and support, and is a great entryway into more complicated embedded systems. If you're look for a place to start with microcontrollers, PICAXE is a great way to go!
Configuring PICAXE-08 / 08M Input-Output Pins
The PICAXE-08 microcontroller has 5 input/output pins. Unlike the larger PICAXE microcontroller (where the pins are pre-defined) the user can select whether some of the pins are used as input or as outputs.
Pin 0 must always be an output, and pin 3 must always be an input (this is due to the internal construction of the microcontroller). The other 3 pins can be selected to be inputs or outputs, and so the user can select any input/output combination between the limits of 1 input-4 outputs and 4 inputs-1 output.
In addition pin 1 also contains a low-resolution analogue to digital converter and so can be used as an analogue input pin if required.
Important - Don’t Get Confused!
The input/output pin numbers are NOT the same as the external ‘leg’ numbers, as the input/output pin numbering follows the microcontrollers manufacturers port allocation. To avoid confusion this manual always talks about ‘legs’ where referring to the external physical location of the input/output pin.
Leg
|
Description
|
Notes |
1 |
Positive Supply, V
|
Use a 3V to 5V battery pack/supply |
2 |
Serial In |
Used for the program download |
3 |
Pin 4 |
Input or output |
4 |
Pin 3 |
Input only |
5 |
Pin 2 |
Input or output |
6 |
Pin1 |
Input or output |
7 |
Pin 0 / Serial Out |
Output only. Also used for download |
8 |
Ground, G |
Connect to the power supply (0V) |
Special Note - Output Pin 0
Pin 0 (leg 7) is used during the program download, but can also be used as a normal output once the download is complete. On the project boards a jumper link allows the microcontroller leg to either be connected to the download socket (PROG position) or to the output (OUT position). Remember to move the jumper into the correct position when testing your program!.
If you are making your own pcb you can include a similar jumper link or small switch, or you may prefer to connect the microcontroller leg to both the output device and the program socket at the same time. In this case you must remember that your output device will rapidly switch on and off as the download takes place (not a problem with simple outputs like LEDs, but could cause problems with other devices such as motors).
Selecting Inputs or Outputs.
When the PICAXE-08 first powers up, all pins are configured as input pins (except pin0, which is always an output). There are three methods of setting the other pins to be outputs (if required)
Method 1 – use a command that requires the pin to be an output.
This is the simplest method, used by most educational users. As soon as a command that involves an output pin (such as high, low, toggle, serout or sound) is used, the PICAXE-08 microcontroller automatically converts the pin to an output (and leaves the pin as an output).
Therefore the simplest way to setup outputs is just to put a ‘low’ command at the start of the program for each output pin. This tells the microcontroller to make the pin an output, and to make sure the output is condition low (off).
Method 2 – use the input and output command.
The command ‘output ?’ (where ? is the pin number) can also be used to tell the pin to be an output at the start of a program. Likewise the ‘input ?’ command can be used to set the pin as an input, although this is not normally necessary as most of the pins are set as inputs by default. Note that the output command does not set the pin into a known high or low state, so it is often preferable to use the ‘low’ command instead.
The input and output commands have no effect on pin 0 (output) and pin 3 (input), which cannot be altered.
Method 3 – (advanced) use the let dirs = command
The ‘let dirs = %000100111’ command can be used to simultaneously set all the pins at the same time. This is quicker than using multiple input/output commands but requires an understanding of binary bits (explained in tutorial 9). Placing a 0 for the pin number bit will make the corresponding pin an input, a 1 will make the pin an output. The value of bits 0,3,5,6,7 can be either 0s or 1s as they have no effect on the microcontroller and are simply ignored.
Selecting pins to be an analogue input.
Use of the readadc command will automatically configure the pin to be an analogue input. Therefore use the command ‘readadc 1,b2’ whenever you wish to take an analogue reading (presuming use of variable b2 to store the analogue reading).
No recommended products at the moment.