02-04-2012, 12:08 PM
MICROCONTROLLER INTERFACING CIRCUITS
MICROCONTROLLER INTERFACING CIRCUITS.pdf (Size: 286.29 KB / Downloads: 30)
About this manual
Please note an update version of this manual is under preparation. See
www.picaxe.co.uk for latest version
The PICAXE manual is divided into three separate sections:
Section 1 - Getting Started (picaxe_manual1.pdf)
Section 2 - BASIC Commands (picaxe_manual2.pdf)
Section 3 - Microcontroller interfacing circuits (picaxe_manual3.pdf)
This third section provides general microcontroller interfacing circuits, and
example programs, for most common input/output transducers used within
microcontroller circuits.
For general information on getting started with the PICAXE system please see
section 1 of the manual. No prior understanding of microcontrollers is
required. A series of tutorials introduces the main features of the system.
For more specific information, syntax and examples of each BASIC Command
please see section 2 ‘BASIC Commands’.
The software used for programming the PICAXE is called the ‘Programming
Editor’. This software is free to download from www.picaxe.co.uk. This manual
was prepared using Version 5.2.0 of the Programming Editor software. Please
ensure you are using this version (or later) of the software, as earlier versions
may not support all the commands and features described.
The latest version of this document is available on the PICAXE website at
www.picaxe.co.uk
If you have a question about any command please post a question on the very
active support forum at this website.
3 Section 3
MICROCONTROLLER INTERFACING CIRCUITS
revolution Revolution Education Ltd. Web: www.picaxe.co.uk
Version 4.4 12/2010
3
www.picaxe.co.uk
Microcontroller Interfacing Circuits
What is a PIC Microcontroller?
A PIC microcontroller is a single integrated circuit small enough to fit in the palm of a
hand. ‘Traditional’ microprocessor circuits contain four or five separate integrated
circuits - the microprocessor (CPU) itself, an EPROM program memory chip, some
RAM memory and an input/output interface. With PIC microcontrollers all these
functions are included within one single package, making them cost effective and easy
to use.
PIC microcontrollers can be used as the ‘brain’ to control a large variety of products. In
order to control devices, it is necessary to interface (or ‘connect’) them to the PIC
microcontroller. This section will help to enable those with limited electronics
experience to successfully complete these interfacing tasks.
What is a PICAXE microcontroller?
A PICAXE microcontroller is a standard Microchip PICmicro™ microcontroller that has
been pre-programmed with the PICAXE bootstrap code. The bootstrap code enables
the PICAXE microcontroller to be re-programmed directly via a simple serial
connection. This eliminates the need for an (expensive) conventional programmer,
making the whole download system a very low-cost simple serial cable!
The pre-programmed bootstrap code also contains common routines (such as how to
generate a pause delay or a sound output), so that each download does not have to
waste time downloading this commonly required data. This makes the download time
much quicker.
As the blank microcontrollers purchased to ‘make’ PICAXE microcontrollers are
purchased in large volumes, it is possible for the manufacturer to program the
bootstrap code and still sell the PICAXE microcontroller at prices close to standard
catalogue process for single un-programmed PIC microcontrollers. This means the cost
of the PICAXE microcontroller to the end user is very economical.
4 Section 3
MICROCONTROLLER INTERFACING CIRCUITS
revolution Revolution Education Ltd. Web: www.picaxe.co.uk
Version 4.4 12/2010
4
www.picaxe.co.uk
Interfacing to the PICAXE Microcontroller
This section explains how to interface many different input and output devices to the
PICAXE microcontroller. Explanations of BASIC commands are provided in the
Commands section (available separately). The interfacing circuits can also be used
with any other PIC microcontrollers such as the PIC16F84A, although these
microcontrollers may require programming in assembler code.
This section is split into four subsections:
• Introduction to ‘standard’ interfacing circuits
• Output Device Interfacing
• Input Device Interfacing
• Advanced Component Interfacing
5 Section 3
MICROCONTROLLER INTERFACING CIRCUITS
revolution Revolution Education Ltd. Web: www.picaxe.co.uk
Version 4.4 12/2010
5
www.picaxe.co.uk
Note on the BASIC Code Samples
Simple BASIC code examples are provided within each subsection. The samples are
not ‘complete’ programs but sections of code that can be included within a main
program when using that particular component. When using these code samples it
must be remembered that:
1. Each pin should be set up as an input or output before using the code (stamp
users only).
2. If the hardware pins are changed from those given in the circuit diagrams it will
be necessary to modify the pin numbers in the code.
3. Any ‘let dirs =’ or ‘let pins =’ commands will adjust all 8 pins, in the port.
4. Try to keep variables independant of each other. If a sub-procedure uses a
variable, do not use the same variable anywhere else in the code. If the same
variable must be used again, make sure there is no way it can clash with any
other part of the code. This is the most common way of adding ‘hard-to-find’
bugs into software code.
Note on Component Selection
For convenience and ease of understanding, a single device has been adopted when
using standard interfacing components such as transistors and MOSFETS. For instance,
the ‘standard’ transistor selected is the darlington device BCX38C. This does not mean
that this device is the only transistor that can be used in all the transistor circuits, as it
is not, but it is chosen because it is suitable for the majority of project work
applications. All components listed are common devices that can be purchased from
most electronics distributors.
6 Section 3
MICROCONTROLLER INTERFACING CIRCUITS
revolution Revolution Education Ltd. Web: www.picaxe.co.uk
Version 4.4 12/2010
6
www.picaxe.co.uk
Standard Interfacing Circuits
Standard Circuits 1 - The Transistor Interfacing Circuit
Many output devices will require a transistor switching circuit. In most cases a
darlington pair formed from two transistors is ideal.
However this circuit requires that two separate transistors are used. It is possible to
buy a device that contains the two transistors in a single package. This transistor is
called the BCX38C, and can switch currents up to 800mA. This is the transistor used in
all the circuits through this book.
Note that it is usual to connect a back emf suppression diode across the output device.
This is essential with devices such as relays, solenoids and motors which create a back
emf when power is switched off. The diode type 1N4001 is the device recommended.