41
Introduction to Introduction to the PIC the PIC Microcontroller Microcontroller

PIC Introduction and explained in detailed

Embed Size (px)

Citation preview

Page 1: PIC Introduction and explained in detailed

Introduction to the Introduction to the PIC MicrocontrollerPIC Microcontroller

Page 2: PIC Introduction and explained in detailed

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

Page 3: PIC Introduction and explained in detailed

What is What is Microcontroller?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

Page 4: PIC Introduction and explained in detailed

µC µC vs General-Purpose vs General-Purpose µµPP

Microcontroller MicroprocessorDevices 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

Page 5: PIC Introduction and explained in detailed

µC µC vs General-Purpose vs General-Purpose µµPP

Cont…

CPU / μP

Register

Control Unit

ALUDATA BUSCPU / μP

Register

Control Unit

ALU

ADDRESS BUS

CONTROL BUS

μC

RAM ROM I/O Timer Serial COM

Page 6: PIC Introduction and explained in detailed

µC µC vs General-Purpose vs General-Purpose µµPP

Cont…

Mic

ropr

oces

sor

EEPROM

RAM

Inputand

outputports

Serial I/O

Parallel I/O

Timer

PWM

Inputand

outputports

A/D

D/A

AnalogI/O

ROM

Mic

ropr

oces

sor

EEPROM

RAM

Inputand

outputports

Serial I/O

Parallel I/O

Timer

PWM

Inputand

outputports

A/DA/D

D/AD/A

AnalogI/O

ROM

Microprocessor-based System Microcontroller-based System

Page 7: PIC Introduction and explained in detailed

A Brief History of PIC A Brief History of PIC µCµ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

Page 8: PIC Introduction and explained in detailed

A Brief History of PIC A Brief History of PIC µCµC

Cont…

http://www.microchip.com

Page 9: PIC Introduction and explained in detailed

A Brief History of PIC A Brief History of PIC µCµ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…

Page 10: PIC Introduction and explained in detailed

A Brief History of PIC A Brief History of PIC µCµCAdvantages 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…

Page 11: PIC Introduction and explained in detailed

A Brief History of PIC A Brief History of PIC µCµCArchitecture:

Cont…

CPU Program & Data Memory

Von Neumann architecture

CPU Program Memory

Data Memory

Harvard architecture

Page 12: PIC Introduction and explained in detailed

PIC16F84 FeaturesPIC16F84 Features 18 pins, DIP18 type (Dual in Package) or SMD type

Remarks:RA0 - RA3: Pins on port A. No additional functionRA4 : TOCK1 which functions as a timerRB0 : 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 modeMCLR : Reset input and Vpp programming voltageVss : Ground of power supply.Vdd : Positive power supply pole.OSC1 - OSC2 : Pins for connecting with oscillator.

Page 13: PIC Introduction and explained in detailed

PIC16F84 FeaturesPIC16F84 Features Cont…

Block Block diagram of diagram of PIC16F84PIC16F84

Page 14: PIC Introduction and explained in detailed

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

Page 15: PIC Introduction and explained in detailed

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…

Page 16: PIC Introduction and explained in detailed

PIC Clock GeneratorPIC Clock GeneratorCrystal Oscillator/Ceramic Resonators For XT, LP or HS OSC configurations Crystal or ceramic resonator is connected to

the OSC1/CLKIN & OSC2/CLKOUT pins

Cont…

Page 17: PIC Introduction and explained in detailed

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

Page 18: PIC Introduction and explained in detailed

PIC Clock GeneratorPIC Clock Generator Cont…

Capacitor selection for ceramic resonators

Capacitor selection for crystal resonators

Page 19: PIC Introduction and explained in detailed

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…

Page 20: PIC Introduction and explained in detailed

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

Page 21: PIC Introduction and explained in detailed

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

Page 22: PIC Introduction and explained in detailed

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)

Page 23: PIC Introduction and explained in detailed

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)

Page 24: PIC Introduction and explained in detailed

Center Processing Unit Center 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

Page 25: PIC Introduction and explained in detailed

Center Processing Unit Center Processing Unit (CPU)(CPU)

MOVLW 0x20

Program Memory

Temporary storage

executeexecute

Memory11 00xx 0010 0000

opcode

Assembler (translator)

Decoder

Fetch instruction

Fetch instruction

Page 26: PIC Introduction and explained in detailed

Center Processing Unit Center 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…

Page 27: PIC Introduction and explained in detailed

Center Processing Unit Center Processing Unit (CPU)(CPU)

Cont…

ALU STATUS register

8-bit literal (from instruction word)

WREG register

8-bit

8-bit

8-bitZ, DC, C flags

Carry bit

Page 28: PIC Introduction and explained in detailed

MEMORY MEMORY ORGANIZATIONORGANIZATION 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

Page 29: PIC Introduction and explained in detailed

Memory organization of PIC16F84

Page 30: PIC Introduction and explained in detailed

MEMORY ORGANIZATION:MEMORY ORGANIZATION: Program Program MemoryMemory

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

Page 31: PIC Introduction and explained in detailed

MEMORY ORGANIZATION:MEMORY ORGANIZATION: Program Program MemoryMemory

Page 32: PIC Introduction and explained in detailed

MEMORY ORGANIZATION:MEMORY ORGANIZATION: Data Data MemoryMemory

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

Page 33: PIC Introduction and explained in detailed

Data Memory Organization

Page 34: PIC Introduction and explained in detailed

SFR File Memory

Legend: x = unknown, u = unchanged, - = unimplemented, read as '0', q = value depends on conditionNote 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.

Page 35: PIC Introduction and explained in detailed

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

Page 36: PIC Introduction and explained in detailed

Timer & PrescalarTimer & Prescalar Cont…

Page 37: PIC Introduction and explained in detailed

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

Page 38: PIC Introduction and explained in detailed

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.

Page 39: PIC Introduction and explained in detailed

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.

Page 40: PIC Introduction and explained in detailed

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.

Page 41: PIC Introduction and explained in detailed