PIC instruction set (cont.)

advertisement
16.317: Microprocessor
System Design I
Instructor: Dr. Michael Geiger
Spring 2012
Lecture 33: PIC instruction set, pt. 3
Lecture outline

Announcements/reminders

Lab 4 due 4/25




Lab 5 posted; report due 5/7 (last day of classes)
HW 4 to be posted ASAP (hopefully later today)



Likely our last homework assignment—doesn’t make sense to have
both a homework assignment and lab due at the end of classes
No lecture Friday
Lecture outline

Review: PIC instructions




4/12/2020
Limited # of PICkits  strongly suggest you work in a group for the
last two assignments
PICkits can be checked out from the lab
Logical ops
Goto/call/return
Misc
Continue with PIC instructions
Microprocessors I: Lecture 33
2
Review: PIC instructions

Logical operations




Rotates





goto
call
return/retlw/retfie
Miscellaneous


4/12/2020
rrf
rlf
Jumps/calls/return


andlw/andwf
iorlw/iorwf
xorlw/xorwf
nop
sleep/clrwdt
Microprocessors I: Lecture 33
3
Conditional Execution


none
Conditional execution in PIC: skip next instruction if condition true
Two general forms


btfsc
btfss
decfsz
incfsz
Test bit and skip if bit clear/set
Increment/decrement register and skip if result is 0
f, b
f, b
f, F(W)
f, F(W)
Examples:

btfsc TEMP1, 0

btfss STATUS, C

decfsz TEMP1, F

incfsz TEMP1, W
4/12/2020
STATUS bits:
;Test bit b of register f, where b=0 to 7, skip if clear
;Test bit b of register f, where b=0 to 7, skip if set
;decrement f, putting result in F or W, skip if zero
;increment f, putting result in F or W, skip if zero
; Skip the next instruction if bit 0 of TEMP1 equals 0
; Skip the next instruction if C==1
; Decrement TEMP1, skip if TEMP1==0
; W <- TEMP1+1 , skip if W==0 (TEMP1==0xFF)
; Leave TEMP1 unchanged
Microprocessors I: Lecture 33
4
Example

Show the values of all changed registers
after each of the following sequences

(a)
What high-level operation does each perform?
movf
sublw
btfsc
goto
incf
goto
a, W
0xA
STATUS, Z
L1
b, W
L2
L1
movf
subwf
btfss
goto
movf
goto
NUM2, W
NUM1, W
STATUS, C
BL
NUM1, W
Done
movf
NUM2, W
movwf
MAX
BL
decf
b, W
L2
Done
movwf
4/12/2020
(b)
a
Microprocessors I: Lecture 33
5
Example solution (part a)
W=a
 W = 10 – a
 Skip goto if result
is non-zero
 Goto L1 if result == 0
 Reach this point if
result non-zero
W=b+1
movf
sublw
btfsc
a, W
0xA
STATUS, Z
goto
L1
incf
goto
b, W
L2
decf
b, W
W=b-1
movwf
a
 a = W  value depends
on what’s executed before this
L1
High-level operation:
if ((10 – a) == 0)
a=b–1
else
a=b+1
L2
4/12/2020
Microprocessors I: Lecture 33
6
Example solution (part b)
 W = NUM2
 W = NUM1 – W
= NUM1 – NUM2
 Carry indicates
“above”
 if set, NUM1 > NUM2
movf
subwf
NUM2, W
NUM1, W
btfss
STATUS, C
goto
movf
BL
NUM1, W
goto
Done
 Skip “below” section
movf
NUM2, W
 if (NUM1 < NUM2)
W = NUM2
movwf
MAX
 if (NUM1 >= NUM2)
W = NUM1
High-level operation:
if (NUM1 < NUM2)
MAX = NUM2
else
MAX = NUM1
BL
Done
4/12/2020
Microprocessors I: Lecture 33
7
Working with 16-bit data
Assume a 16-bit counter, the upper byte of the counter is called COUNTH and the lower byte is
called COUNTL.
Decrement a 16-bit counter
movf
btfsc
decf
decf
COUNTL, F
STATUS, Z
COUNTH, F
COUNTL, F
; Set Z if lower byte == 0
; if so, decrement COUNTH
; in either case decrement COUNTL
Test a 16-bit variable for zero
movf
btfsc
movf
btfsc
goto
COUNTL, F
STATUS, Z
COUNTH, F
STATUS, Z
BothZero
; Set Z if lower byte == 0
; If not, then done testing
; Set Z if upper byte == 0
; if not, then done
; branch if 16-bit variable == 0
CarryOn
PIC Microcontroller
Prof. Yan Luo,
UMass Lowell
8
A Delay Subroutine
; ***********************************************************************************
; TenMs subroutine and its call inserts a delay of exactly ten milliseconds
; into the execution of code.
; It assumes a 4 MHz crystal clock. One instruction cycle = 4 * Tosc.
; TenMsH equ 13
; Initial value of TenMs Subroutine's counter
; TenMsL equ 250
; COUNTH and COUNTL are two variables
TenMs
nop
movlw
movwf
movlw
movwf
Ten_1
decfsz
goto
decfsz
goto
return
4/12/2020
TenMsH
COUNTH
TenMsL
COUNTL
COUNTL,F
Ten_1
COUNTH,F
Ten_1
; one cycle
; Initialize COUNT
COUNTH = TenMsH
COUNTL = TenMsL
COUNTL = COUNTL
-1
Yes
No
COUNTL == 0 ?
Yes
COUNTH = COUNTH - 1
Yes
; Inner loop
No
COUNTH == 0 ?
; Outer loop
Yes
return
Microprocessors I: Lecture 33
9
Next time


4/12/2020
PIC programming examples
Lab 5 discussion
Microprocessors I: Lecture 33
10
Download
Study collections