This is only a preview of the December 2001 issue of Silicon Chip. You can view 28 of the 96 pages in the full issue, including the advertisments. For full access, purchase the issue for $10.00 or subscribe for access to the latest issues. Items relevant to "Build A PC Infrared Transceiver":
Items relevant to "100W RMS/Channel Stereo Amplifier; Pt.2":
Articles in this series:
|
PIC FUN AND
Way back in time, last century even, we presented a neat
little PIC-based project called LED FUN. Here’s its big
brother, another PIC project called PICFun2. And while
it can flash LEDs, it is capable of doing a whole lot more!
A
ctually, the project we referred today that an understanding of them is programmed (or “written to”) only
to above wasn’t all that long almost essential for anyone interested once. Their program cannot be erased
ago – February 1999 to be pre- in furthering their electronics knowl- – to change the program, you have
cise (it just seems long ago!). LED FUN edge, whether that be at a hobby, stu- to change the chip. These are much
was based on a PIC12C508 which was dent, technician or professional level. cheaper to produce than the re-programmable type and are used when
programmed to flash LEDs in a variety
When we say common, we mean
all of the code has been tested or “deof patterns.
it. Unless you’ve just woken up,
The board was designed and prothe chances are that already today bugged”, ready for a production run.
duced in Australia by Labtronics. Now you’ve used not just one, but several
If you want to know more about
reincarnated as eLabtronics, the new
devices containing PICs or other mi- PICs and microcontrollers, there is a
project, PICFun2, is based on a more crocon-trollers. In fact, if you woke up
lot more in the PICFun manual on the
powerful PIC, the 16F84.
to an electronic alarm clock or clock
CD-ROM – a lot more!
PICFun2 has more than one
What you get
aim. In its “bare bones” form, it’s
basically just a PIC on a PC board
In the PICFun2 kit, there is
with a sprinkling of components
a small PC board, the PIC chip
to enable you to connect it to the
(16F84) with an 18-pin IC socket,
outside world (or, more correctly,
a buzzer, a 9-pin male D socket,
the inside world – the inside of
a couple of PC board mounting
your personal computer!).
terminal blocks, a battery holder
It’s designed as an educational
(no batteries!), a slide switch and
aid, something for (especially)
a pushbutton switch, some reschool students (or anyone else)
sistors, capacitors, diodes, LEDs
to “cut their teeth” on in the world
and a transistor, along with some
of microcontrollers. Indeed, the
hookup wire.
man-ual supplied (on an accomOn an accompanying CD, there
panying CD-ROM) goes into a great
is a range of software, manuals –
deal of explanation into just what
even a technical manual on the
a microcontroller is and what it
PIC16F8X range – and various
does, long before you get to touch a
other information. This CD-ROM
soldering iron! There’s even a trial When they say PICFun is child’s play, they
is PC (ie, IBM) compatible.
version of some software to help mean it! Here is 8-year-old Emilio who built a
Putting it together
you program – but more on this PICFun2 kit – and it worked first time! (This
version actually has a bit more on it than the
shortly.
The first thing to do is completeBut it’s much more than this. basic PICFUN2 described here.)
ly ignore the PC board component
The project software provided on
layout in the instruction manual.
the CD-ROM shows just a couple
It will confuse the heck out of you
radio, it probably contained one!
of things you can do with PICs. Once
for two reasons: (a) it’s an earlier PC
There are many different types of board (new ones are different!) and
you’ve learned how to drive them,
you’re ready to start writing your own PICs (and other microcontrollers).
(b) it shows a different project to what
Some, such as the type we are us- you’re building here. Use the PC board
code to do, well, whatever you want
ing here, can be programmed and component layout we’ve shown here
to.
erased hundreds, often thousands of and the accompanying photo.
Why would you want to learn about
times. Others, such as the ones used
microcontrollers, and PICs in particuStep-by-step instructions are givin commercial equipment, can be
lar? Well, they’re in such common use
en in the manual but assembly is
78 Silicon Chip
www.siliconchip.com.au
GAMES
basically the same
as any other kit:
start with the lowest
profile components
first – the resistors,
followed by the diodes, capacitors, transistors and LEDs.
The hardware (IC socket, switches, D9
socket, terminal blocks and buzzer) is
the last to be soldered in place.
Soldering the D9 socket in place
is probably the most tricky bit. The
easiest way to do it is to undo the
nuts on each end which hold the plug
shell in place (remember which way
up it goes!), soldering the pins to the
PC board and then replacing the shell
and the nuts.
Also the on-board terminals need
a bit of explaining: you slide these
By Ross Tester
In its most basic form, there isn’t much to PICFun2 – apart from the PIC chip
itself there is just an input from your PC (the D9 connector), power supply and
some output LEDs. But this is only the starting point. PICFun2 can be expanded
to do a lot more than flash LEDs!
Use this overlay to populate
the PC board, not the one in
the manual. The circuit diagram is overleaf.
www.siliconchip.com.au
December 2001 79
In its simplest form, PICFun2 contains only the PIC chip itself, some power supply components, the interface to your PC
and some output LEDs. The manual has a number of programming suggestions.
together to form a four-way terminal
block before soldering them in place.
The “open” side of the plug (ie, the
bit where you poke in the wires!) has
to face to the outside edge of the PC
board.
And lastly, the LEDs: the manual
makes some comment about aligning
all the LEDs so that their longer leg
(the so-called “negative lead” – we’d
call it the cathode!) goes “via the thick
track to the negative rail”.
What they should simply say (we
think!) is that all the LEDs should be
soldered in so that their flat sides are
facing the top of the board as you read
the labels. Now that’s a tad simpler,
isn’t it? And yes, there are a couple
of LED positions not used.
What you should end up with is a
PC board similar to that photographed
on page79. As you can see, there is not
a lot of the PC board “populated”; that
is for later expansion when you start
doing really clever stuff with the PIC.
Testing the board
Having assembled the hardware for
the controller the next step is to test it.
80 Silicon Chip
First of all, you need to supply
power. The manual talks about 3 x
“AA” cells but a 4 x“AA” cell holder
is supplied. Use four cells, otherwise
you will have an open-circuit power
supply! The 5.1V zener diode included
in the circuit will regulate the voltage
to within the PIC’s specs.
Install the software provided with
the PICFun2 kit. Start the program
Picplc. This program is used to send
code in binary format to the 16F84 for
programming. Code for this is obtained
from the appropriate *.hex file.
When started you will be asked for
the location of the hex file you wish
to download. Load the file and the
number of the serial port being used for
programming (ie; c:/PICFUN/mode1.
hex 2 where 2 is the com port and
the file is located in the c:/PICFUN
directory). Leave a space between the
x and the number.
It is suggested that you use the
mode1.hex file for the test. This is
found amongst others on the disk
provided.
Follow the steps below. They will
lead you through the processes re-
quired to program the chip as well
as providing a test for its successful
construction.
Step 1
Connect a 9-pin serial cable (not
supplied with the single version of
the educational kit) from the D9 port
connector on the microcontroller to
an available serial COM port on your
computer. You will need to know if it
is COM 1 or 2 that you have selected.
Check the gender of the connectors
on your cable. A gender changer may
be required. (The cable is a 1-1 wired
serial cable female to female, 9 pin to
9-pin or 9-pin to 25-pin).
Step 2
Run START on the supplied CD.
Install all the software ( PICFun and
MPLAB ) and drivers to drive C:/
PICFUN of your computer. You will
need approximately 5Mb of hard disk
space.
Step 3
With the computer off, connect the
PICFun2 to the serial connection on
your computer, then start the computer. Keep the serial lead and programmer connected during start up and the
www.siliconchip.com.au
Parts List – PICFun2
1 PC board, 80 x 48 mm, coded
PICFun2
2 PC board mounting terminal
blocks
1 18-pin IC socket
1 piezo buzzer
1 miniature pushbutton switch,
NO contacts
1 SPST miniature slide switch,
PC board mounting
1 4xAA battery holder
4 AA batteries
(not included in kit)
1 9-pin “D” serial interface
connector, right-angle PC
mounting
1 “straight through” serial cable,
9-pin female to 9-pin female
Hookup wire
Semiconductors
1 PIC 16F84 microcontroller IC
(IC1)
1 BC547 NPN transistor (TR1)
4 1N914 silicon signal diodes
(D2-D5)
1 5.1V 400mW zener diode (D1)
6 red LEDs (DOL1-6)
Capacitors
1 100µF 25VW PC electrolytic
1 0.1µF ceramic
(code 104 or 0.1)
1 22pF ceramic (code 22p or 22)
Resistors (0.25W, 5%)
7 10kΩ 1 4.7kΩ
8 390Ω
1 10Ω
slide switch on the PICFun PC board
towards the middle of the unit.
Step 4
The slide switch is vital to the
programming and running modes. It
tells the PIC whether it is in a write
(programming) or read mode. Make
sure it is connected (towards middle)
during programming. When running
programs it must be disconnected (towards outside). Power is not applied to
the PICFun2 during the programming
process. The required voltage is derived from the serial interface. Power
is only applied during the running
process.
Step 5
Go to the Start/Programs list and
run the Picplc programmer software.
(NB: In the PICFun2 software setup
and supplied files the term ‘PIC PLC’
is used to describe the device as it was
www.siliconchip.com.au
originally known by that name.)
Step 6
Under Windows you open the the
program in the normal manner. You’ll
need to tell PICFun2 which COM port
you are using. The software will then
transfer the sample program “model.
hex” to your PICFun board.
Step 7
Test your PICFun2 programmer
and micro controller. Disconnect the
serial lead and jumper. Insert batteries
into the holder (4 x 1.5V cells). Once
power is applied the program will start
to run. When the switch is pressed
for a second and then released, the
LEDs should light up randomly and
a sound sequence be produced by the
piezo buzzer.
Kits
without
compromise
What if it doesn’t work?
OK, we’ll be honest. Ours didn’t
work first time! Here are just a couple
of the traps you could fall in to.
(1) Check your soldering and component placement. 99% of all faults with
kits are found in this area. Are all the
diodes and other polarised components
around the right way? Have you managed
to solder a bridge between adjacent pads?
Have you forgotten to solder a component
in (or, have you made a “dry joint”)?
Having exhausted all those possibilities
through careful inspection and checking,
let’s move on to the other 1% (our problems were in the 1% category!).
(2) Is your power supply/plugpack
connected the right way around? The
series diode will prevent anything
catastrophic happening if you connect
the power back-to-front . . . but it won’t
work, of course!
(3) Is your 9-pin D to 9-pin D cable
a true serial cable? Many of the cables
have pins swapped in them (so-called
“null modem” cables) and these will
not work. If in doubt, check for continuity between pins with your multimeter and some short lengths of wire
poked into the socket holes. Pin 1 must
connect to pin 1, 2 to 2 and so on right
through to pin 9. (Not all pins are used
but the cable should be wired through).
Similarly, you must use a female-to-female cable. If you have a
female- to-male cable with a gender
changer on one end, there may be a
crossover in that gender changer or
cable.
(4) Have you followed the software
loading/downloading steps carefully
and have you properly initialized the
software?
“Sound quality to die for”
Rolling Stone Magazine
“..A new benchmark in
every criteria”
Best Buys Home Theatre
Speaker Kits
without compromise
from $312 pr to $8,863 pr
FreeCall 1800 818882
www.vaf.com.au
vaf<at>vaf.com.au
December 2001 81
RESISTOR COLOUR CODES
No.
7
1
8
1
Value
10kΩ
4.7kΩ
390Ω
10Ω
4-Band Code (1%)
brown black orange brown
yellow purple red brown
orange white brown brown
brown black black brown
(5) Is the path to the hex file correct?
(6) Have you connected the correct
COM port?
(7) Have you set the programming
switch/jumper on the board before
running the program (ie; applying
power).
Where to from here?
Space does not permit detailing
all the applications possible with the
simple PICFun2 board – you’ll find a
lot more on this in the manual and on
the CD-ROM.
One of the sample programs on the
CD-ROM is a demonstration temperature controller, which uses the PIC to
sense the temperature of a thermistor.
The thermistor, in turn, is under the
influence of both a small light globe
(heater) and a fan (cooler), each of
which are also controlled by the PIC.
This does require a few more components than what we’ve shown here,
by the way.
A setup screen is provided on the
PC through which you can enter maximum and minimum temperatures.
When you download and run the
program, you’ll find the light comes
on to heat the thermistor up to your
maximum temperature, at which point
the light goes off and the fan goes on
to cool it back down to the minimum.
Such a demonstration board is
shown separately. Sure, it’s only a
gimmick – but it’s a great little demonstration of what a microcontroller can
do and makes an interesting school
project.
Just imagine if that light, thermistor
and fan were replaced by a large heating, sensing and cooling system for a
city skyscraper. Impossible? Nothing
is impossible for a microcontroller!
Creating a program
As we said at the outset, the PICFun2 is just a starting point. Writing
your own software (also known as
code or a program) is not easy for a
beginner – but start out simple and
82 Silicon Chip
5-Band Code (1%)
brown black black red brown
yellow purple black brown brown
orange white black black brown
brown black black gold brown
keep practicing – and pretty soon you
could be an expert!
Microchip Technologies, the makers of PICs, have provided a number
of shareware software tools for the
support of their products. “MPLAB”,
which is downloadable from their web
site (www.microchip.com) offers a
text editor, an assembler and software
simulator for the writing, assembling
and testing of programs.
The text editor is used to compile
the source code. This is made up of
device instructions, data, directives
and comments.
The program is written in mnemonic form and is based on an instruction
set peculiar to the PIC device. Programs consist of a series of instructions that detail consecutively the
processes the programmer requires the
microcontroller to execute. Programs
are set out in a special format so that
labels, instructions, directives and
comments are recognised by the assembler.
The assembler takes the compiled
source code and processes this to
produce an assembled (*.asm) file and
an output (*.hex) file. The compiled
source code is saved as an *.asm file
while the *.hex file contains the data
ready for downloading to the microcontroller.
The hex file must be loaded into a
program such as Picplc to convert it
into binary form first.
Debugging
It’s a pretty rare programmer who
manages to write code without errors,
or bugs. Getting rid of these is not
called squashing or swatting, it’s called
debugging.
MPLAB contains a software simulator which enables programs to be
checked and debugged. The simulator
enables programs to be observed step
by step and shows what is happening
in the various register and memory
locations.
Simulators can be invaluable tools
for program development but have
their limitations since they are not the
real device. For the simulator to work,
a hex file must be loaded into it.
In this section we have set out some
of the basics for preparing a program.
We have included examples of how
all three tools are used in the process.
Your first step will be to install the
MPLAB software if this has not already
been done. About 8Mb of hard disk
space will be needed. The zipped files
can be saved to individual disks and
installed after downloading.
And if you want more information,
the web contains thousands – no,
probably millions – of pages of data,
programs and help on PICs as well as
other microcontrollers. If you don’t
believe us, go to www.siliconchip.com
.au and type PIC into the Google search
engine. See you in a couple of years!
BitSet program
Included in the kit is a trial version
of eLabtronics' “BitSet” software,
an icon-based programming tool designed to replicate all the instructions
available in the 16F84 instruction set.
It utilises windows and drop down
menus in which all the information
contained in a text instruction can be
entered and implemented on variables
and literals.
This provides a convenient method
of entering instructions and data. The
names assigned to the icons are representative of the group of functions
SC
hidden behind each button.
Where from?
The PICFun2 is designed by
eLabtronics, 12-20 Gilles St,
Adelaide, SA 5000.
Tel (08) 8231 5966 Fax (08) 8231 5266
website: www.labtron.com.au
Price of the basic PICFun2 is
$78.00 +GST.
It is also available through Altronics
stores and mail order (1800 999 007).
www.siliconchip.com.au
|