Unit Iv Pic Microcontroller
Unit Iv Pic Microcontroller
PIC MICROCONTROLLER
AGENDA
• Introduction to PIC
• Features
• Architecture
• Programming model(memory organization)
• Oscillator options
• BOD, power down modes
• Configuration bit settings
• Peripheral support
• Comparison of 10f,12f,16f and 18f PIC controller
families
• Overview of instruction set
SYLLABUS
• Comparison of PIC family, Criteria for Choosing
Microcontroller, features, PIC18FXX architecture with
generalized block diagram.
• MCU, Program and Data memory organization, Bank
selection using Bank Select
• Register, Pin out diagram, Reset operations, Watch Dog
Timers, Configuration registers and oscillator options
(CONFIG).
• Power down modes , Brief summary of Peripheral support,
Overview of instruction set.
Introduction to PIC
• In 1989, Microchip technology introduced an
8 bit controller called PIC
• PIC: Peripheral Interface Controller.
• The PIC family:
– 10xxx, 12xxx, 14xxx, 16xxx,17xxx and 18xxx
• PIC 18xxx is the highest performing
microcontroller from the PIC family
• It is available in 18-pin to 80-pin packages.
Features of PIC 18fxx
• High speed RISC Architecture
• Operating frequency for PIC 18 DC to 40 MHz
• General features include: Timers, Watch dog
timers, ADC, Extended Instruction / Data
memory , Serial communication , Capture/
Compare/ Pulse width modulation (CCP).
• PIC 18 can have 2MB of program ROM memory. ROM may be of
different types such as (flash, OTP, UV-EPROM etc.)
– 21 bit PC available
– On chip ROM: Flash :F and OTP:C
• PIC can have maximum of 4KB of data RAM.
– The RAM consists of two components:
• GP RAM
• SFRs
• EEPROM 256 Bytes for storing critical data.(optional)
• It uses 16-bit wide instructions, 8-bit wide data path.
• 5 I/O ports available for PIC18f4520
– PORT A through PORT E
– Each port can be configured as input or output.-Bidirectional port
– Each port has some other functions Such as timer , ADC, interrupts
and serial communication
Features: PIC 18F452
• Power Management Features
• Flexible Oscillator Structure
• Wide Operating Voltage Range: 2.0V to 5.5V
• High-Current Sink/Source 25 mA/25 mA
• Many on chip peripherals available.
– Up to three Programmable External Interrupts
– Counter/Timer modules.
• Modules 0,2 (8-Bits)
• Modules 1,3 (16-Bits)
– Up to two CCP Modules/ ECCP module
• The CCP module is a peripheral which allows the user to time and
control different events
– ADC 10-bits with 8-way input multiplexer.
PIC 18F452 : Peripherals
• C (Carry/Borrow Flag):
▫ set when an addition generates a carry and a subtraction generates a borrow
• DC (Digit Carry Flag):
▫ also called Half Carry flag; set when carry generated from Bit3 to Bit4 in an arithmetic
operation
• Z (Zero Flag):
▫ set when result of an operation is zero
• OV (Overflow Flag):
▫ set when result of an operation of signed numbers goes beyond seven bits
• N (Negative Flag):
▫ set when bit B7 is one of the result of an arithmetic /logic operation
Stack
• The stack operates as a 31-word by 21-bit RAM .
• It is not part of either program or data space.
• 5-bit Pointer, STKPTR.
• The Stack Pointer is readable and writable.
– The address on the top of the stack is readable and writable through
the Top-of-Stack (TOS) Special Function Registers.
– Data can also be pushed to, or popped from the stack, using these
registers.
• A CALL type instruction causes a push onto the stack.
– The Stack Pointer is first incremented and the location pointed to by
the Stack Pointer is written with the contents of the PC (already
pointing to the instruction following the CALL).
• A RETURN type instruction causes a pop from the stack.
– The contents of the location pointed to by the STKPTR are transferred
to the PC and then the Stack Pointer is decremented
• For stack access, four registers are provided in the
Special Function Register (SFR) bank. They are:
– TOSU
– TOSH
– TOSL
– STKPTR
• The Stack Pointer is initialized to ‘00000’ after all Resets.
• There is no RAM associated with the location
corresponding to a Stack Pointer value of ‘00000’; this is
only a Reset value.
• Status bits indicate if the stack is full, or has overflown
or underflown.
• Only the top of the
return address stack
(TOS) is readable and
writable.
• A set of three registers,
TOSU:TOSH:TOSL, hold
the contents of the
stack location pointed
to by the STKPTR
register.
Stack Pointer (STKPTR)
D7 D6 D5 D4 D3 D2 D1 D0
D7 D6 D5 D4 D3 D2 D1 D0
• C (Carry/Borrow Flag):
– set when an addition generates a carry and a subtraction generates a borrow
• DC (Digit Carry Flag):
– also called Half Carry flag; set when carry generated from Bit3 to Bit4 in an arithmetic
operation
• Z (Zero Flag):
– set when result of an operation is zero
• OV (Overflow Flag):
– set when result of an operation of signed numbers goes beyond seven bits
• N (Negative Flag):
– set when bit B7 is one of the result of an arithmetic /logic operation
File Select Registers (FSR)
• There are three registers:
• FSR0, FSR1, and FSR2
• Each register composed of two 8-bit
registers (FSRH and FSRL)
• Used as pointers for data
registers
• Holds 12-bit address of data
register
Instruction set of PIC 18f4520
• The CPU can access data in various ways. The data
could be in any register, memory location, or provided
as an immediate value. These various ways of
accessing data are called addressing modes.
• The addressing modes supported by a up/uc, are
determined when it is designed and cannot be altered
by the programmer.
• The addressing modes supported by PIC18f are:
– Immediate
– Direct
– Register Indirect
– Indexed-ROM
Addressing modes in brief
• Immediate:
– The operand is literal constant.
– Operand comes immediately after the opcode
when an instruction is specified.
– This addressing mode is used to load information
into WREG and selected registers but not in any
file registers.
ex: MOVLW 45H
ADDLW D’62’
• Direct:
• The entire data RAM file register can be
accessed using either direct or register indirect
addressing mode.
• In direct addressing mode, the operand data is
in a RAM memory location whose address is
known and this address is given as part of the
instruction.
ex: MOVWF 0X40
MOVFF 0X40,0X50
• Register indirect:
• In this addressing mode, a register is used as a pointer to the data
RAM location.
• In PIC18f, three registers are used for this purpose:
– FSR0, FSR1,FSR2 (FSR: File select register)
• The FSR is 12-bit register allowing access to entire 4096 bytes of
data RAM.
• Use instruction LFSR (load FSR) to load the RAM location .
ex: LFSR 0,0X30 MOVWF INDF0
LFSR 1,0X20
LFSR 2,0X40
• The FSRs are split into 8 bit registers. As FSRxL and FSRxH(only
lower 4 bits used).
• INDF(Indirect register) is associated with each FSR.
– INDF0,INDF1,INDF2
• The data pointed by FSRx is moved into INDFx register.
• Indexed ROM
• This addressing mode is widely used to access
data from the program ROM space of PIC18f
• It is also known as table processing.
• There are a group of instructions for table
processing(both read as well as write).
• TBLPTR(Table pointer) is an 21 bit SFR used to
point byte to be fetched from code memory.
– TBLPTR is divided into three 8-bit parts viz. TBLPTRL,
TBLPTRH, TBLPTRU.
• The other SFR register used for table processing
is TABLAT.
– The TABLAT is used to keep the byte once it is fetched
into the CPU.
The instruction set is also grouped as:
• Byte oriented
• 15Bit OPCODE
oriented9 d 8 a 7 f(FileReg) 0
15 OPCODE 9 b 8 a 7 f(FileReg) 0
• Literal
15 OPCODE 8 7 k (Literal) 0
• Control
15 OPCODE 8 7 n (Literal) 0
0 1 1 0 1 1 1 a f f f f f f f f
fileReg (w)