Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 25

Embedded software design

Click Prabhath Buddhika style R.A. to edit Master subtitle


B.Sc.Eng(Hons)(Moratuwa)

--Embedded Software

Set 5

Lecture 04

Instructions set PIC16F


Thanks to Dr. Malitha Wijesundara

--Embedded Software

Set 5

22

objectives
PIC16F Types

instruction set modes

of instructions

Addressing

--Embedded Software Design--

Set 5

33

General form of instructions


General

symbolic form of an instruction in PIC16F instruction set is:


Instruction_mnemonic

<operand A>,<operand B>

Where

operand A is the source datum or its location and operand B the destination.
E.g.:

movf h20, w
--Embedded Software Design-Set 5 44

General form of instructions


Let

us look at addwf [file], d

Adds

W registers contents to the specified files contents and deposits the result either in W or back in the File itself.
Therefore,

addwf h20, f means add the contents of W register to that of File h20 and put the outcome in File h20.
This

--Embedded Software Design-[f20]

is written in shorthand as [f20] W +


Set 5 55

Addressing modes
An

addressing mode is a method that an instruction specifies the location of an operand

Immediate/literal

Inherent Absolute File File

direct indirect

In fact there can be some others in different processors


Set 5 66

--Embedded Software Design--

Instructions can be classified by their addressing modes


Literal

11 ????

LLLLLLLL

Literal instructions use the lower eight instruction word bits to specify a source operand which is a constant datum rather than a byte in a File. In this type destination is always the Working register. The sum W+6 is copied back to the Working register. addlw 06 b 11111000000110
Set 5 77

--Embedded Software Design--

Instructions can be classified by their addressing modes


Inherent

0000000
clrwdt retfie nop

???????

clear watchdog timer return from interrupt and enable

return and sleep b00000000000100


Set 5

clrwdt

--Embedded Software Design--

88

Instructions can be classified by their addressing modes


Absolute

10 ? AAAAAAAAAAA

Two instructions allow the program to jump to another instruction anywhere in the Program store. These are goto and call (call up or go to a subroutine will be discussed later). goto h400 call h530 b 10 1 10000000000 b 10 0 10100110000
Set 5

--Embedded Software Design--

99

Generating a 13-bit program-store address from a 11-bit absolute address field for the goto and call instructions

--Embedded Software Design--

Set 5

Effective 13-bit Programstore


10

Instructions can be classified by their addressing modes


File

Direct

00 ???? 0 FFFFFFF
The

majority of instructions are of this type. These specify that their source and/or destination operand lie in a File. h26,f [f] + [W]
Set 5 11

addwf [f]

--Embedded Software Design--

Selecting the destination of the outcome from the instruction addwf h26

--Embedded Software Design--

Set 5

12

RP0 (register page control) acting as the MSB in 16F84

Can you remember where RP0 is located? RP0 is the 5th bit of the status register

The PIC16F84 Data store


--Embedded Software Design-Set 5 13

Can you remember how to use indirect addressing?

Whenever the data store address is b0000000, 8-bit contents of the FSR is switched to the Data stores address bus.

The PIC16F84 Data store


--Embedded Software Design-Set 5 14

The PIC16F627/8 Data store

--Embedded Software Design--

Set 5

15

The PIC16F627/8 Data store

A total of 224 GPRs 16 are shadowed (mirrored) for fast access (for frequently used data)

--Embedded Software Design--

Set 5

16

General 14-bit core Status Register


--Embedded Software Design-Set 5 17

Fixed Addresses & Indirect Addresses

Fixed Addresses:

The

7-bit address of the operand is fixed as an integral part of the instruction code, and thus cannot be changed as execution progresses. 00 ???? D 0000000
File

Indirect:

All

processors feature some kind of Indirect


Set 5 18

--Embedded Software Design--

The Indirect addressing mechanism

--Embedded Software Design--

Set 5

19

Suppose

we wish to clear the contents of all File registers in Bank 0 of PIC16F627/8. That is from File h20 File h7F. The obvious way would be to use clrf (Clear File) 96 times.
include "p16f627.inc" clrf clrf clrf clrf clrf clrf clrf h'20' h'21' h'22' h'23' h'24' h'25' h'26' ; Clear File 32 ; and File 33 ; Each clear File operation ; uses one instruction ; in the Program store ; File d'37' cleared ; and so on

CLEAR_ARRAY

Program 5.1 Clearing a block of Files in a linear way


20

clrf h'7E' --Embedded Software Design--

Set 5

Is there a more efficient way of doing this by using File Indirect addressing? 1. Set the FSR pointer to the initial array address.
2.

Clear the pointed-to File by targeting File 0. Increment the FSR pointer. Check. Has the pointer gone over the top; in our case, has it reached h80? If no THEN go to item 2. Continue on to the next part of the program. Using a loop to clear an array of data

3. 4.

5. 6.

--Embedded Software Design--

Set 5

21

Application of File Indirect Addressing: Walking through the array

--Embedded Software Design--

Set 5

22

Name the various registers & bits for readibility equ 4; Give File 4 the name FSR (File Select Register) equ 3; Give File 3 the neme STATUS

FSR

STATUS Z

equ

2; in which the Z flag is bit 2

Now for the program proper

CLEAR_ARRAY ; ;

movlw movwf

h'20' FSR

; Put start address in W ; and into the FSR as a pointer

-------------------------------------------------------------------Now for the program proper (i.e. the loop)

CLOOP

dummy read to File 0 (INDF)

clrf 0

; Clear byte pointed to by FSR by ; Increment pointer in FSR

; doing a

incf FSR,f

; Now check; is pointer at top yet? movf FSR,w addlw -h'80' ; Copy pointer address into W ; Compare with the end address (h'80')

Clearing aSTATUS,Z ; IF Files using a repeating loop and Indirect block of Zero flag is set (same) THEN finished btfss addressing goto CLOOP ; ELSE do the next pass through loop
--Embedded Software Design-Set 5 23

Bit
Four

01 ?? NNN FFFFFFF

instructions (as specified by the ?? above) either alter or test the state of a single bit within a register File.
In

this case, the instruction word has embedded 3-bit code NNN defining the bit number from 0 through 7, as well as the File address coded in the normal way.
bcf

h20,7 b 01 00 111 0100000 Bit clear bit 7 in File h20 Bit set in File Set 5

bsf is coded as --Embedded Software Design-- 01

24

Thank You

--Embedded Software Design--

Set 5

25

You might also like