|
Chapter 0
The chapters you are about to read in our PIC programming course have been designed by the Staff at Talking
Electronics to assist the BEGINNER to get into programming the PIC12C508A and PIC16F84
microcontrollers.
The '508A is the
"baby" and the 'F84 is the "one-and-a-half-port"
version we will be covering.
Both of these are very small devices in the
"micro" world but they are the place to start.
The pin-outs
for the two devices are
shown below:

We have chosen them out of the range of PIC devices as
they are the cheapest and the best (for the beginner). You will see what we mean
by this, AND AGREE, after you read the course.
Maybe you are wondering why we have produced so much information on
programming these chips, as there is already an enormous amount available in
books and on web sites.
The reason is the information you can find is of a highly technical nature and
not designed to get the REAL BEGINNER into programming.
What is needed is an absolute beginners course. One that introduces the least
amount of complication to get a program
up-and-running.
And that's what we have done. You don't have to know Boolean Algebra, complex
mathematics or the effect of double XOR'ing a file, to be able to program.
We do everything the simple
way. The course also shows you how to interface the chips to external devices and
by taking ideas from one project and applying them to another you can create a
totally new circuit with the least amount of technical skill.
There's an amazing
thing about programming. A program can be constructed using highly
complex thinking or very simple thinking. The end result is the same but the
simple approach may take a few more instructions to achieve the end result. Who cares
about a few more instructions when the micro is processing at 1,000,000
instructions per second!
We start you off with a simple seven-line program to turn on a LED in a
prototyping module called the Pseudo'508A.
SetUp BSF 03,5
MOVLW 3E
MOVWF
06
BCF 03,5
Out0 MOVLW 01
MOVWF 06
GOTO Out0
|
This is the simplest program for the '508A. It turns on a LED as
shown in the animation below: |
This is just one of the modules we have designed to get you into programming and
and help you to produce "final designs." It has LEDs connected to three of the output lines and the program above simply
accesses one of these LEDs.
Click on the animation below
and you will see it turn on the LED connected to GP0 (General
Purpose IN-OUT line ZERO - Pin 7)
Suppose you want to make the LED
flash. This requires a 4-step program as shown below.
Suppose the on-time is 0.1seconds and off-time=0.9seconds. A
simple flow chart can be produced:
From
the flow-chart you can see you need to do 4 things:
1. Turn ON an output
2. Keep the output ON for a period of time
3. Turn OFF the output
4. Keep the output turned OFF for a period of time.
The thing you must remember is the processor (the heart of the
microcontroller chip) must be kept running all the time. The
chip contains a 4MHz oscillator and this frequency is
internally divided by 4 so that one instruction is processed every microsecond.
This makes it very easy to produce accurate delay
routines.
In our case we don't need an accurate delay-time, but at
least we can work things out via the program and the circuit will work exactly as
it is meant to.
This means you need to produce a DELAY of
100,000 "DO-NOTHING" cycles while the output is kept ON.
The same applies for the 0.9 seconds. It requires a delay of 900,000
cycles while the output is in the OFF condition.
To create the routine needed to flash the LED, you can start from scratch
by reading the notes we have provided in our chapters or go to the Library
of Routines
chapter, under Flashing LED. You will find references to '508A
Proto-1 project
(Programs 1 and 2) and Toggle, and Turning on an Output (both in the
Library of Routines).
The lines of code are also available on a disk (called "LIBRARY
OF ROUTINES") or you can COPY and PASTE from the web.
These are the lines of code you will need:
FlashLED1
Loop1
AA1
Delay1
DelX
|
BSF 03h,5
MOVLW 00
MOVWF 06
BCF 03h,5
BSF 06,0
CALL Delay1
BCF 06,0
MOVLW 09
MOVWF 0C
CALL Delay1
DECFSZ 0C
GOTO AA1
GOTO
Loop1
MOVLW 82h
MOVWF 1A
DECFSZ 1B
GOTO DelX
DECFSZ 1A
GOTO DelX
RETURN
|
;Select
Page1
;to make GP0 output
;Select Page0
;SET bit0 HIGH
;Make bit0 LOW
;Put 9 in W
;0C is the loop file
;130
loops
;256 decrements
;2uS
instruction |
|
This
program turns a LED for 0.1sec (Delay1 routine) then OFF for 0.9s
by calling the routine 9 times. |
The
following animation shows the result of burning the code into a
'508A: 
But
just before you rush out and do it, you must understand that a
PIC12c508A chip can only be burnt ONCE because the cells holding the
program receive a charge during programming and this charge cannot
be removed. The chip is guaranteed to hold a program for many years
and so you only use one when you are completely satisfied with a
program and the whole project is finalised.
That's a long way down the track and so all our experimenting and
programming is done with a PIC16F84 chip. This is a larger
version of the '508A and fortunately nearly all the features of the
'508A can be found in the '84. This means we can treat the '84 like
a 508A and use the registers and input/output pins that correspond
to the '508A code written into the '84 can
be loaded into a '508A and it can be put in a
project.
Why do we do this?
Because the '508A is much cheaper than the '84 and you can make a very
small cheap project. We also do it because the '84 can be programmed and erased over 1,000 times and
this saves us wasting chips. We can do all our programming in a single '84 and
put the successful program to
a '508A and the project is done!
This has never been done before.
We have seen lots of projects designed around a '508A but the only
way to get the program up-and-running is to buy a window-version of
the chip @$15 each! You will need at least 6 of these and each chip
takes 20 minutes to erase! This slows you down enormously when you
are actually getting the program operational, so we had to find a
better way!
We did it with our "Pseudo-'508A" and you will learn a lot
more about this later.
As you will read in the chapters, the course is entirely PRACTICAL and it
gets you into programming at the least expense.
Because of this we have not used any of the "STAMP" concepts as
they are very expensive and reduce the capability of the chip enormously.
Our aim is to get you into programming so you can produce microcontroller
projects and sell programmed chips for as little as $5.00 each (in large quantities). This is something that has never been aimed-at before.
That's what stands our course out from everything else. By the same token I
am not decrying (knocking) any of the PIC user groups or any of the producers of
low-cost programmers as you will be needing assistance from these sources, once
you get the "bug" for programming. All these other groups
have an enormously valuable input to understanding PIC programming and the only
thing you have to remember is the concept of programming via a Library of
Routines and using the '84 as a development tool for simple '508A
projects.
All sorts of help is available at the "top-end." It's the starting point that is lacking. No-one has started at SQUARE ZERO! and guided
the beginner. Standing back, as an educator for the past 20 years, I can see
this and if you agree, you will be fascinated with the approach we have taken.
It's not the conventional approach as this would involve lots of new terms
and complications. It's the SIMPLE APPROACH and once you master the art of
putting a program together you can add to your skills with information from
other sites.
The two chips we have concentrated on are the PIC12C508A and PIC16F84 as
these will allow you to get into creating projects equivalent to 6 or 8 chips
(or even more in
the old technology of gates and counters etc) and produce things such as electronic locks using a card as
access, security tags that transmit up to a metre or so, displays, games, telephone devices, alarms,
interfacing devices, oscillators, robotics and lots more. As one programmer
said: "You will never use a 555 again!" Any of the ideas and projects
that have already been produced on and for an "interpreter-type"
module can now be created in a single chip and produced at less than 1/4 of the
cost.
Surprisingly, our course will
have enormous appeal to those already programming with one of these expensive
modules. Quite often an idea will come up that is suitable for marketing. That's
when the project will have to be converted to a much cheaper design to make it
marketable. And that's where we step in. For the cost of a chip, a $5.00
prototyping PC board, a set of programming disks and books, you will be able to
launch your own product. But obviously you will have to start at the beginning
and familiarize yourself with the code and capabilities of the chip.
All
the programming, instructions and circuit diagrams are contained in
a set of two books. They are called: PIC
Projects - 1 and PIC
Projects - 2.
We had so many pages on programming and projects, we had to put them
into two books. You will need both books to get the full set of
details on programming and at the same time you get a wide range of
projects designed around both the PIC12c508A and PIC16F84.
The projects start from a simple use of the '508A and increase to using
its full memory. Other projects use the 'F84 and they highlight the
capabilities of a microcontroller.
All the programming is
"linear" (very simple) and by going through each documented line you
will be able to see exactly what is being done at each step.
The biggest problem with the STAMP concept is the cost of duplication. The
first prototype may cost $40 to $70 but additional copies will cost more
than $20. With our approach a fully programmed chip will be able to be sold by
you for $5.00 to $8.00 (they cost as lost as $2 in large
quantities), and an assembled PC board for less than $12.00. This
gives you a head-start in the world of marketing and makes you competitive in
manufacturing and selling your ideas.
Many will say the "STAMP concept" gets a program up and running
with very few instructions but we have combated this by designing a set of
routines to perform many of the operations you will require in the development
of a program and placed them in a LIBRARY OF ROUTINES.
This file is supplied on one of the programming disks in the course and you
can down-load any of the sub-routines you require for your program. In this way you can get a program up
and running with very little effort. The advantage of our approach is the micro
runs at full speed, the program memory space can be fully utilized, no
additional chips are required to store the program and all the input-output lines of the chip
are available. There is really no comparison between the two concepts and the differences will not be
mentioned again.
The biggest advantage of doing things our way is you
are fully in charge of the program. If something doesn't work, you don't have to
wonder if the routine provided by the "STAMP or CLONE" is not doing the operation, or if your code has a bug. By
directly using the micro's instructions (from the
set of 33 instructions) you can see exactly what is happening and why it's not
working.
As you will notice, we are presenting the pages of the course on the web to
give you an idea of the content of the books. Many of the diagrams cannot be
reproduced due to them being in a format that does not convert to a .jpg or .gif
file. It's a pity but if you want the complete version of the course you
will need to buy the books. They cost $10.00 each plus $6.00 each for
postage. Simply send us an
E-mail and we will reply.
I know you will buy the
books in the finish because the printed word is the most efficient way to
present information. You can peruse a book much faster than looking at a screen
and the books are such a valuable reference that we refer to them all the time!
While your books are being sent to you through the post, you can refer to
the chapters we have prepared on the web. Only about 60% of each book will be presented on the
web due to the memory it occupies. New chapters are being added all the time, so
bookmark us and keep
re-visiting.
- Colin Mitchell
2000
|