Chapter 3 Introduction to PIC Microcontroller – Part 1

russianharmoniousElectronics - Devices

Nov 2, 2013 (3 years and 9 months ago)

96 views

KHAN WAHID
2010-11 (Term 1)
EE331 Microprocessor
Chapter 3
Introduction to PIC
Introduction to PIC
Microcontroller
Microcontroller


Part 1
Part 1
Dr. KHAN WAHID
2010-11 (Term 1)
2EE 331: Microprocessor
Chapter Objectives

This chapter covers

General microcontroller and microprocessor
architecture

PIC16F84A MCU architecture

Fetch and Execute units: PC, ID, ALU, Stack,
Program Store, Data Store, Status Register, etc.

Peripherals: Oscillator, Timer, I/O Ports, Data
EEPROM, etc.

Problem solving
Dr. KHAN WAHID
2010-11 (Term 1)
3EE 331: Microprocessor
General Microcontroller Architecture

Microprocessors (MPU) and microcontrollers (MCU) are
different

MPU is general purposein nature, and generally contains
only CPU on one chip

MCU is basically a microprocessor, memory, timers, I/O
ports, etc. –all on one chip

MCU is less flexible than MPU as it has fixed amount of memory and
internal peripherals

MCU is a complete system on one chip, hence, normally used in
embedded systems

We can at any time build our own flexible MPU-based system by adding
external chips to MPU
Dr. KHAN WAHID
2010-11 (Term 1)
4EE 331: Microprocessor
Basic Microprocessor Architecture

A Microprocessor Unit (MPU)
consists of 6 basic
components:

Arithmetic logic unit (ALU)

Accumulator (or Working Reg)

Instruction decoder

Control unit

Memory/Registers

Internal system bus
Dr. KHAN WAHID
2010-11 (Term 1)
5EE 331: Microprocessor
Basic Microprocessor Architecture

Arithmetic logic unit (ALU)

Performs arithmetic(e.g. add, sub, etc.)
and logic operations(e.g. AND, OR,
etc.)

**Accumulator (or Working
Register)

The accumulator is usually the register
that is used in all ALU operations

When data is sent from the MPU to
external worldor received from the
external world to the MPU, it normally
goes out or comes into from the
accumulator via data bus
Dr. KHAN WAHID
2010-11 (Term 1)
6EE 331: Microprocessor
Basic Microprocessor Architecture

Instruction decoder

Decodes the instructions(it receives
over the internal data bus) at a binary
level, and sends the appropriate signals
to the control unit

Control unit

Performs the operation as instructed

Sends data to the appropriate internal
section

Also sends out any needed control
signals externally to the MPU over the
control bus to external devices(e.g.
memories, I/O, etc.)
Dr. KHAN WAHID
2010-11 (Term 1)
7EE 331: Microprocessor
Basic Microprocessor Architecture

General purpose registers (GPR)

Used by the MPU for data storage

The size and number vary depending upon
specific MPU type

Special function registers (SFR)

Accumulator

Program counter (PC)

Instructions are normally stored
sequentially in program memory, and PC
is the counter register that keeps track of
the current instruction

A simple binary up counter

PC always contains only the memory address of the next instruction to
be executed

Sometimes, referred as Instruction pointer
Dr. KHAN WAHID
2010-11 (Term 1)
8EE 331: Microprocessor
Let us explore the ALU-Accumulator…

Add two 8-bits words: A + B

Recall 74LS382
Dr. KHAN WAHID
2010-11 (Term 1)
9EE 331: Microprocessor
8-bit ALU-Accumulator Processor

Add two 8-bits words: A + B
Dr. KHAN WAHID
2010-11 (Term 1)
10EE 331: Microprocessor
8-bit ALU-Accumulator Processor

Let us give a system look of the ALU-Accumulator
(from program
memory)
(from data
memory)
Q. Can you add two 16-bits numbers
using this hardware architecture?
Dr. KHAN WAHID
2010-11 (Term 1)
11EE 331: Microprocessor
Microcontroller –Putting it all together 
For a real application, a
microcontroller alone is not
enough; besides it needs a
program that would be executed
Dr. KHAN WAHID
2010-11 (Term 1)
12EE 331: Microprocessor
Freescale68HC908 Microcontroller
Dr. KHAN WAHID
2010-11 (Term 1)
13EE 331: Microprocessor
Other Microcontroller
Block diagram of an MC6811 microcontroller
Dr. KHAN WAHID
2010-11 (Term 1)
14EE 331: Microprocessor
PIC12F508/509 Microcontroller
Dr. KHAN WAHID
2010-11 (Term 1)
15EE 331: Microprocessor
PIC16F84A vs. PIC12F508/509
Learn ONE, learn ALL
Dr. KHAN WAHID
2010-11 (Term 1)
16EE 331: Microprocessor
MCU –Programming
Programming can be done in several
languages,such as Assembly, C and BASIC,
which are the most commonly used
languages

Assembly belongs to lower level languages
that is programmed slowly, but takes up the
least amount of space in memory and gives
the best results

Programs in C language are easier to be
writtenand understood, but are slower in
executingfrom assembly programs

BASIC is the easiest one to learn, and its
instructions are nearest a human's way of
reasoning, but like C language, it is also
slower than assembly
Dr. KHAN WAHID
2010-11 (Term 1)
17EE 331: Microprocessor
MCU –Compile /Assemble
Compile:translation
from the high level source
code to assembly code
Assemble:translation from the assembly
code to the target machine code
Both compiler and assembler are machine (and vendor)
specific (e.g., PIC assembler won't work with ARM)
Dr. KHAN WAHID
2010-11 (Term 1)
18EE 331: Microprocessor
Example –Car Odometer
Consider a car odometer monitoring system that displays
two things: (a) total distance since manufactured and (b) a
trip odometer
Resource Budget (List of subsystem):
1. An edge-triggered input for the tachometer pulse train to
add up engine revolutions
2. Gear ratio, mi/km option and trip reset
3. Four output digital lines to clock the two shift registers
and provide segment data
4. An MPU to do the calculations and to read/write to the
input/output ports
5. Program memory, usually ROM of some kind
6. Data memory for temporary storage of program
variables, usually static RAM
7. Non-volatile memory to store physical variables
Any improvements? (SAQ3.5)
Any improvements?
(SAQ3.6)
Dr. KHAN WAHID
2010-11 (Term 1)
19EE 331: Microprocessor
E3.1 –Greenhouse Environment Controller
A greenhouse controller is to monitor an analog signal from a soil moisture
probe and if below a certain value turn on a water valve for 5 seconds and
off for 5 seconds.
Resource Budget (List of subsystem):
1. An input for an external oscillator, connected to a counter/timer
to allow the MCU to calculate time. In practice the system clockcan
often be used by this internal timer to measure duration.
2. A 1-input analog input line to measure the analog signal from the
moisture detector
3. A 1-input digital line to check the level of the reservoir water tank
4. A 1-output digital line to open and close the water valve
5. A 1-output digital line to activate the buzzer alarm
6. A microprocessor to do the calculations and to read/write to the
input/output ports, respectively
7. Program memory, usually ROM of some kind
8. Data memory for temporary storage of program variables, usually
static RAM
E3.2 –MCU controlled robot to cross a road, pp. 63-67
Dr. KHAN WAHID
2010-11 (Term 1)
20EE 331: Microprocessor
Microchip and PIC MCU

Peripheral Interface Controller (PIC)

PIC was originally a design of General Instruments (now Motorola
Connected Home Solutions)

Microchip (formed in 1989) developed their first 8-bit Harvard
architecture MCU –PIC16C5xx

All MCUsare low-cost, self-contained, Harvard arch, pipelined,
RISC, single accumulator, with fixed reset and interrupt vectors
PIC Family
Stack size
(words)
Instruction
Word size
Number of
Instructions
Interrupt
Vectors
12CXXX/12FXXX 2 12 or 14-bit 33 None
16C5XX/16F5XX 2 12-bit 33 None
16CXXX/16FXXX 8 14-bit 35 1
17CXXX 16 16-bit 58, including
hardware multiply
4
18CXXX/18FXXX 32 16-bit 77, including
hardware multiply
2 (prioritised)

Dr. KHAN WAHID
2010-11 (Term 1)
21EE 331: Microprocessor
Microchip and PIC MCU
Dr. KHAN WAHID
2010-11 (Term 1)
22EE 331: Microprocessor
Microchip and PIC MCU
PIC16F84A
Dr. KHAN WAHID
2010-11 (Term 1)
23EE 331: Microprocessor
Pin no.1 RA2Second pin on port A.
Pin no.2 RA3Third pin on port A.
Pin no.3 RA4Fourth pin on port A. TOCK1 which functions as
a timer is also found on this pin.
Pin no.4 MCLRReset input and Vppprogramming voltage of a
microcontroller.
Pin no.5 VSSGround of power supply.
Pin no.6 RB0Zero pin on port B. Interrupt input is an additional
function.
Pin no.7 RB1First pin on port B.
Pin no.8 RB2Second pin on port B.
Pin no.9 RB3Third pin on port B.
Pin no.10 RB4Fourth pin on port B.
Pin no.11 RB5Fifth pin on port B.
Pin no.12 RB6Sixth pin on port B.
Pin no.13 RB7Seventh pin on port B.
Pin no.14 VDDPositive power supply pole.
Pin no.15 OSC2Pin assigned for connecting with an oscillator.
Pin no.16 OSC1Pin assigned for connecting with an oscillator.
Pin no.17 RA2Second pin on port A.
Pin no.18 RA1First pin on port A.
PIC16F84A Microcontroller (8-bit)
18
Pin Count
2 to 6
Operating Voltage Range (V)
-40 to 85
Temperature Range (C)
1 x 8-bit
Timers
64
Data EEPROM (bytes)
68
RAM Bytes
5
CPU Speed (MIPS)
1.75
Program Memory (KB)
Flash
Program Memory Type
Value
Parameter Name
Dr. KHAN WAHID
2010-11 (Term 1)
24EE 331: Microprocessor
PIC16F84A Microcontroller (8-bit)

Block diagram from the manufacturer’s data sheet
A good understanding
of the block diagram
leads to an ability to
designwith the
microcontroller, and to
program it.
7
Dr. KHAN WAHID
2010-11 (Term 1)
25EE 331: Microprocessor
PIC16F84A Microcontroller (8-bit)

Block diagram from
the textbook for
better understanding

Let’s explore inside
and look at the
components one by
one…
Dr. KHAN WAHID
2010-11 (Term 1)
26EE 331: Microprocessor
System-look of ALU-Accumulator

Now let’s extend the ALU-Accumulator (add other
components)
IR
/ ID
Dr. KHAN WAHID
2010-11 (Term 1)
27EE 331: Microprocessor
MPU: State Machine

An MPU needs a set of instructions to follow that
tells itwhat operations to perform on what data

It fetches the first instruction from a designated area
in its memory

Loads it into instruction register

Decodes it and executes that operation

This sequence of fetch, decode and execute is
continued until instructed to “stop”
Dr. KHAN WAHID
2010-11 (Term 1)
28EE 331: Microprocessor
MPU: Fetch-Decode-Execute
Example:
Num_2 = Num_1 + 4
=> D[26] = D[25] + 4
IR
Dr. KHAN WAHID
2010-11 (Term 1)
29EE 331: Microprocessor
Program Store

Example: Num_2 = Num_1 + 4
00100000100101
11111000000100
00000010100110
movf25, w
addlw4
movwf26
Mnemonics
(Assembly)
Machine code
(program store
content, 14-bits)
0825
3E04
00A6
Hexadecimal
10-bit address
Dr. KHAN WAHID
2010-11 (Term 1)
30EE 331: Microprocessor
MPU: Fetch-Decode-Execute
The Quintessential PIC
Microcontroller: pp. 49-57
Basic All-purpose Stored
Instruction Computer (BASIC)
Example:
Num_2 = Num_1 + 4
=> D[26] = D[25] + 4
(14-bits)
(8-bits)
??
??
??
??
Dr. KHAN WAHID
2010-11 (Term 1)
31EE 331: Microprocessor
(14-bits)
(8-bits)
MPU: Fetch-Decode-Execute
movf25, w
Move contents of File
h’25’into w(working
register)
Example:
Num_2 = Num_1 + 4
=> D[26] = D[25] + 4
Dr. KHAN WAHID
2010-11 (Term 1)
32EE 331: Microprocessor
(14-bits)
(8-bits)
MPU: Fetch-Decode-Execute
addlw04Adds literal (i.e., a constant)
“04”to w and save into w
Example:
Num_2 = Num_1 + 4
=> D[26] = D[25] + 4
movwf26Move the contents of w
into File h’26’(save
results)
Dr. KHAN WAHID
2010-11 (Term 1)
33EE 331: Microprocessor
2-Stage Pipelining

BASIC architecture is divided into
two parts

Any execution of “memory access”
will be on the Data store and each
store has its own bus

the fetch and execution processes
can progress in parallel

Pipelining: While instruction n is
being fetched, instruction (n −1) is
being executed (see SAQ3.3)
Dr. KHAN WAHID
2010-11 (Term 1)
34EE 331: Microprocessor
2-Stage Pipelining

The instruction codes for both the current and the immediate next instructions
are held in the two Instruction registers IR2 and IR1 respectively

During each cycle, except for the first, one fetch and one execution are
proceeding simultaneously
Let’s explore in more details…

BASIC architecture is divided into
two parts

Any execution of “memory access”
will be on the Data store and each
store has its own bus

the fetch and execution processes
can progress in parallel
current
next
Dr. KHAN WAHID
2010-11 (Term 1)
35EE 331: Microprocessor
2-Stage Pipelining

Assume that, the PC has been reset to h’000’
and has just finished the Cycle 1 (Fetch)

Cycle 2 (Fetch)

Increment PC (h’001’) to point to inst 2

Simultaneously move the inst word 1 down the
pipeline from IR1 to IR2

PC (h’001’) to the Program store’s address bus

The inst word 2 then appears on the Program
store’s data bus and is loaded into IR1

Cycle 2 (Execute)

The operand address h’25’moves to the FAR
and out onto the FA bus

The content is read onto the Data store’s data
bus and loaded into the FDR

The ALU is configured to the Pass Through
mode, which feeds the data through to the
Working register
Dr. KHAN WAHID
2010-11 (Term 1)
36EE 331: Microprocessor
2-Stage Pipelining

Cycle 3 (Fetch)

Increment PC (h’002’) to point to inst 3

Simultaneously move the inst word 2 down
the Pipeline from IR1 to IR2

PC (h’002’) to the Program store’s address
bus

The inst word 3 then appears on the
Program store’s data bus and is loaded into
IR1

Cycle 3 (Execute)

The ALU is configured to the Add mode
and the literal (which is part of inst word 2)
is added to the data in W

The ALU output, (NUM_1 + 4), is placed
in W
Dr. KHAN WAHID
2010-11 (Term 1)
37EE 331: Microprocessor
2-Stage Pipelining

Cycle 4 (Fetch)

Increment PC (h’003’) to point to inst 4

Simultaneously move the inst word 3 down the
Pipeline from IR1 to IR2

PC (h’003’) to the Program store’s address bus

The inst word 4 then appears on the Program
store’s data bus and is loaded into IR1

Cycle 4 (Execute)

The operand address (i.e., NUM_2) h’26’to the
FAR and out onto the FA bus

The ALU is configured to the Pass Through
mode, which feeds the contents of W through to
the FDR and onto the Data store’s data bus

The data in the FDR is written into the Data
store at the address on the Data store’s address
bus and becomes the new data in NUM_2
Self-study: Example 4.1 (pp. 90-91)
Q. How many cycles are needed to
perform “Fetch”and “Execute”?
Dr. KHAN WAHID
2010-11 (Term 1)
38EE 331: Microprocessor
2-Stage Pipelining

In PIC MCU, each
instruction takes 4
clock cycles to execute

Q1: Decode

Q2: Read

Q3: Process

Q4: Write To
Dr. KHAN WAHID
2010-11 (Term 1)
39EE 331: Microprocessor
PIC: Instruction Set

Two categories of Instructions:

File Direct

Literal

File Direct

Instructions that specify the File address
where their target operand is locateduse
this type of addressing;

e.g., movfh’25’,w designates File h’25’
as the target
001000
Dr. KHAN WAHID
2010-11 (Term 1)
40EE 331: Microprocessor
001000
Instruction Set: File Direct

The leftmost six bits(#13 through #8): operation code, or op-code

Every instruction has a unique op-code, and it is this pattern that the decoding
circuits use to define what type of instruction it is

The middle bit(#7) labeled d defines the
destination of the outcome

If the destination is W and the d bit is 0

addwfh’30’, w

If the destination is F and the d bit is 1

addwfh’30’, f
addwfh’30’, w
w
h’30’
Before execution:xy
After execution:x+yy
addwfh’30’, f
Before execution:xy
After execution:xx+y
Dr. KHAN WAHID
2010-11 (Term 1)
41EE 331: Microprocessor
001000
Instruction Set: File Direct

The leftmost six bits(#13 through #8): operation code, or op-code

Every instruction has a unique op-code, and it is this pattern that the decoding
circuits use to define what type of instruction it is

The middle bit(#7) labeled d defines the
destination of the outcome

If the destination is W and the d bit is 0

addwfh’30’, w

If the destination is F and the d bit is 1

addwfh’30’, f

The rightmost seven bits(#6 through #0) define
the File address

E.g. File h’25’is b’010_0101’

Only a bank of 27
= 128 Files can be directly
addressed; that is File 00 through File h’7F’
Dr. KHAN WAHID
2010-11 (Term 1)
42EE 331: Microprocessor
Instruction Set: Literal

The lower 8-bit zoneis the byte constant itself

The outcome is always in the Working register
and so there is no need for a destination bit nor
Data store address

The literal is limited to the range b’00000000’–
b’11111111’(h’00’–h’FF’, or decimal zero
through 255),

Remember, the Working register is only 8-bits
wide

The leftmost six bits(#13 through #8): operation code, or op-code

Every instruction has a unique op-code, and it is this pattern that the decoding
circuits use to define what type of instruction it is
Dr. KHAN WAHID
2010-11 (Term 1)
43EE 331: Microprocessor
PIC16F84A

Let us now extend the
BASIC architecture
(discussed earlier) to
PIC16F family…

Two parts in common:

Fetch unit

Execute unit
Dr. KHAN WAHID
2010-11 (Term 1)
44EE 331: Microprocessor
Fetch Unit

Primarily concerned in fetching
instructions down into the
Pipeline from the Program store

Program Store (16F84A)

Flash EEPROM type

1024 (1k) instructions can be
stored (8192 instructions in
PIC16F876/7)

14-bit long instruction
6
Dr. KHAN WAHID
2010-11 (Term 1)
45EE 331: Microprocessor
Fetch Unit –Program Store
Primarily concerned in fetching
instructions down into the
Pipeline from the Program store

Program Store (16F84A)

Flash EEPROM type

1024 (1k) instructions can be
stored (8192 instructions in
PIC16F876/7)

14-bit long instruction
Dr. KHAN WAHID
2010-11 (Term 1)
46EE 331: Microprocessor
Fetch Unit –Program Counter
Program Counter

13-bit registernormally increments after
each fetch, effectively acting as a binary
counter

However, there are a few instructions, (such
as goto, call) that will cause execution of
the program to jump to another part of the
Program store

Thus PC’s normal up count can be
overridden

If the program attempts to go to any
instruction above 1024, the address will
wrap around back to address zero
6
Dr. KHAN WAHID
2010-11 (Term 1)
47EE 331: Microprocessor
Fetch Unit –Program Counter
Program Counter

In all cases the PC will be cleared
on a reset; that is, the first
instruction is always in location
h’000’(reset vector)

In 16F84A, out of the 13-bits, only
the lower 10-bits are physically
connected(hardwired)

PIC16F628 uses 11-bits (211
= 2K),
16F874 uses 12-bits (2
12
= 4K), 16F877
and 16F886 uses all 13 bits (2
13 = 8K)
Dr. KHAN WAHID
2010-11 (Term 1)
48EE 331: Microprocessor
6
Fetch Unit –Instruction Decoder
Instruction Decoder

uses logic circuitry to decode the 6-bit
op-code of the 14-bit instruction

gates the appropriate addresses and data
to the correct execution unit’s circuitry

configures the ALU

All PIC MCU have an internal
circuitry to generate time-related
sequencesof operations commanded
by the Instruction Decoder

Note that, 16F84A does not have on-
chip oscillator
Dr. KHAN WAHID
2010-11 (Term 1)
49EE 331: Microprocessor
Fetch Unit –Instruction Decoder
The oscillator is frequency-divided
as to give four internal non-
overlapping quadratureclocks
Q1: Decode

Q2: Read

Q3: Process

Q4: Write To

A consequence is that an instruction
cycletakes fourexternal clock periods
(1/fosc)to complete

Example:with a 4MHz crystal, the
instruction cycle rate is f
osc
/4, or 1MHz
=> 1 instruction takes 1us (4/f
osc) to
complete
Dr. KHAN WAHID
2010-11 (Term 1)
50EE 331: Microprocessor
Building Clock Oscillator

Needs

One Mod-4 counter

One 2:1 decoder
Dr. KHAN WAHID
2010-11 (Term 1)
51EE 331: Microprocessor
7
Data Flow inside 16F84A

movfh’25’, w
001000_0_0100101
001000_0_0100101
001000
0100101
ffffffff
d=0d=1
Dr. KHAN WAHID
2010-11 (Term 1)
52EE 331: Microprocessor
7
Data Flow inside 16F84A

addlwh’04’
111110_00000100
111110_00000100
111110
00000100
d=0d=1
Dr. KHAN WAHID
2010-11 (Term 1)
53EE 331: Microprocessor
7
Data Flow inside 16F84A

movwfh’26’
000000_1_0100110
000000_1_0100110
000000
0100110
ffffffff
d=0d=1
Dr. KHAN WAHID
2010-11 (Term 1)
54EE 331: Microprocessor
MCU Elements –Oscillator
Some MCUshave on-chip oscillator that
supplies synchronized clock pulses

Ensures harmonic and synchronous operation
of all circuits of the microcontroller

Usually configured to use quartz crystal or
ceramic resonator for frequency stabilization

Instructions are not executed at the rate
imposed by the oscillatoritself, but several
times slower (do you remember WHY?)

Because each instruction is executed in several steps

In some MCU, the same number of cycles is needed to execute any
instruction, while in others, the execution time is not the same for all
instructions
Dr. KHAN WAHID
2010-11 (Term 1)
55EE 331: Microprocessor
Clock Oscillator and Instruction Cycle

Some popular clock frequencies for PIC16
series

For the fastest clock frequency, 20 MHz
(the instruction cycle freq. is 5 MHz =>
5,000,000 instructions per sec; period of
200 ns)

The slightly cheaper version of the controller, the 16F84-04, with
maximum clock frequency of 4 MHz (1 us)
Simple timing applications, using software delay loops and the counter/timer

A popular clock frequency is 32.768 kHz (122.07 us)
The result is very low power, but strictly no high-speed calculations!

E.g., digital clock, wristwatches (WHY used?)
http://seng.ulster.ac.uk/eme/sidk/quintessential/Chapters_2ed/Chapter4/ch4_9_2.htm
Dr. KHAN WAHID
2010-11 (Term 1)
56EE 331: Microprocessor
Clock Oscillator

Two types of oscillator circuit in
common use in microcontrollers

Resistor-Capacitor, P= CV
2f

See notes for details

Crystal Oscillator
Depends on the piezo-electric properties of
quartz crystal

Any mechanical distortion of the material
causes a voltage to be produced across
opposite sides of it; similarly, if a voltage
is applied to the material, a mechanical
distortion results

Crystal vibration occurs at a fixed and
remarkably stable frequency–a great
advantage
Dr. KHAN WAHID
2010-11 (Term 1)
57EE 331: Microprocessor
PIC16F84A Clock Oscillator

Four different oscillator modes, allowing implementation of RC, crystal or
ceramic oscillators, and external clock source

Selected by user: “Configuration Word”

RC –resistor–capacitor

An external R-C must be connected to pin 16. This is the lowest cost way of getting an
oscillator, but should not be used when any timing accuracy is required.

LP –low power

This mode is intended for low-frequency crystal applications (up to 200kHz) and gives
the lowest power consumption possible.

XT –crystal

This is the standard crystal configuration (1MHz –4MHz)

HS –high speed

This is a higher drive version of the XT configuration (4MHz –20MHz). It recognizes
that higher frequency crystals, and ceramic resonators in general, require a higher drive
current. It leads to the highest current consumption of all the oscillator modes.
Dr. KHAN WAHID
2010-11 (Term 1)
58EE 331: Microprocessor
PIC16F84A Clock Oscillator

Four different oscillator modes, allowing implementation of RC, crystal or
ceramic oscillators, and external clock source

Selected by user: “Configuration Word”
Pin 15
Pin 16
Dr. KHAN WAHID
2010-11 (Term 1)
59EE 331: Microprocessor
Problems (E10.1, SAQ10.2)
Q. Find out fosc
Dr. KHAN WAHID
2010-11 (Term 1)
60EE 331: Microprocessor
PIC16F84A Clock Oscillator
Fig. Typical supply current vs. Clocking frequency
All PIC MCU families feature a Sleep mode which
effectively turns off the internal clock oscillator=>
using sleepinstruction.
Once asleep, the contents of the Data store are
retained provided that the supply voltage remains
above 1.5V (VDR in the Data sheet).
The PIC MCU can be awakened either by resetting
the device, by an enabled interrupt request, or if the
enabled Watchdog timer overflows. [SID –pp. 277]
Dr. KHAN WAHID
2010-11 (Term 1)
61EE 331: Microprocessor
Basic Microprocessor Architecture

Special function registers (SFR)

Stack pointer

A last in, first out (LIFO) special
memory structurecharacterized by
only two operations –push and
pop

At any given time, the SP holds
the address of the next free
location in the stack
Dr. KHAN WAHID
2010-11 (Term 1)
62EE 331: Microprocessor
PIC16F84A –8-level Stack
Eight 13-bit registers are stacked
below and are connected to the PC

Used to hold past states of the PC to
“remember”the jumping-off point when
a subroutine is called up

Also used for gotoinstruction

No pushand pop instructions in 16F84A

Details to follow…
Call subroutine(pushPC to stack)
Return from subroutine(pop PC
from stack)
Dr. KHAN WAHID
2010-11 (Term 1)
63EE 331: Microprocessor
PIC16F84A Microcontroller

We have so far
discussed the Fetch
unit

Now let us look into
the Execute unit
Dr. KHAN WAHID
2010-11 (Term 1)
64EE 331: Microprocessor
Acknowledgments

These slides have been prepared by Khan Wahid and may
contain material copyrighted by:

The Quintessential PIC®Microcontroller, Sid Katzen, 2nd edition,
2005, ISBN: 978-1-85233-942-5

Designing Embedded Systems with PIC Microcontrollers:
Principles and Applications, Tim Wilmshurt, 2007, ISBN: 978-
0750667555

PIC16F84A Data Sheet, 35007b, Microchip Technology Inc.

Microprocessors/Microcontrollers –Course Notes, Delmar
CengageLeaning, ISBN: 1435453816

PIC Microcontroller and Embedded Systems using Assembly and
C for PIC18, Mazidi, Mckinlay, Causey, 2008

PIC Microcontrollers, Milan Verle, free online
(www.mikroe.com/en/books/picmcubook/
)