lec10 pic inst
Post on 06-Apr-2018
239 Views
Preview:
TRANSCRIPT
-
8/3/2019 Lec10 Pic Inst
1/37
1
EECE416: Microcomputer
Fundamentals and Design
PIC Instruction Set and SomeTips for Programming
Dr. Charles J. Kim
Howard University
-
8/3/2019 Lec10 Pic Inst
2/37
2
F877 Instruction Set
14-Bit Word
Byte-Oriented Instruction
F: File Register (or RAM)
D: Destination
D=0: Destination W
D=1: Destination
File Register
Bit-Oriented Instruction
B: Bit Field
F: Register File where the Bit is located Literal and Control Operation
K: 8-bit constant
-
8/3/2019 Lec10 Pic Inst
3/37
3
General Form of Instruction
-
8/3/2019 Lec10 Pic Inst
4/37
4
Instruction List
-
8/3/2019 Lec10 Pic Inst
5/37
5
Destination of the result & Machine Code
D=0: Destination WD=1: Destination File Register (Default)
addw f PORTD ;
Add content of PORTD to content of the W and
store the result back into PORTD
addwf PORTD, 0 ;
Add content of PORTD to content of the W andstore the result into W
-
8/3/2019 Lec10 Pic Inst
6/37
6
Register Addressing Modes
Immediate Addressing(ex) MOVLW 0x0F
Direct AddressingUses 7 bits of 14 bit instruction to identify a register file address
8th
and 9th
bit comes from RP0 and RP1 bits of STATUS register. Initial condition for RP0 and RP1: RP1=RP0=0
(ex) SSPCON EQU 0x14
STATUS EQU 0x03
SSPSTAT EQU 0x94BCF STATUS, 0x05
BCF SSPCON, 0x01
BSF STATUS, 0x05
BCF SSPSTAT, 0x02
-
8/3/2019 Lec10 Pic Inst
7/37
7
Direct Addressing - Recap
-
8/3/2019 Lec10 Pic Inst
8/37
8
Indirect Addressing
INDF registerAny instruction using the INDF actually accesses the register
pointed to by the File Select Register (FSR).
A 9-bit EA is obtained by concatenating the 8-bit FSRregister and the IRP bit(STATUS)
Example: Erase the RAM section of 0x20-0x2FMovlw 0x20; pointer
Movwf FSR
Next clrf INDF
incf FSR
btfss FSR, 4goto next
-
8/3/2019 Lec10 Pic Inst
9/37
9
Direct vs. Indirect Addressing
-
8/3/2019 Lec10 Pic Inst
10/37
10
Instruction Setsdescription convention
-
8/3/2019 Lec10 Pic Inst
11/37
11
addlw
-
8/3/2019 Lec10 Pic Inst
12/37
12
addwf
-
8/3/2019 Lec10 Pic Inst
13/37
13
andlw
-
8/3/2019 Lec10 Pic Inst
14/37
14
andwf
-
8/3/2019 Lec10 Pic Inst
15/37
15
Bcf & bsf
-
8/3/2019 Lec10 Pic Inst
16/37
16
btfsc
-
8/3/2019 Lec10 Pic Inst
17/37
17
Btfss
-
8/3/2019 Lec10 Pic Inst
18/37
18
Call
-
8/3/2019 Lec10 Pic Inst
19/37
19
CLRF & CLRW
-
8/3/2019 Lec10 Pic Inst
20/37
20
COMF & DECF
-
8/3/2019 Lec10 Pic Inst
21/37
21
DECFSZ
-
8/3/2019 Lec10 Pic Inst
22/37
22
GOTO & INCF
-
8/3/2019 Lec10 Pic Inst
23/37
23
INCFSZ
-
8/3/2019 Lec10 Pic Inst
24/37
24
IORLW & IORWF
-
8/3/2019 Lec10 Pic Inst
25/37
25
MOVLW & MOVF
-
8/3/2019 Lec10 Pic Inst
26/37
26
MOVWF & NOP
-
8/3/2019 Lec10 Pic Inst
27/37
27
RETFIE & RETLW
-
8/3/2019 Lec10 Pic Inst
28/37
28
RETURN
-
8/3/2019 Lec10 Pic Inst
29/37
29
RLF & RRF
-
8/3/2019 Lec10 Pic Inst
30/37
30
SUBLW & SUBWF
-
8/3/2019 Lec10 Pic Inst
31/37
31
SWAPF & XORLW
-
8/3/2019 Lec10 Pic Inst
32/37
32
XORWF
-
8/3/2019 Lec10 Pic Inst
33/37
33
F877 Instruction Programming Tips
Tips on Instruction Skills and Tricks
Frequently Met Situations
(a) Turn on/off an LEDAn LED is connected to a pin at one, say,
PORTB, and to a ground at the other.
Use a bit-oriented file register operation:bsf
PORTB, 0x00
;to turn on and
BSF PORTB, 0 ;same effect
bcf PORTB, 0x00 ;to turn off.BCF PORTB, 0 ;same OFF
-
8/3/2019 Lec10 Pic Inst
34/37
34
(b)Variable DeclarationIn C:
byte temp
intx
In PIC:
Variables must occupy physical RAM space
CBLOCK ENDC pairExample:
Tips Variable Declaration
-
8/3/2019 Lec10 Pic Inst
35/37
35
(c) I/O designation to the I/O PortI/O Ports: PORTA, PORTB, PORTC, PORTD, PORTE
Bi-directional
Input or Output
I/O selection file register
TRISA for PORTA; TRISB for PORTB; TRISC for PORTC
TRISD for PORTD; TRISE for PORTE
Each pin can be selected as
1: Input
0: Output
Tips I/O designation
-
8/3/2019 Lec10 Pic Inst
36/37
39
(e) Reading sensor (digital) input anddecision-making based on the input
PIR motion detector & buzzer examplePIR output1: No motion detected
0: Motion detected
Buzzer
1: Buzzer On0: Buzzer Off
Use BTFSS or BTFSC
Tips Reading Sensor Input
-
8/3/2019 Lec10 Pic Inst
37/37
40
Sample Code
top related