Professional Documents
Culture Documents
Embedded Software Design: R.A. Prabhath Buddhika
Embedded Software Design: R.A. Prabhath Buddhika
--Embedded Software
Set 5
Lecture 04
--Embedded Software
Set 5
22
objectives
PIC16F Types
of instructions
Addressing
Set 5
33
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
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
Addressing modes
An
Immediate/literal
direct indirect
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
0000000
clrwdt retfie nop
???????
clrwdt
88
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
99
Generating a 13-bit program-store address from a 11-bit absolute address field for the goto and call instructions
Set 5
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]
Selecting the destination of the outcome from the instruction addwf h26
Set 5
12
Can you remember where RP0 is located? RP0 is the 5th bit of the status register
Whenever the data store address is b0000000, 8-bit contents of the FSR is switched to the Data stores address bus.
Set 5
15
A total of 224 GPRs 16 are shadowed (mirrored) for fast access (for frequently used data)
Set 5
16
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
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
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.
Set 5
21
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
CLEAR_ARRAY ; ;
movlw movwf
h'20' FSR
CLOOP
clrf 0
; 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
24
Thank You
Set 5
25