2. OutlineOutline
ï« 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
3. What is Microcontroller?What is Microcontroller?
ïž Integrated chip that
contains CPU, RAM,
some form of ROM, I/O
ports, and timers
ïž Designed for a very
specific task to control
a particular system
ïž reduce production cost
4. ”C”C vs General-Purposevs General-Purpose ””PP
Microcontroller Microprocessor
Devices Microchipâs PICâs
series, Atmelâs AVR
series
Intelâs x86 family (8086,
80286, 80386, 80486 &
the Pentium) or
(Motorolaâs PowerPC
family)
Components Internal CPU, RAM,
ROM, I/O ports and
timers
External RAM, ROM, and
I/O ports
Application Perform specific
function: A small set of
signal processing
functions for digital
signal processor
Perform more tasks that
related to general
requirements: calculations
of software, personal
computer
5. ”C”C vs General-Purposevs General-Purpose ””PP ContâŠ
CPU / ÎŒP
RegisterRegister
Control UnitControl Unit
ALUALU
DATA BUSCPU / ÎŒP
Register
Register
Control Unit
Control Unit
ALU
ALU
ADDRESS BUS
CONTROL BUS
ÎŒC
RAM ROM I/O Timer
Serial
COM
6. ”C”C vs General-Purposevs General-Purpose ””PP ContâŠ
Microprocessor
EEPROM
RAM
Input
and
output
ports
Serial I/O
Parallel I/O
Timer
PWM
Input
and
output
ports
A/D
D/A
Analog
I/O
ROM
Microprocessor
EEPROM
RAM
Input
and
output
ports
Serial I/O
Parallel I/O
Timer
PWM
Input
and
output
ports
A/DA/D
D/AD/A
Analog
I/O
ROM
Microprocessor-based System Microcontroller-based System
7. A Brief History of PIC ”CA Brief History of PIC ”C
ïž In 1989, Microchip Technology Corporation introduced
an 8-bit ”C called PIC (Peripheral Interface Controller).
ïž This 8 pins chip contains a small amounts of data RAM, a
few hundred bytes of on-chip ROM for program, one
timer, and a few pins for I/O ports.
ïž The family of 8-bit ”C: 10xxx, 12xxx, 14xxx, 16xxx,
17xxx, and 18xxx
8. A Brief History of PIC ”CA Brief History of PIC ”C ContâŠ
http://www.microchip.com
9. A Brief History of PIC ”CA Brief History of PIC ”C
ïž They are all 8-bit processors that the CPU can work on
only 8 bits of data a time.
ïž Problem: not all 100% upwardly compatible in terms of
software when going from one family to another family.
ïž Ex.: 12xxx - 12-bit wide instructions
16xxx- 14-bit wide instructions
PIC18xxx - 16-bit wide with many
new instructions
ContâŠ
10. A Brief History of PIC ”CA Brief History of PIC ”C
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
ContâŠ
11. A Brief History of PIC ”CA Brief History of PIC ”C
Architecture:
ContâŠ
CPU
Program &
Data Memory
Von Neumann architecture
CPU
Program
Memory
Data
Memory
Harvard architecture
12. PIC16F84 FeaturesPIC16F84 Features
ïČ 18 pins, DIP18 type (Dual in Package) or SMD type
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.
14. PIC Clock GeneratorPIC Clock Generator
ï To provide a clock for executing a program or program
instructions of ”C.
ï Types of PIC clock generator:
ï A crystal & two capacitors
ï Resonators or external resistor-capacitor pair
ï Built-in resistor-capacitor
15. PIC Clock GeneratorPIC Clock Generator
ï¶ PIC16F84 can operate in four different oscillation
modes:
- LP low power crystal
- XT crystal/resonator
- HS high speed crystal/resonator
- RC resistor/capacitor
ï¶ Two configuration bits, FOSC1 & FOSC0 are used to
select one of these four modes
ContâŠ
16. PIC Clock GeneratorPIC Clock Generator
Crystal Oscillator/Ceramic Resonators
ï For XT, LP or HS OSC configurations
ï Crystal or ceramic resonator is connected to
the OSC1/CLKIN & OSC2/CLKOUT pins
ContâŠ
17. PIC Clock GeneratorPIC Clock Generator
ïČ A parallel cut crystal is used to design PIC16F84A
ïČ The use of a series cut crystal may give a freq. out of the crystal
manufacturerâs specifications
ContâŠ
External clock input operations
18. PIC Clock GeneratorPIC Clock Generator ContâŠ
Capacitor selection for ceramic resonators
Capacitor selection for crystal resonators
19. PIC Clock GeneratorPIC Clock Generator
RC Oscillator
ï» Reduce cost for timing insensitive applications
ï» Variation of the oscillator frequency:
- operating temperature
- process parameter variation
- difference in lead frame capacitance between package types (low
CEXT values)
- tolerance of the external R & C components
ContâŠ
20. ResetReset
ïČ Power-on Reset (POR)
ïČ MCLR during normal operation
ïČ MCLR during SLEEP
ïČ WDT Reset (during normal
operation)
ïČ WDT Wake-up (during SLEEP)
Register Reset value (hex)
PC 000000
WREG 00
SP 00
TRISA-TRISB FF
Value registers upon reset
21. PORTSPORTS
ïČ Physical connection of CPU and outside world â monitor
@ control other components @ devices
ïČ A group of pins which can be accessed simultaneously @
set the desired combination of zeros and ones
ïČ All port pins can be designated as input @ output
22. PORTS:PORTS: PORTA & TRISAPORTA & TRISA
ï PORTA is a 5-bit wide, bi-directional port
ï TRISA: data direction register of PORTA
ï TRISA = 1, PORTA is
an input (output
driver in HI-
impedance mode)
ï TRISA = 0, PORTA is
an output (contents
of the output latch
on the selected pin)
23. PORTS:PORTS: PORTB & TRISBPORTB & TRISB
ïš PORTB is a 8-bit wide, bi-directional port
ïš TRISB: data direction register of PORTB
ïš TRISB = 1, PORTB
is an input (output
driver in HI-
impedance mode)
ïš TRISB = 0, PORTB
is an output
(contents of the
output latch on the
selected pin)
24. Center Processing UnitCenter Processing Unit
(CPU)(CPU)ï€ The brain of the ”C
ï€ Connect all parts of the ”C through a data bus
& and an address bus
ï€ Find, fetch, decode & execute the right
instruction
ï€ CPU resources:
ï€ Registers: store temporary information
ï€ ALU: performing arithmetic functions
ï€ Program counter: point to the address of the next
instruction to be executed
ï€ Instruction decoder: interpret the instruction
fetched into the CPU
25. Center Processing UnitCenter Processing Unit
(CPU)(CPU)
MOVLW 0x20
Program
Memory
Temporary
storage
executeexecute
Memory
11 00xx 0010 0000
opcode
Assembler (translator)
Decoder
Fetch
instruction
Fetch
instruction
26. Center Processing UnitCenter Processing Unit
(CPU)(CPU)
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).
ContâŠ
27. Center Processing UnitCenter Processing Unit
(CPU)(CPU)
ContâŠ
ALU
STATUS
register
8-bit literal (from
instruction word)
WREG
register
8-
bit
8-
bit
8-bit
Z, DC, C flags
Carry bit
28. MEMORY ORGANIZATIONMEMORY ORGANIZATION
ï€ PIC16F84 has two separate memory blocks: data &
program
ï€ Data block: GPR and SFP registers in RAM memory
(read/write memory- static memory), EEPROM memory
ï€ Program block: FLASH memory
30. MEMORY ORGANIZATION:MEMORY ORGANIZATION: Program MemoryProgram Memory
ï€ Used for storing programs (opcodes), directly
under control of program counter (PC)
ï€ Wake up memory (address 0000H) when PIC is
powered up.
ï€ Has been carried out in FLASH technology
(indicated by the letter F in the part number, C for
one-time programmable (OTP)): possible to
program a ”C many times
ï€ Size of 1024 locations, 14 bits width
ï€ Locations 0000h & 0004h are reserved for
reset & interrupt vector, respectively
ï€ The 1st
1Kx14 (0000h-03FFh) are physically
implemented address
ï€ Accessing a location of physically
implemented address will cause a wraparound
32. MEMORY ORGANIZATION:MEMORY ORGANIZATION: Data MemoryData 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
34. 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.
35. Timer & PrescalarTimer & 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
37. Flash MemoryFlash 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
38. RAMRAM
ïż 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.
39. ROMROM
ï¶ 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.
40. EEPROMEEPROM
ï 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.