Download as pdf or txt
Download as pdf or txt
You are on page 1of 41

BFM3333 Course:

MICROCONTROLLER SYSTEM
L4: PIC16 ARCHITECTURE 1
L4: Lesson outcome

- To recognize the basic structure of microcontroller


PIC16
- To understand the principle of work for these parts in
PIC16 microcontroller
LECTURE OUTLINES

- Introduction
- The PIC16 Basic Features
- PIC16 Internal Components
- CPU
- Control Unit
- ALU Unit
- Program Memory
- Data Memory

3
Introduction

v Studying of architecture will contain the following things:


v The basic components inside the PIC16 microcontroller.
v The pins on the PIC16 microcontroller and their function
v Flow of the data inside PIC16 microcontroller
v Programming of PIC Microcontroller to do certain tasks
v PIC Microcontroller architecture is based on Harvard architecture
and supports RISC architecture (Reduced Instruction Set
Computer). PIC microcontroller architecture consists of memory
organization (ram, rom, stack), CPU, timers, counter, ADC, DAC,
serial communication, CCP module and I/O ports. PIC
microcontroller also supports the protocols like CAN, SPI, UART
for interfacing with other peripherals.
v PIC16 belongs to a class of 8bit microcontrollers with RISC
architecture
4
The PIC16F887 Basic Features
•RISC architecture
•Only 35 instructions to learn
• All single-cycle instructions except branches
•Operating frequency 0-20 MHz
•Precision internal oscillator
• Factory calibrated
• Software selectable frequency range of 8MHz to 31KHz
•Power supply voltage 2.0-5.5V 5

•Consumption: 220uA
(2.0V, 4MHz), 11uA (2.0
V,
32 KHz) 50nA (stand-by mode)
•Power-Saving Sleep Mode
•Brown-out Reset (BOR) with
software control option
The PIC16F887 Basic Features

•35 input/output pins


• High current source/sink for direct LED drive
• software and individually programmable pull-up resistor
• Interrupt-on-Change pin
•8K ROM memory in FLASH technology
• Chip can be reprogrammed up to 100.000 times
•In-Circuit Serial Programming Option
• Chip can be programmed even embedded in the target
device
•256 bytes EEPROM memory
• Data can be written more than 1.000.000 times
•368 bytes RAM memory

6
The PIC16F887 Basic Features
•A/D converter:
• 14-channels
• 10-bit resolution
•3 independent timers/counters
•Watch-dog timer
•Analogue comparator module with
• Two analogue comparators
• Fixed voltage reference (0.6V)
• Programmable on-chip voltage reference
•PWM output steering control
•Enhanced USART module
• Supports RS-485, RS-232 and LIN2.0
• Auto-Baud Detect
•Master Synchronous Serial Port (MSSP)
• supports SPI and I2C mode
7
PIC16 Internal Components

8
PIC16 Instructions Set
PIC16 Internal Components
CPU
v RISC gives the PIC16F887 two great advantages: The CPU
only recognizes 35 simple instructions.
v Just to mention that in order to program other
microcontrollers in assembly language it is necessary to
know more than 200 instructions by heart.
v The execution time is the same for almost all instructions,
and lasts for 2 clock cycles.
v The oscillator frequency is stabilized by a quartz crystal.
v The execution time of jump and branch instructions is 2 clock
cycles.
v It means that if the microcontroller’s operating speed is
20MHz, the execution time of each instruction will be 200nS,
i.e. the program will execute 5 million instructions per
second!
1
0
PIC16 Internal Components
Control Unit: Program Memory
v Microcontrollers used for prototyping and short production
runs use flash memory to store the program.
v The PIC 16 program consists of a list of 14-bit binary codes, each
containing the instruction and operand (data) in one operation
code.
v The program starts at address zero and the instructions are
executed in turn unless a branch instruction or an external ‘interrupt’
occurs.
v Usually, the last instruction causes a loop back to repeat the control
sequence.
v The capacity of the program memory block is one of the most
significant features of each PIC, varying from 1024 to 8096
instructions in the 16 series.

1
1
PIC16 Internal Components
Control Unit:

1
2
PIC16 Internal Components
Control Unit:

1
3
PIC16 Internal Components

Control Unit: Program Counter


v The Program Counter (PC) is a register that keeps track of the
program sequence, by storing the address of the instruction
currently being executed.
v It is automatically loaded with zero when the chip is powered up or
reset. The program counter is file register number 2 in the SFR set.
v As each instruction is executed, PC is incremented
(increased by one) to point to the next instruction.
v Program jumps are achieved by reloading PC to point to an
instruction other than the next in sequence.
v This new address is provided in the instruction.

1
4
PIC16 Internal Components
Control Unit:

Program Counter

14
PIC16 Internal Components

Control Unit: Instruction Register and Decoder


v To execute an instruction, the processor copies the instruction code
from the program memory into the instruction register (IR).
v It can then be decoded (interpreted) by the instruction decoder,
which is a combinational logic block which sets up the processor
control lines as required.
v These control lines are not shown explicitly in the block diagram,
as they go to all parts of the chip, and would make it too
complicated.
v In the PIC, the instruction code includes the operand (working
data), which may be a literal value or register address.

1
6
PIC16 Internal Components

Control Unit: STACK


v A part of RAM used as stack consists of eight 13-bit registers.
v Before the microcontroller starts to execute a subroutine
(CALLinstruction) or when an interrupt occurs, the address of the
first next instruction to execute is pushed onto the stack,
i.e. one of its registers.
v Thanks to that the microcontroller knows from where to continue
regular program execution upon a subroutine or an interrupt
execution.
vThis address is cleared after returning to the program because there
is no need to save it any longer, and one location of the stack becomes
automatically available for further use.

1
7
PIC16 Internal Components

Control Unit: STACK


v It is accessed with the commands PUSH
(put something on the stack) and POP
(remove something from the stack).
v To store the current fill level of the stack,
the CPU contains a special register called
the stack pointer (SP), which points to
the top of the stack. Stacks typically
grow “down”, that is, from the higher
memory addresses to the lower
addresses. So the SP generally starts at
the end of the data memory and is
decremented with every push and
incremented with every pop.
1
8
PIC16 Internal Components

Control Unit: Timing and Control


v This sequential logic block provides overall control of the
chip, sending signals to all parts of the chip to move the data
around and carry out logical operations and calculations
v . A clock signal is needed to drive the program sequence; it is
traditionally derived from an external crystal oscillator, which
provides an accurate, fixed frequency signal.
v More recent chips have an internal oscillator, which saves
on external components.
v A maximum frequency of operation is always specified; most
current PIC 16 chips run at a maximum of 20 MHz, although
newer designs reach 32 MHz.

1
9
PIC16 Internal Components

Control Unit: Timing and Control

2
0
PIC16 Internal Components
ALU
PIC16 Internal Components
ALU

21
PIC16 Internal Components
ALU

22
PIC16 Internal Components
ALU

24
2
5
PIC16 Internal Components
ALU

General-purpose registers are used for storing temporary data and


results created during operation.

2
6
PIC16 Internal Components
ALU

26
PIC16 Internal Components
ALU

27
PIC16 Internal Components
ALU: STATUS REGISTER
28
PIC16 Internal Components
ALU: STATUS REGISTER 29
PIC16 Internal Components

Program memory
v Program memory contains the
programs that are written by the user.
v The program counter (PC) executes
these stored commands one by one.
v Usually PIC16 devices have a 13 bit
wide program counter that is capable
of addressing 8K× 14 bit program
memory space.
v This memory is primarily used for
storing the programs that are written
(burned) to be used by the PIC.

3
1
PIC16 Internal Components

v These devices also have 8K*14 bits of flash memory


that can be electrically erasable /reprogrammed.
v Each time we write a new program to the controller, we
must delete the old one at that time.
v Program counters (PC) is used to keep the track of the
program execution by holding the address of the current
instruction. The counter is automatically incremented to the
next instruction during the current instruction execution.
v The PIC16F87XA family has an 8-level deep x 13-bit wide
hardware stack.
v The stack space is not a part of either program or data space
and the stack pointers are not readable or writable. In the
PIC microcontrollers, this is a special block of RAM
memory used only for this purpose.
3
2
PIC16 Internal Components
PIC16 Data Memory 32

v The data memory of


PIC16F877 is separated into
multiple banks which contain
the general purpose registers
(GPR) and special function
registers (SPR).
v According to the type of the
microcontroller, these banks
may vary.
v The PIC16F877 chip only has
four banks (BANK 0, BANK 1,
BANK 2, and BANK4). Each
bank holds 128 bytes of
addressable memory.
PIC16 Internal Components

Data EEPROM and FLASH


v The data EEPROM and Flash program memory is
readable and writable during normal operation (over the full
VDD range).
v This memory is not directly mapped in the register file
space. Instead, it is indirectly addressed through the
Special Function Registers.
v There are six SFRs used to read and write this memory:
• EECON1
• EECON2
• EEDATA
• EEDATH
• EEADR
• EEADRH

3
4
Pinout description

v Most pins of the PIC16F887


microcontroller are multi-
functional as seen in figure
above.
v Such pin functionality is
very useful as it makes the
microcontroller package
more compact without
affecting its operation.
v These various pin functions
cannot be used
simultaneously but can be
changed at any point during
operation. The following
tables refer to the PDIP 40
3
5
Pinout description

3
6
Pinout description

3
7
Pinout description

3
8
Pinout description

3
9
Pinout description
Thank you

www.ump.edu.my 40

You might also like