PIC Architecture Instruction Set 9206 Lecture 21 PIC

  • Slides: 20
Download presentation
PIC Architecture Instruction Set 9/20/6 Lecture 21 -PIC Architecture 1

PIC Architecture Instruction Set 9/20/6 Lecture 21 -PIC Architecture 1

PICs-Instruction Set o Have Covered Instruction Set Basics n n n o 9/20/6 Accumulator

PICs-Instruction Set o Have Covered Instruction Set Basics n n n o 9/20/6 Accumulator Architecture Direct addressing Indirect addressing Now lets look at the instructions Lecture 21 -PIC Architecture 2

MOVE instructions o o PIC spend a lot of time moving data around as

MOVE instructions o o PIC spend a lot of time moving data around as data stored in memory movlw 20 n n o movlw -2 n 9/20/6 Move the hex value H’ 20’ into W To load a decimal must use the correct assembler directive - D’ 20’ Loads B’ 1111 1110 into WREG Lecture 21 -PIC Architecture 3

More on MOVE o Initialization of a variable n n n o Assembler MACRO

More on MOVE o Initialization of a variable n n n o Assembler MACRO n n 9/20/6 movlw B’ 11100000’ movwf TRIST Initialize the PORTB data direction register MOVLF B’ 11100000’, TRISB Assembled into the two instructions above Lecture 21 -PIC Architecture 4

The movff instruction o movff n n movff - a two-word instruction Thus source

The movff instruction o movff n n movff - a two-word instruction Thus source and destination have 12 -bit addresses o o n n 9/20/6 PORTB, PORTB_COPY Source – instruction bits + BSR Destination – instruction 2 nd byte Moves data from a 1 -byte source to a 1 -byte destination. For instruction memory as efficient as the regular move instruction. Lecture 21 -PIC Architecture 5

The movwf o movwf f(, Banked) – Move WREG to f o For storing

The movwf o movwf f(, Banked) – Move WREG to f o For storing back the result of an operation Does not affect status bits o 9/20/6 Lecture 21 -PIC Architecture 6

The movf instruction o o 9/20/6 Move the value and set the status register

The movf instruction o o 9/20/6 Move the value and set the status register bits appropriately Affects N and Z bits Lecture 21 -PIC Architecture 7

Move summary o o movlw k - load literal value movwf MYVAR - move

Move summary o o movlw k - load literal value movwf MYVAR - move value but do not affect status bits movff V 1, V 2 - move data at source address to data at destination address movf f, F/W - move value and affect status bits n 9/20/6 What does movf COUNT, F Lecture 21 -PIC Architecture do? 8

Other move/load instructions o lrsr 0, num 1 n n o n movff FSR

Other move/load instructions o lrsr 0, num 1 n n o n movff FSR 0 L, FSR 0 L_TEMP movff FSR 0 H, FRS 0 H_TEMP Loading a FSR register n n 9/20/6 1 st argument is FSR register number 2 nd argument is value to load Saving a FSR register n o - load FSR register movff FSR 0 L_TEMP, FSR 0 L movff FRS 0 H_TEMP, FSR 0 H Lecture 21 -PIC Architecture 9

Load BSR register & other o movlb 2 n o o o 9/20/6 Load

Load BSR register & other o movlb 2 n o o o 9/20/6 Load the value of 2 into the BSR register clrf TEMP – Load 0 x 00 into variable TEMP setf TEMP – Load 0 xff into variable TEMP swapf f - swap nibbles of f Lecture 21 -PIC Architecture 10

Single operand instructions o Single bit instructions n n n o - Set the

Single operand instructions o Single bit instructions n n n o - Set the lsb of PORTB - clear bit 1 of PORTB - toggle bit 2 of PORTB Rotate instructions illustrated on next slide n n n 9/20/6 bsf PORTB, 0 bcf PORTB, 1 btg PORTB, 2 rlcf rlncf rrncf cf rotate including carry bit ncf rotate without carry bit Lecture 21 -PIC Architecture 11

9/20/6 Lecture 21 -PIC Architecture 12

9/20/6 Lecture 21 -PIC Architecture 12

Logical instructions o o o 9/20/6 andlw B’ 00001111’ And WREG with value andwf

Logical instructions o o o 9/20/6 andlw B’ 00001111’ And WREG with value andwf f, F/W - AND WREG with f putting result back in F or WREG iorlw k -Inclusive OR literal value and WREG iorwf f, F/W – inclusive OR WREG with f and put result into f or WREG xorlw k, xorwf f, F/W - Exclusive OR Lecture 21 -PIC Architecture 13

Arithmetic o o o 9/20/6 addlw k, addwf f, F/W addwfc f, F/W -

Arithmetic o o o 9/20/6 addlw k, addwf f, F/W addwfc f, F/W - Add WREG, F and carry bit daw – Decimal adjust sum of pack BCD subwf, sublw subwfb f, F/W - subtract with borrow Lecture 21 -PIC Architecture 14

Multiplicaiton o o 9/20/6 mullw k - multiply WREG with literal value k putting

Multiplicaiton o o 9/20/6 mullw k - multiply WREG with literal value k putting result in PRODH: PRODL reg WREG unaffected mullwf f(, Banked) - Multiply WREG with f putting results in PRODH: PRODL - both WREG and f remain unchanged Lecture 21 -PIC Architecture 15

Branches o o Needed for program flow control Tests on status register n n

Branches o o Needed for program flow control Tests on status register n n o 9/20/6 bc, bnc, bz, bn, bnn, bov, bnov Use the c, x, n, and ov bits of the status register bra – branch always Lecture 21 -PIC Architecture 16

Conditional Skip instructions o Ten further instructions that test for a condition and skip

Conditional Skip instructions o Ten further instructions that test for a condition and skip over the next instruction if the condition is met. n n n 9/20/6 Next instruction is typically a branch or rcall Very useful at end of a loop Loop code …. decfsz count, F ; Decrement and skip if zero bra top_of_loop Lecture 21 -PIC Architecture 17

Skip instructions o o o o 9/20/6 cpfseq f - skip if f =

Skip instructions o o o o 9/20/6 cpfseq f - skip if f = WREG cpfsgt f - skip if f > WREG cpfslt f - skip if f < WREG tstfsz t - Test f, skip if zero decfsz f, F/W - Decr f, res->WREG, skip if 0 dcfsnz f, F/W - Decr f, res->WREG, skip not 0 incfsz f, F/W – Incr f, res->WREG, skip if 0 infsnz f, F/W – Incr f, res->WREG, skip not 0 Lecture 21 -PIC Architecture 18

Other – Subroutine, interrupt o o o 9/20/6 rcall label - call subroutine (within

Other – Subroutine, interrupt o o o 9/20/6 rcall label - call subroutine (within 512 instr) call label – call subroutine (anywhere) call label, FAST - call subroutine, copy state to shadow registers return – return form subroutine return FAST - return and restore from shadow registers return k - return and put value k in WREG Lecture 21 -PIC Architecture 19

cont o o o o 9/20/6 retfie - return from interrupt and re-enable retfie

cont o o o o 9/20/6 retfie - return from interrupt and re-enable retfie FAST – return, re-enable- restore push - Push addr of next instruction onto stack pop - discard address on top of stack clrwdt - clear watchdog timer sleep - Go into standby mode reset - software controlled reset nop Lecture 21 -PIC Architecture 20