Programming PIC
Programming PIC
Micro Controller
Computer Organization
CS 140
CS140 - Lab03 1
The Lab - Overview
In the last labs, you learned how to program the PIC Microcontroller running on the
Demo Board. You could write a bit of new code, and you could explain what
various Assembly instructions do. You also had a general idea of how to read
the hardware specification.
But first, we’re going on a major detour introducing you to some new concepts.
These concepts include:
a. A new demo board.
b. A new PIC Processor.
c. TTL Logic.
d. Wiring up the Chip.
e. Code to drive and test this logic.
CS140 - Lab03 2
The Demo Board
POT
General factoids:
This is called the “28-pin
Demo Board”.
It’s described here.
It uses the PIC processor
16F886. The spec for this
chip is here.
RB6, RB7
MCLR
Don’t mess with
these three pins.
Switch
Connector
3 RA1 RB5 26
The voltage generated by Switch
4 RA2 RB4 25
the “Pot” is sensed by RA0
and is converted from an 5 RA3 RB3 24
analog to a digital signal.
6 RA4 RB2 23
7 RA5 RB1 22
8 Vss RB0 21
+5V
9 RA7 Vdd 20 LED
Note that for each of the devices (Chip driver/reader), Switch, LED;
there’s a routine to configure and one to read/write as appropriate.
CS140 - Lab03 10
The Logic Chips
You will be amazed how useful your book is for this part. Of particular
interest is the book’s description of three kinds of chips. I’ve provided
an overview of the chip-type, examples of that type I will give you,
and examples of chips I might ask you to wire up for show and tell.
Chip Type Provided For Practice For Show and Tell?
Finding out more: The appendix of this document contains some information about these
chips. Otherwise, Google can be your friend. (Search on “TTL” + Chip number)
These chips were made originally by Motorola, Fairchild, Texas Instruments, and now
by many vendors.
CS140 - Lab03 11
Task 1: Code for Reconfiguration
The code that’s been given to you for this project assumes that the switch
is being read at RB5. Test the circuit to make sure this works for you.
During show and tell, I’m going to move the switch wire to some other
input pin – I can be devilish in this activity. ☺
Your task will then be to make this starter code work.
You can practice this before show and tell. Try it at different locations
and see what happens. A good set of sample/practice locations
would be:
RB5 – where it is configured now in the sample code.
RA2 – make sure you turn off analog inputs.
RC1 – especially devilish since that then requires you to reconfigure the
code that you’re using to drive the logic chip in the starter code.
Note: I can’t use RB0 – RB3 – that’s where the LEDs are located.
Nor can I use RA0 since the Pot is on that pin.
Also MCLR, RB6, RB7 are off limits because of debugging constraints.
You will have a set of others chips to practice on; and then at show and
tell time, you will demonstrate your prowess with chip testing.
You will have a choice of what type of chip to test, and you will then wire
up that chip on the board and produce code that can run that chip.
The chip you will get will be one of those listed on a previous page
labeled “For Show and Tell”. By all means, practice on the six chips
provided in order to understand how they work. Get together with
your buddies if you wish. Learn all you want about the Show and Tell
chips though you won’t be able to practice on them beforehand.
By The Way: Task 1 and Task 2 are independent of each other – you
can wire the switch wherever you want for Task 2.
Task 1:
1. Starting with the code for ChipDriver.asm, the wire for the switch will
be put on some other pin of the microcontroller. You can successfully
modify ChipDriver.asm to make the modified board run successfully.
Task 2:
1. The risk of your chip is Low Medium.
2. You correctly wire your chip, remembering the switch, +5V and ground
for the chip, stimuli wires INTO the chip, response wires OUTOF the
chip.
3. Your code can get one of the states (in and out) to work and the LED
to display what is happening.
CS140 - Lab03 16
Appendix – Logic Gates
CS140 - Lab03 17
Appendix – Combinational
74LS42 74LS85
74LS85
74LS42 This is a Decoder
4-bit Magnitude Comparator
One of Ten Decoder
CS140 - Lab03 18
Appendix – Combinational
This is a Decoder
74LS138
3 to 8 line decoder
(multiplexer)
CS140 - Lab03 19
Appendix – Combinational
CS140 - Lab03 21
Appendix – Combinational
This will be interesting and fun to program. Getting
the whole thing to work would be a big job, but I
might ask you to program the two examples below.
74LS283
74LS283
4-bit full adder
CS140 - Lab03 22
Appendix – Combinational
74LS164
8-bit shift register
CS140 - Lab03 23
Appendix – Sequential
74LS112
74LS93
Dual JK Negative Edge Flip Flop
Binary Counter
CS140 - Lab03 24
Appendix – Sequential
74LS174
Hex D Flip Flop
CS140 - Lab03 25
Appendix – Sequential
74LS194
4-bit bidirectional shift register
CS140 - Lab03 26
Appendix – Sequential
74LS374
Octal D-type latch
CS140 - Lab03 27