Professional Documents
Culture Documents
Chapter – 2
end applications
PICs are “RISC” (Reduced Instruction
Set Computers)
PIC Micro-Controller
3
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
CLK
Q1
Q2
Q3
Q4
PC PC PC+1 PC+2
Instruction Execution
7
8 bit
from instruction word
Register
file
Word 8 bit register value
register From direct or
indirect addressing Special
of instruction Function
Registers
(SRRs)
&
ALU General
Purpose
RAM
(GPR)
d=0 d=1
d = destination bit
Status Register
11
TO: Time Out; PD: Power Down; IRP, RP1, RP0: bank
selects; DC: Digital Carry (BCD); Z: Zero; C: Carry
Memory Organization
12
Data Memory
Program Memory
Only Memory)
• One Time Programmable (OTP) chips are EPROM
chips, but with no window.
FLASH
• Re-writable
• Much faster to develop
The PIC Family: Program Memory
14
program counter.
Width of program memory bus is 14
bits.
Program memory space divided into 4
pages of 2k each.
Memory Map
15
Stack
16
hardware stack.
PC is pushed onto the stack when CALL
Byte-Oriented Operation
• 0..6: 7 bit file register address
• 7: d bit; 0 for destination W
• 8..13: opcode
Bit-Oriented Operation
• 0..6: 7 bits file register address
• 7..9: 3 bits bit addresses within the 8-bit file
register
• 10..13: opcode
Instruction Format
22
00 01 10 11
00h
In status register
Data Memory
7Fh
Bank 0 Bank 1 Bank 2 Bank 3
Indirect Addressing Mode
24
Byte-Oriented Operations
• Arithmetic & logical operation
• Data movement
Examples
• addwf f,d
Add contents of W with the register f, if d=0
store result in W else in register f.
• E.g.: addwf 0x20,0
Instructions
27
• clrf f
Contents of register f are cleared & Z bit
(STATUS) is set
• E.g.: clrf 0x30
• movwf f
Move data from W register to register f.
• E.g.: movwf 0x04
Instructions
28
Literal Operations
• Immediate Addressing Mode
Examples
• addlw k
Add literal k to register W.
• E.g.: addlw 0x50
• movlw k
Move literal k into register W.
• E.g.: movlw 0x21
More on data transfer instructions
30
flag C
Bits move by one bit to left towards bit
Control Instructions
• Program & processor control
Examples
• goto k(k-11 bit)
Unconditional branch. Literal k is loaded into PC
• E.g.: goto there (use labels)
• call k
Call subroutine at location k
• E.g.: call sum
Instructions
38
Examples
• retfie
Return from interrupt service routine & re-enable
interrupt
• sleep
Go to standby mode
• clrwdt
Clear watchdog timer.
Direct program flow
39
peripherals
Some Common peripherals are:
• Tri-state digital I/O pins
• Analog to digital converters (ADC)
• Serial Communications: UART
• Timer and counter
• others
Interrupts
44
END