Professional Documents
Culture Documents
CoreChart 628tutorial
CoreChart 628tutorial
1 Day Workshop
Upon completion of this Microcontroller Development Course, the user should have an
understanding in the basics of how a microcontroller works. It will also introduce
elabtronics’ CoreChart, an icon based assembler program designed to simplify the
programming of microcontrollers for beginners, while still offering all the functionality
of text-based programming for more experienced users.
The course is structured in way that an aspect of the microcontroller is explained, and
then a similarly themed practical is undertaken for the user to become more familiar
with the concepts presented. This will hopefully avoid making beginners feel
overwhelmed by having to consume large amount of information at one time.
You might ask: What do I need to know about Microcontroller thingy’s? The answer is
quite simple – nothing. These machines will go about their tasks silently and without
complaint. They never tire, get hungry, distracted, or disgruntled and never forget what
they are supposed to do (unlike most of us on occasion).
These are your remotes, watches, calculators, CD players, Gameboys, sensor lights,
alarm systems, stereos, VCR’s, Digital cameras, washing machines, auto doors, GPS’s,
depth sounder’s, bar code readers, pace makers, and millions of other devices that we
take for granted.
3 million cows in Australia will be tagged with microcontrollers (similar to the one used
in the ledfun), which will be used to gather important health information of the cows.
Millions of smart cards are made from these chips.
In the world of big business the emphasis is on who can produce the most powerful chip
for the smallest amount of money.
The result has been shift in industry over the last 40 years that has been unequalled
since the development of the internal combustion engine. Computers the size of your
desk (1980) used to boast of 2000KB (2,000,000b) of memory, today it is an easy task
to find single chips that exceed that by far. The PIC16F628 has 2KB and is about as
long (size) as its name “PIC16F628” (Times “12”) if not a little smaller.
Consumers should be a part of this revolution. There is no reason to be waiting for the
latest ‘product from overseas’ when the average person could be talented enough to
produce the next Gameboy, MP3, Furby or Poo Chi dog. Even better, the nature of the
technology is such that one person or a team working away in the corner of a room can
produce results that are the equal of the industrial giants.
2
Microcontrollers, or “computers on a single chip”, play a crucial role in most industries.
The ICT industry is one that is experiencing extreme growth. Microcontrollers have
been used to build web servers the size of five cent coins. These web servers are being
used for Internet Connectivity in equipment and products, such as air-conditioners that
can be turned on with a phone call or refrigerators that order you fresh milk when the
expiry date is past it’s “Use by” date. These omnipresent microcontrollers are found in
practically every industry, such as telecommunication, food processing, bio-electronics,
ICT and automotive.
What is a Microcontroller?
In all cases MCs are small stand-alone computer systems designed for the purpose of
control whereas a personal computer is primarily designed to process large amounts of
data quickly. An MC has all of the components on a single chip, such as CPU, RAM,
ROM, inputs and outputs. A microprocessor is simply a CPU and needs the RAM,
ROM, inputs and outputs to be added to the system.
Keyboard
mouse
3.5 Floppy
Figure 1. Above shows the typical structure of a microcontroller and personal computer
system. Note the similarities.
Why elab628?
Apart from being fun to use, the elab628 kit and concept is particularly suited to
educational activities as it is useful and versatile, while still remaining inexpensive.
This provides the opportunity to implement all sorts of programming and design
possibilities, in electronics, robotics and control technology.
3
World class elab628 industrial controllers and data loggers have been implemented by
students and professional engineers for various industries. The elab628 users are using
the development board in conjunction with the latest cutting edge technology in
hardware and software engineering.
Hardware Options
Let us take a closer look at the elab628 Board. The elab628 has been designed to be
as flexible as possible and incorporates many hardware options.
Secondly, the hardware on the elab628 Programmer has options. The controller has 2
Ports, Port A (8 bits) and Port B (8 bits). These correspond to the I/O port numbers on
the PIC16F628 and can individually programmed to be either inputs or outputs.
4
Serial port
Port B
Port A B0-B7
A0-A7 Shown as
TS0-TS7
LED’s
Port A has a set of Resistive Dividers with a pulldown resistor going to 0V. These can
be used to set a trip voltage to trip an input either high or low. For example you need to
check if an input is above 12V or under 12V – resistors can divide the 12V down to the
1V - 1.5V PIC16F628 trip voltage (voltage divider). This will then trip the pin when it
is above 12V. This can then be used to control another external component for
regulation. Port A may be configured for both analog and digital input via internal
settings in the PIC.
Port B has been provided with special options if used as an output. It can directly drive
LEDs, or Transistors can be used instead to control relays or similar devices connected
to the Port B Connectors. Relays may be used directly on the board although you must
utilize a protection diode to prevent voltage spikes caused when relay contacts break
(back emf).
The other major option is the use of the Serial Port for your own PC interface. A
program can be written to control the RB6 and RB7 bits of Port B on the chip to send
information to or from the PC. Software would need to be developed on both the
elab628 and the PC.
We will look at the hardware further later, for now let’s take a look at how to use the
software.
elab628 Software
This course is based on the CoreChart icon assembler program that is found on your
desktop. Double click the icon to open the program.
elab628 Hardware
This course is based on the elab628 development kit by elabtronics. For the
purpose of your learning you will be provided with a elab628 training board set up
to operate the learning area you are working in.
5
Practical 1a
Programming the elab628
Now it is time to install an example BST file ( which is found on the hard-drive of this
computer) into the microchip. A “BST file” is one that contains instructions in a format
suitable for programming PIC chips. This will test if the hardware and software are all
working properly. Following the steps and diagrams below will serve as a diagnostic
procedure for your project, as well as showing you how to load a program into the chip.
Connect the supplied DB9 Serial Cable from the COM port connector on the
elab628 Programmer to an available COM port on your computer. You will need
to know which COM port it is (COM1 or COM2) so that the software can be
configured correctly.
2. Make sure the elab628 is in the Programming Mode (PROG) by switching the
program/run switch towards the PROG on the board.
LD
Run Program
Push
6
3. Make sure that CoreChart is set to 628 mode – it should say CoreChart628 on
the top. If this is not set, then go to ‘Options’ / Select chip model
4. A dialog box will know appear – Select P16F628- then click OK.
7
5. Make sure your COM Port setting is set correctly to the port you plugged the
serial cable into. The setting is changed at: ‘Options’ / ‘Hardware Settings’. In most
cases your computer will be configured correctly.
Note:
If your computer displays the machine code
when you click “Send to PIC” then the setting
in configuration “Show Full IC Prog” must be
changed.
A dialog box will appear, the correct setting is: JDM Programmer, your COM PORT
(look if you don’t know) and ‘Direct I/O’ is for Windows 95 or 98 (Use Windows API
on other versions of Windows )
8
On the left hand top menu select “File”. Position the pointer onto Open and left
click the mouse.
Ask your teacher where the samples are stored and select the “Sample Program for
628” folder. You should see a file, “Program1.BST”.
#1
#2
9
Step 4: Program chip
Go to “Options” and click “Send To Pic”. The Program will now transfer the
Sample program “Program1.bst” to your hardware and verify it by reading the
software back off the PIC.
Don’t worry
10
Trouble shooting
If the programmer fails to take a program it is unlikely that the unit is “Defective”. It is
more probable that there is minor error with your setup.
Settings – Ensure that the settings are as shone in Step 2 #5 – You may try adjusting the
I/O delay to improve performance.
Reset Button - In some circumstances this button has “stuck” ,just check it.
If you assembled your own elab628 you might want to check your soldering.
If the Programmer still fails to accept a “known” working program refer the problem to
your teacher.
Test your elab628 Programmer. Switch the elab628 Programmer into Run Mode
by switching the program/run switch towards the ‘RUN’ label on the board. Make
sure power is connected to the board or the board is plugged into the serial port.
Press the Push Button and the LEDs should light up in order and the buzzer should
beep when the light reaches the end. When the button is released and the LDR
( Light Dependant Resistor ) is covered, the LEDs will light up in reverse order.
LDR
Run
Push Button
11
If you have any problems, check the hardware and check each step carefully.
Otherwise you are ready to go on to Practical 1b.
Note: During certain operations which place a large load on the serial port power supply
the supply voltage will drop below the required amount and it will fail (brown out). This
is because the port can only supply a very limited amount of power (about 150mA). If
the board is fitted with transistors, relays and LED’s then it will be very easy to do.
Connect an external power supply to prevent a “brown out” condition.
Practical 1b
Editing and Renaming a PIC Program using CoreChart Software
In this practical you will learn how to edit an existing CoreChart program. The file
you will modify is “program1.bst”. After editing this program you will rename the
modified program to a name and file of your choice (e.g. "bob’sfast.bst”).
Example
Bob’s fast.bst
As in Practical 1a, this new program file will be programmed onto the PIC16F628
chip (on the elab628 board), and tested. You will see the results with your own eyes!
Run the CoreChart program. Go to “File” and Open the folder: “Sample
Program for 628”. Load the program: “Program1.bst” (same procedure as
Practical 1a)
12
Step 2: Editing and Renaming the program1.bst program
You should now have the icons for the program1.bst showing on the screen.
• Select (Click on) the “Assignment” icon block on the right hand side of the
window
13
• Select another “Assignment” icon and set it to read “y = w” place it on top of the
‘call delay’ icon (15)
If time permits, modify the delay number used in this program (w=10) by changing the
number 10 to 50, and test the results.
How could we create a larger delay than can be provided from a single
delay?
14
SECTION 2
15
elab628 Hardware Description
Power
The PIC16F628 requires a 5V DC supply; actually, any voltage from 4.0 to 6.0 Volts
will do fine, so you can run it from three or four 1.5V cells. The PIC chip consumes
only 1 mA - even less, at low clock speeds - but the power supply must also provide the
current flowing through LEDs or other high-current devices that the PIC chip might be
driving.
The circuit relies on a 0.1µF capacitor from V+ (pin 14) to ground (pin 5), mounted
close to the PIC chip, to protect the chip and adjacent components from electrical noise.
This capacitor should always be present, no matter how constant the DC supply is. This
is capacitor C3 on the elab628 Board.
Reset
The MCLR pin (4) is normally connected to V+ (pin 14) through a 10K resister.
Grounding the pin momentarily will clear the RAM and reset the PIC. If your power
supply voltage rises slowly, the MC may start up in a confused state. A normally open
reset button, between MCLR and ground, is added to prevent this from occurring and
will also provide a circuit reset switch.
Clock
The clock is a small oscillator used to generate a signal voltage for stepping the MCU
sequentially through a program. Clock frequencies may vary from the DC level up to a
number of megahertz (MHz). At DC the MCU will be stalled with no operations taking
place.
OSC1/4
18 17 16 15 14 13 12 11 10
VDD
OSC1 OSC2
V
a PIC 16F84
PIC16F628
OSC 1
OSC 2
OSC 1 1 2 3 4 5 6 7 8 9
1
C
Values fo F OSC / 4
Figure 4: RC oscillator
The PIC16F628 chip has the input clock signal divided by 4. For almost all operations,
each instruction in a program will take one of these clock cycles to be executed. For
example, a clock crystal frequency of 4MHz is internally divided to 1MHz. This means
that each instruction will take 1 millionth of a second to execute (1µs.)
16
The ability of the PIC chip to take one internal clock cycle for each instruction is
particularly useful when calculating specific time intervals in real time applications.
The word “digital” refers to electronics that use “digits” for processing information.
“Digits”, or numbers, could be 3 or 6 or even 2. In fact we normally use digits
anywhere between 0 to 9.
Electronics that are not digital are referred to as “analogue”. An example of an
“analogue” signal is say a voltage: The voltage at any time may vary between 0 to 5
Volts. This is an “analogue” signal.
For electronic computers such as the PIC chip on the elab628, it is easier to have just 2
digits, such as 0 and 1. The circuit can then be either on or off, or maybe 0V or 5V.
This system of using just 2 digits is called the binary number system. The digits are
called bits (binary digits).
Just like decimal numbers, binary numbers are made larger by putting more digits
together. Below is a table of decimal number up to ten and their binary equivalents.
Decimal Binary
0 0
1 1
2 10
3 11
4 100
5 101
6 110
7 111
8 1000
9 1001
10 1010
Outputs
Output devices are used to communicate information. Personal computers use a video
display and printer. Microcontrollers use simpler devices such as lamps, light emitting
diodes (LEDs), opto couplers, relays, and switching transistors.
Relays, switching transistors and opto couplers are in turn used to interface to higher
power applications such as heaters, electric motors and solenoid devices.
17
This section for advanced classes
The output from an MCU is in the form of a digital signal (logic 0 or 1) placed on the
required port connection (I/O line). Sometimes the output of an MCU may need to be
translated into a corresponding analogue voltage level, in which case a digital to
analogue converter (DAC) is used.
+5v +9v
18
17
16
15
14
13
12
11
10
NC
relay
NO
PB1
PB2
PB3
PIC16F84 C
PIC16F628 390R B transistor
BC54
BC549
R1
E
1
2
3
4
5
6
7
8
9
LED
In figure 5, one pin of the output interfacing system used on the elab628 has been
illustrated (there are 8 similar pins). The elab628 has been designed with a dual
purpose. By soldering in the LEDs as provided in the basic kit, each I/O line of PORTB
is connected to a LED via a 390 Ohm resistor. This configuration allows the status of
PORTB pins to be displayed (i.e. an LED which is on indicates a logic 1). Each pin of
the PIC chip is able to source 20mA, which is ample for each LED. If the LEDs are
omitted, and the switching transistors are inserted instead, then each I/O line of PORTB
can be used to switch relays via the collector of the transistors as shown above. If you
wish to maintain the LED (light) while still operating a transistor then you must solder
an additional 390 ohm parallel with the corresponding resistor.
Assembly Language
The PIC microcomputer on the elab628 spends its time reading binary instructions
from the program memory, one after another, and doing whatever those instructions say.
Each instruction consists of 14 bits. If you could see the bits as binary ones and zeroes,
a program might look like this:
11000000000000
00000001100110
11000000000001
00000010000110
10100000000100
The earliest computers were programmed by skilled technicians writing binary codes
just like this. As you can see, though, binary codes are very hard for human beings to
comprehend as they do not represent the “normal” way that we communicate.
Another reason binary codes are hard to write is that many of them refer to locations in
memory. For instance, a "go to" instruction will have to say what memory address to
jump to. Programming would be much easier if you could label a location in the
program and have the computer figure out its address.
18
For both of those reasons, assembly language was invented over forty years ago. Or, to
be more precise, many assembly languages have been invented, one for each type of
CPU. What assembly languages have in common is that the instructions are abbreviated
by readable codes (mnemonics) such as GOTO, and locations can be represented by
programmer-assigned labels
19
Practical 2a
Starting your own program
Startup the CoreChart program, open the “program1.bst” file by clicking on File-
>Open.>drive>your folder “program1.bst”
Delete all icons between the “Start” icon and the “End” icon. The reason we are reusing
the file is because it contains the subroutine “delay”, which we need to use. Note that
you cannot delete the “label” icons until the “goto” icons have been deleted. Delete
these “goto” icons first, then the “label” icons, and lastly delete the other icons.
When completed
the screen should
look like this.
Note:
You can select
multiple icons by
holding the shift
key
20
Step 3: Save new file
You should now be looking at a blank area with just two icons “Start” and “End”.
Select a Text icon and a box will appear below, enter into it the program name
“;ON LED PROGRAM”. The description is “;To turn on a LED or relay”.
(Remember: each comment line should be preceded with a semicolon (;)). Save the
modified program as “on.bst” (File->Save As…).
Note
21
Step 4: Insert new instructions
Now we basically have a clear program. To add code to this program it is simply a
matter of putting code icons on the page. Start by inserting the following icons in
the order shown below.
Label Icon
Timing Icon
Goto Icon
Procedure
# 1 Select a Set/Reset Icon, in the Icon Properties box (look below icons)
22
Set the Goto drop down box to – Here
Place above end icon
Your screen
should look like
this
Save the program into your own folder and run it. Do this by selecting Options-
>Send to Pic or hit the <F9> shortcut key. When the program is run, the elab628
LED 0 should light up.
Set PORTB 1 ON
Save and recompile (Send to Pic), then run this and the next LED (1) should turn
on.
23
Step 7: Modify program
Set PORTB 0 ON
Save and recompile (Send to Pic), then run this and the LED’s 0 and 1 should turn on.
Now one at a time change the program by adding another port ie. B2, B3….
Practical 2b
Loops and Delays
Startup the CoreChart program, open the “on.bst” and save the program as
“onoff.bst” (File, Save as, Select your folder) and clear the icons like you did as
per Practical 1b (all icons between start and stop deleted).
Select the Text icon and add to the comments to include your name and the program
name “;ON /OFF LED FLASHER”. The description is “;To flash a LED or
relay”. Save the modified program
(Note: Each line in the Paste Text icon’s comments must begin with a semicolon “;”
otherwise an error will occur when you try to send it to the PIC chip).
New Icon
Assignment Icon
Call Icon
24
Step 3: Add new instructions
ICON PROPERTIES
Label here
Set PORTB 0 ON
Assignment w = 10
Call delay
Set PORTB 0 OFF
Assignment w = 10
Call delay
Goto here
Your program
should now
look like this
Save the program and send to the PIC chip as per Practical 1b. It should flash LED
0.
Change the program in step 3 by changing the value of W in the assignment icon to
a larger number, up to 255. Resave and send to the PIC chip. The LED should
flash slower since there is now a longer delay between changes to the on and off
states.
25
Extension Questions (required)
How does entering different values for “W” in each delay effect the timing?
How does adding another delay directly after the existing ones affect the result?
Also try making PORTB,2 or PORTB,3 flash and see what happens.
After successfully completing the above, go on to Practical 2c.
Practical 2c
Chasing LEDs
Startup the CoreChart program, open the “onoff.bst” and save the program as
“chase.bst” (file-save as).
Change the comments in the Paste Text icon to include your name and the program
name “;LED CHASER”. The description is “;To make the LEDs chase across”.
Save the program.
Modify
ICON PROPERTIES
Label here
Set PORTB 0 ON
Assignment w = 10
Call delay
Set PORTB 0 OFF
Assignment w = 10
Call delay
Set PORTB 1 ON
Assignment w = 10
Call delay
Set PORTB 1 OFF
Assignment w = 10
Call delay
Goto here
26
Your screen
should now
look like this
Save the program, send it to the PIC and run it. It should flash LED number 0 and
LED number 1 alternately.
Change the program in Step 3 by adding a third section with LED Number 2 also
turned on then off. Resaving and sending to the PIC should cause the LEDs to
chase from 0 to 1 then to 2.
Add in the rest of the LEDs and see if you can make them all chase each other.
27
More of what's Inside a PIC…the Memory
The figure below shows the most important parts inside the PIC16F628 device. As we
have seen, the PIC chip is a tiny but complete computer. It has a central processing unit
(CPU), program memory (PROM), working memory (RAM), and input-output ports.
As you can see from figure 6, the device is essentially a one-chip computer
The CPU is, of course, the ‘brain’ of the computer. It reads and executes instructions
from the PROM. As instructions are interpreted, it can store and retrieve data in RAM.
Some CPUs make a distinction between registers located within the CPU and RAM
located outside it; but the PIC chip does not. The general-purpose working RAM is also
known as ‘file registers’. On the PIC16F628, there are 224 bytes of general-purpose
RAM.
These file registers are defined automatically by CoreChart, and they configure the
assembler by putting it into PIC16F628 mode and defining variables. In CoreChart
variables can be added simply from the menu Variables and will automatically be
assigned the next free register.
The program memory of the PIC16F628 consists of flash EPROM; it can be recorded
and erased electrically, and it retains its contents when powered off. Many other PIC
chips require ultraviolet light for erasure, and some are not erasable. The PIC16F628,
however, is erasable and reprogrammable over 100,000 times.
28
Inputs and Outputs
There are two input-output ports, port A and port B, and each pin of each port can be set
individually as an input or an output. The bits of each port are numbered, starting at
zero. Figure 7 below shows PORTA, labelled RA0-RA7, and PORTB, labelled RB0-
RB7.
Input devices, known as sensors, supply information to the MC system from the outside
world. With a desktop PC system this is usually a keyboard and a mouse. In a
microcontroller system the inputs may be a number of different devices such as
switches, keypads or even a light sensor.
The input signal to the MC from a sensor is usually in digital form. More advanced
devices, such as the PIC16F877 chip on the elab877 development board, have the
ability to accept analogue signals since an analogue to digital converter is built into the
chip. Usually digital signals are at voltage levels near to that of the power supply rails.
In the case of the PIC16F628, a logic 0 is represented by 0 volts and a logic 1 by 5
volts.
Because MCU devices are CMOS in nature and have electrons as their major current
carrier, zero volts is referred to as the source (VSS) and the positive connection as the
drain (VDD).
+5v
18
17
16
15
14
13
12
11
10
RA1 RA0
R1
PIC16F84
PIC16F628
390R
PA2
PA3
CONNECTION
Figure 8 shows the circuitry for interfacing to PORTA of the elab628. By using this
arrangement, the I/O lines RA0 to RA7 can be used to either output or input a logic
signal. Resistor R2 has the effect of holding pin 1 (RA2) low (logic 0) to prevent the
29
voltage on it from floating. It also provides a load across which the output signal is
developed.
Alternatively, a logic signal can be input to the MCU by pulling pin 1 high. This
happens when the switch is pressed. Resistors R1 and R2 form a voltage divider
providing a voltage high enough on pin 1 to be read as logic 1. It is important that input
logic signals be kept within the device specifications i.e. 0 to 5 Volts.
By using this arrangement, the PORTA I/O lines on the elab628 have been set up for
the dual purposes of input and output.
Figure 9 below shows a similar process for setting PORTB to be used as both an input
and output. PORTB operates slightly differently to PORTA because the external circuit
is already on the elab628 board. This external circuit was shown previously in figure
5, part 2.
+5v +9v
18
17
16
15
14
13
12
11
10
NC
relay
NO
PB1
PB2
PB3
PIC16F84
PIC16F628 390R
transistor
BC54
R1
BC549
LED
1
2
3
4
5
6
7
8
9
Let us look more closely at how inputs and outputs are set on the ports.
Micro-controller Configuration
When you double click the “Start” icon in CoreChart, a window containing all the PIC
micro-controller configurations will be displayed (see figure 10).
30
Figure 10: PIC chip configuration window
By default, all the pins of PORTA (RA0 to RA7) are set as inputs.
In the OPTION Register, PORTB pull-ups (RBPU) are disabled and the prescaler rate
select bits (PS2 to PS0) are cleared (i.e. 0).
To change one of the settings in the CONFIG Word or OPTION Register, move the
mouse icon over one of the boxes or radio buttons provided and left click the mouse. A
tick or a dot indicates that the particular bit is selected.
To deselect the bit, move the mouse icon over one of the selected boxes or radio buttons
you want to deselect and left click the mouse .
You can also configure the input/output pins of PORTA and PORTB with the similar
procedure described in the previous paragraphs. (Note: An arrow pointing towards the
PIC microchip stands for an input, whereas an arrow pointing away from the
microchip indicates an output).
31
Practical 3a
Startup the CoreChart program, open the “program1.bst” and delete all the icons
between start and end, then save as “press.bst” (use the procedure from Practical
1b).
Insert a paste text icon and include your name and the program name “PRESS ON
LED” the description is “To turn on a LED or relay by pressing a button”.
Save the modified program.
ICON PROPERTIES
Assignment w = 7
Assignment CMCON = w
Label Here
Set PORTB 0 OFF
If PORTA 5 OFF
Set PORTB 0 ON
Call Delay
Goto Here
Save the program and send it to the PIC chip, it should now light up LED 0 when
the button is being pressed.
Change the program in step 4 by inserting “call delay” before the IF icon. Resaving
and sending to the PIC should now cause the LED to flash when the button is
pressed. Can you work out why?
(Answer: It is because there is now the LED is turned off for a short delay period,
instead of being turned on again instantly as was the case before).
Try changing the program so it switches on and off the Peizo buzzer on PORTA, 3
when the button is pressed. Make a note of what happens. (Hint: Change the bit
that gets turned on and off in the last program).
32
Practical 4a
Startup the CoreChart program, open the “program1.bst” and delete all the icons
between start and end, then save as “walk.bst” (use the procedure from Practical
1b).
Insert a paste text icon and include your name and the program name “ROBOT
WALK” the description is “Making the robot walk by pressing a button. Using
binary numbers in the program”. Save the modified program.
ICON PROPERTIES
Set PORTB 0 ON
Timer Clear Watchdog
If PORTA 5 ON
Goto Start
Assignment w = b’11010100’
Assignment PORTB = w
LED 0 should be lit and wait for the push button to be pushed for the walk to
start. The eyes of the robot also should be lit.
At this point it is a good idea to look at the full set of PIC Instructions. The advantage
of the PIC16F series is that there are only 35 instructions. Every instruction that does
not involve a jump executes in just one clock cycle. Thus, the PIC qualifies as a form of
RISC processor (reduced instruction set computer). By contrast, the Pentium has
hundreds of instructions, each of which takes several clock cycles to execute. This
makes the Pentium a CISC processor (complex instruction set computer).
In order to simplify the PIC instruction set, and limit instructions to one clock cycle,
there is no “if” statement. Instead, the PIC has several instructions that test for a
condition and skip the next instruction if it is true. An example of how this works is
demonstrated below.
33
ICON PROPERTIES
IF PORTA Bit 0 OFF
Goto m1
Assignment w = 10
ICON PROPERTIES
IF PORTA Bit 0 OFF
Goto m1
Calculate PORTB =>> PORTB
Goto m2
LABEL m1
Calculate PORTB =<< PORTB
LABEL m2
rotate the bits of PORTA to the left if A0=1 and to the right if A0=0.
When a calculation is made, the STATUS register records if the result was zero (Z) or it
overflowed (C) past the 8 bits of one register. The carry bit (C) can also indicate if a
result was positive or negative. The STATUS register is 8 bits long, and is used to
select register banks, as well as check on whether there has been a power-down or time-
out.
Technical Help…
The Microchip Technical Data Sheet…
see the “Technical Data” directory on the CD
elabtronics: www.elabtronics.com email: tech@elabtronics.com
Microchip website: www.microchip.com
End of Document
34