Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Introduction to the
PIC Microcontroller
Company
LOGO
Company
LOGO Outline
What is Microcontroller?
µC vs General-Purpose µP
A Brief History of PIC µC
PIC16F84 Features
PIC Clock Generator
Reset
PORTS
Center Processing Unit (CPU)
MEMORY ORGANIZATION
Timer & Prescalar
Flash Memory
RAM
ROM
EEPROM
Company
LOGO What is Microcontroller?
CPU / μP
μC
CPU / μP DATA BUS
Control Unit
CONTROL BUS
Company
LOGO µC vs General-Purpose µP Cont…
ROM EEPROM
RAM
Microprocessor
Serial I/O
http://www.microchip.com
Company
LOGO A Brief History of PIC µC Cont…
Advantages of PIC:
30 to 100 times faster than other µCs
(program memory is integrated to the chip)
Smaller size (on-board memory)
Easy to program, reusable and
inexpensive
Company
LOGO A Brief History of PIC µC Cont…
Architecture:
Program &
CPU Data Memory
Von Neumann architecture
Data Program
Memory CPU Memory
Harvard architecture
Company
LOGO Review
1. A C normally has which of the following
devices on-chip?
(a) RAM (b) ROM (c) I/O (d) all of the above
Remarks:
RA0 - RA3 : Pins on port A. No additional function
RA4 : TOCK1 which functions as a timer
RB0 : Interrupt input is an additional function.
RB1 - RB5 : Pins on port B. No additional function.
RB6 : 'Clock' line in program mode.
RB7 : 'Data' line in program mode
MCLR : Reset input and Vpp programming voltage
Vss : Ground of power supply.
Vdd : Positive power supply pole.
OSC1 - OSC2 : Pins for connecting with oscillator.
Company
LOGO PIC16F84 Features Cont…
Block
diagram of
PIC16F84
Company
LOGO PIC Clock Generator
RC Oscillator
instruction to be executed
Instruction decoder: interpret the instruction
Temporary
storage Fetch
instruction
Memory opcode
11 00xx 0010 0000
MOVLW 0x20
Decoder execute
Program Fetch
instruction
Memory
Assembler (translator)
Company
LOGO Center Processing Unit (CPU)Cont…
Arithmetic Logic Unit (ALU)
Add, subtract, move (left @ right within a register) and
logic operations
PIC16F84 contains an 8-bit ALU & 8-bit working
registers (WREG)
ALU instructions: two operands @ one operand
Two operands: WREG + file register @ immediate
constant
Registers: GPR (General Purposes Registers) & SFP
(Special Function Registers)
One operand: WREG @ a file register
Execution of ALU instructions can affect STATUS bits
which are carry (C), digit carry (DC), and zero (Z).
Company
LOGO Center Processing Unit (CPU)Cont…
8-bit
8-bit
Carry bit
STATUS
ALU register
Z, DC, C flags
8-bit
Company
LOGO MEMORY ORGANIZATION
Memory
organization
of
PIC16F84
Company
LOGO MEMORY ORGANIZATION: Program Memory
Also known as file register: data storage, scratch pad & registers for internal
use and functions
Special Function Registers (SFR)
- 8-bit wide
- ALU status, timers, serial communication, I/O ports, ADC, & etc.
- function of each SFR is fixed in design, used to control C or peripheral
- access either directly (names @ addresses) or indirectly (FSR – File Select
Register)
- classified into core and peripheral sets
- control bits (RP1, RP0) in STATUS register are used for bank selection
General Purpose Registers (GPR)
- 8-bit wide
- also called general purpose RAM (GP RAM)
- used for data storage & scratch pad
- accessed directly
- addresses in Bank 0 & Bank 1 are mapped together
Location of SFR and GPR vary from chip to chip, even among
members of the same family
Company
LOGO
Data Memory
Organization
Company
LOGO
SFR File
Memory
Legend: x = unknown, u = unchanged, - = unimplemented, read as '0', q = value depends on condition
Note
1: The upper byte of the program counter is not directly accessible. PCLATH is a slave register for PC<12:8>. The contents of PCLATH can be
transferred to the upper byte of the program counter, but the contents of PC<12:8> are never transferred to PCLATH.
2: The TO and PD status bits in the STATUS register are not affected by a MCLR Reset.
3: Other (non power-up) RESETS include: external RESET through MCLR and the Watchdog Timer Reset.
4: On any device RESET, these pins are configured as inputs.
5: This is the value that will be in the port output latch.
Company
LOGO Review
1. True or false. Every member of the PIC16
family, regardless of the program ROM size,
wakes up at memory 0000H when it is powered
up.
2. What is the main difference between the
PIC16Fxxx and PIC16Cxxx C?
3. The GPR and SFR together are called ____.
4. The SFR registers in PIC are ___-bit.
5. The data memory in PIC16 is divided into
____-byte banks.
Company
LOGO Timer & Prescalar
Establish relation between a real dimension such as
“time” and a variable which represents status of a time
within a microcontroller
PIC16F84 has an 8-bit timer, whose its value is
continually increasing to 255 and then it starts all over
again: 0, 1, 2, 3, …, 255, 0, 1,… etc
Prescaler divides oscillator clock before it reaches logic
that increases timer status.
The first three bits in OPTION register defines divisor
256 is the highest divisor, means timer clock would
increase by one at every 256th clock
Company
LOGO Timer & Prescalar Cont…
Company
LOGO Flash Memory
Store permanent information on some palm-
sized computers (operating system & core
applications)
Unlike RAM (random-access memory), flash
memory can continue to store information in the
absence of a power source.
Unlike ROM (read-only memory), we can
write/update to flash memory
More expensive than ROM
Company
LOGO RAM
Random-access memory
The most common computer memory to
perform necessary tasks while the
computer is on
An integrated circuit memory chip allows
information to be stored or accessed in
any order and all storage locations are
equally accessible.
Company
LOGO ROM
Read Only Memory
Non-volatile: hold programs and data that must
be retained even the computer is turned off
data cannot be easily written to ROM; depending
on the technology used in the ROM, writing may
require special hardware, or may be impossible.
A computer's BIOS may be stored in ROM.
Company
LOGO EEPROM
Electrically Erasable Programmable Read Only
Memory
ROM that can be erased electronically and
reprogrammed in-circuit (or with a device
programmer).
EEPROM is very similar to flash memory. The
biggest difference is that the bytes (words) of an
EEPROM can be erased individually.