Loading in 5 sec....

16.317: Microprocessor System Design IPowerPoint Presentation

16.317: Microprocessor System Design I

- 150 Views
- Uploaded on
- Presentation posted in: General

16.317: Microprocessor System Design I

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

16.317: Microprocessor System Design I

Instructor: Dr. Michael Geiger

Spring 2012

Lecture 33: PIC instruction set, pt. 3

- Announcements/reminders
- Lab 4 due 4/25
- Limited # of PICkits strongly suggest you work in a group for the last two assignments
- PICkits can be checked out from the lab

- Lab 5posted; 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

- Lab 4 due 4/25
- Lecture outline
- Review: PIC instructions
- Logical ops
- Goto/call/return
- Misc

- Continue with PIC instructions

- Review: PIC instructions

Microprocessors I: Lecture 33

- Logical operations
- andlw/andwf
- iorlw/iorwf
- xorlw/xorwf

- Rotates
- rrf
- rlf

- Jumps/calls/return
- goto
- call
- return/retlw/retfie

- Miscellaneous
- nop
- sleep/clrwdt

Microprocessors I: Lecture 33

STATUS bits:

none

Examples:

- btfsc TEMP1, 0; Skip the next instruction if bit 0 of TEMP1 equals 0
- btfss STATUS, C; Skip the next instruction if C==1
- decfsz TEMP1, F; Decrement TEMP1, skip if TEMP1==0
- incfsz TEMP1, W ; W <- TEMP1+1 , skip if W==0 (TEMP1==0xFF)
; Leave TEMP1 unchanged

- Conditional execution in PIC: skip next instruction if condition true
- Two general forms
- Test bit and skip if bit clear/set
- Increment/decrement register and skip if result is 0

btfsc f, b ;Test bit b of register f, where b=0 to 7, skip if clear

btfss f, b ;Test bit b of register f, where b=0 to 7, skip if set

decfsz f, F(W) ;decrement f, putting result in F or W, skip if zero

incfsz f, F(W) ;increment f, putting result in F or W, skip if zero

Microprocessors I: Lecture 33

- Show the values of all changed registers after each of the following sequences
- What high-level operation does each perform?

(a)movfa, W

sublw0xA

btfscSTATUS, Z

gotoL1

incfb, W

gotoL2

L1

decfb, W

L2

movwfa

(b)movfNUM2, W

subwfNUM1, W

btfssSTATUS, C

gotoBL

movfNUM1, W

gotoDone

BL

movfNUM2, W

Done

movwfMAX

Microprocessors I: Lecture 33

movfa, W W = a

sublw0xA W = 10 – a

btfscSTATUS, Z Skip goto if result

is non-zero

gotoL1 Goto L1 if result == 0

Reach this point if

result non-zero

incfb, W W = b + 1

gotoL2

L1

decfb, W W = b - 1

L2

movwfa a = W value depends

on what’s executed before this

High-level operation:

if ((10 – a) == 0)

a = b – 1

else

a = b + 1

Microprocessors I: Lecture 33

movfNUM2, W W = NUM2

subwfNUM1, W W = NUM1 – W

= NUM1 – NUM2

btfssSTATUS, C Carry indicates

“above”

if set, NUM1 > NUM2

gotoBL

movfNUM1, W if (NUM1 >= NUM2)

W = NUM1

gotoDone Skip “below” section

BL

movfNUM2, W if (NUM1 < NUM2)

W = NUM2

Done

movwfMAX

High-level operation:

if (NUM1 < NUM2)

MAX = NUM2

else

MAX = NUM1

Microprocessors I: Lecture 33

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

movfCOUNTL, F ; Set Z if lower byte == 0

btfscSTATUS, Z

decfCOUNTH, F ; if so, decrement COUNTH

decfCOUNTL, F ; in either case decrement COUNTL

Test a 16-bit variable for zero

movfCOUNTL, F ; Set Z if lower byte == 0

btfscSTATUS, Z ; If not, then done testing

movfCOUNTH, F ; Set Z if upper byte == 0

btfscSTATUS, Z ; if not, then done

gotoBothZero ; branch if 16-bit variable == 0

CarryOn

PIC Microcontroller Prof. Yan Luo, UMass Lowell

; ***********************************************************************************

; 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.

; TenMsHequ 13; Initial value of TenMs Subroutine's counter

; TenMsLequ 250

; COUNTH and COUNTL are two variables

TenMs

nop; one cycle

movlwTenMsH; Initialize COUNT

movwfCOUNTH

movlwTenMsL

movwfCOUNTL

Ten_1

decfszCOUNTL,F; Inner loop

gotoTen_1

decfszCOUNTH,F; Outer loop

goto Ten_1

return

Microprocessors I: Lecture 33

- PIC programming examples
- Lab 5 discussion

Microprocessors I: Lecture 33