0% found this document useful (0 votes)
29 views27 pages

DEL216D - PIC Chapter 5

Chapter 5 of the document focuses on commands for moving data between registers in microcontroller programming, specifically using PIC microcontrollers. It covers various instructions such as BSF, BCF, MOVF, MOVLW, and GOTO, along with their functionalities and examples. Additionally, it introduces compiler directives like EQU and ORG for managing memory locations and aliases in code.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views27 pages

DEL216D - PIC Chapter 5

Chapter 5 of the document focuses on commands for moving data between registers in microcontroller programming, specifically using PIC microcontrollers. It covers various instructions such as BSF, BCF, MOVF, MOVLW, and GOTO, along with their functionalities and examples. Additionally, it introduces compiler directives like EQU and ORG for managing memory locations and aliases in code.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

Moving Data

Chapter 5 – PIC Notes

Faculty of Information and Communication Technology


Department of Computer Systems Engineering
Aims and Outcomes
• Aims
• To introduce commands used to move data between registers
• To introduce the use of the TRIS registers
• Outcomes
• After completing this chapter you should be able to:
• Set and clear bits in file registers using the BSF and BCF instructions
• Move data between file registers using the MOVF, MOVLW, MOVWF instructions
• Implement the GOTO instruction
• Implement the INCF, DECF, CLRF and CLRW instructions
• Discuss and use the EQU and ORG compiler directives
• Use the TRIS registers to correctly setup the ports

Faculty of Information and Communication Technology


Department of Computer Systems Engineering
Numerical Prefixes
• Decimal
• d’xx’
• Data values can be represented in the • .’xx’
following four formats • xxd
• Confirm the methods your compiler / • Hexadecimal
IDE uses • h’xx’
• 0xAA – Where AA is the hex number
• $F7 – Where F7 is the hex number
• F7h
• Binary
• b’xxxxxxxx’
• 0bxxxxxxxx
• xxxxxxxxb
• ASCII
• ‘A’
• A’…’

Faculty of Information and Communication Technology


Department of Computer Systems Engineering
Introduction to Instructions
• Instructions are used to create a programs
• Instructions are divided into
• Byte-oriented operations
• Bit-oriented operations
• Literal and control operations
Figure 15.2: General Format for Instructions
(Microchip, 2003. p108)

Faculty of Information and Communication Technology


Department of Computer Systems Engineering
OPCODE field Description
• The instruction operands Field Description

indicates the type of data to be f Register file address

used by a specific instruction w Working register


b Bit address within an 8-bit
• Most of the time it can also be file register
deduced from the command k Literal field, constant or
being used label
d Destination select
• MOVLW k d=0: Store results in w
d=1: Store results in f
default is: d=1

Faculty of Information and Communication Technology


Department of Computer Systems Engineering
Instruction Format
• Instructions are 14-bit words divided
into OPCODES and operands
• OPCODES indicate the instruction
type
• Operands specify the operation of
the instruction

Figure 15.1: General Format for Instructions Faculty of Information and Communication Technology
(Microchip, 2003. p107) Department of Computer Systems Engineering
Instruction Construction Example

Figure 15.2: PIC16F62X


Instruction Set (Microchip, 2003.
p108)

• The opcodes for all the instructions are at the back of the PIC notes
and also in the datasheet.
• The included table only shows the literal and control operations.
• As an example let us use the following instruction: GOTO 10h

Faculty of Information and Communication Technology


Department of Computer Systems Engineering
Instruction Construction: GOTO 10h

Figure 15.2: PIC16F62X


Instruction Set (Microchip, 2003.
p108)

• The OPCODE for the GOTO command is: 1012

Faculty of Information and Communication Technology


Department of Computer Systems Engineering
Instruction Construction: GOTO 10h

Figure 15.2: PIC16F62X


Instruction Set (Microchip, 2003.
p108)

• An binary equivalent address must be provided: kkk kkkk kkkk2


• The address 1016 in binary is: 0001 00002

Faculty of Information and Communication Technology


Department of Computer Systems Engineering
Instruction Construction: GOTO 10h

Figure 15.2: PIC16F62X


Instruction Set (Microchip, 2003.
p108)

• The machine code for the command: GOTO 10h, is:

• 101 000 0001 00002

Faculty of Information and Communication Technology


Department of Computer Systems Engineering
W Register
• The Working Register (W) can be seen as a gateway through which all
the data travels towards its new destination
• W is an 8-bit register only accessible by the ALU i.e. does not have a
memory location we can access
• W can be the destination of data movement when using some
commands and setting the destination bit (d) to 1

Faculty of Information and Communication Technology


Department of Computer Systems Engineering
BSF f,b
• Bit Set File is used to SET (change bit to ‘1’) a specific bit inside a file
register
• f = file address
• b = bit position in the file address
• It can only set 1 bit and not set multiple bits

(Spies, 2020. p41)

Faculty of Information and Communication Technology


Department of Computer Systems Engineering
BCF f,b
• Bit Clear File is used to CLEAR (change bit to ‘0’) a specific bit inside a
file register
• f = file address
• b = bit position in the file address
• It can only clear 1 bit and not clear multiple bits

(Spies, 2020. p41)

Faculty of Information and Communication Technology


Department of Computer Systems Engineering
MOVLW k
• Copies a literal value (k) into the working register
• A literal value can be seen as a physical value the programmer wants
to load into the microcontroller
• k = literal value that must be copied to the working register

(Spies, 2020. p41)

Faculty of Information and Communication Technology


Department of Computer Systems Engineering
MOVWF f
• Copy the value of the working register into file register f
• f = address of the file wherein the value needs to be loaded

(Spies, 2020. p41)

Faculty of Information and Communication Technology


Department of Computer Systems Engineering
MOVF f,d
• The content of the selected
register, f, is copied to a
destination depending on the (Spies, 2020. p41)
value of d
• f = file that must be copied from
• d = 0 – destination is the w
register
• d = 1 – destination is back to the (Spies, 2020. p41)

file

Faculty of Information and Communication Technology


Department of Computer Systems Engineering
GOTO k
• This is used to branch off to a specific label
• GOTO is a two-cycle instruction
• k = label name whereto program must branch

(Spies, 2020. p41)

Faculty of Information and Communication Technology


Department of Computer Systems Engineering
INCF f,d
• Increment the content of file f, by 1
• Save the answer into either the w register or the file itself depending on
the value of d
• d=0 – Destination is w register
• d=1 – Destination is the file register, f

(Spies, 2020. p41)

Faculty of Information and Communication Technology


Department of Computer Systems Engineering
DECF f,d
• Decrement the content of file f, by 1
• Save the answer into either the w register or the file itself depending on
the value of d
• d=0 – Destination is w register
• d=1 – Destination is the file register, f

(Spies, 2020. p41)

Faculty of Information and Communication Technology


Department of Computer Systems Engineering
CLRF f
• Clears the value of register f

(Spies, 2020. p41)

Faculty of Information and Communication Technology


Department of Computer Systems Engineering
CLRW
• Clears the value of the w register
• It does the same as the shown MOVLW instruction

(Spies, 2020. p41)

Faculty of Information and Communication Technology


Department of Computer Systems Engineering
PORT Setup Example
• Suppose we want to use RB0 to
connect an LED to flash
• Steps
• Go to Bank 1
• Change RB0 to an output pin
• Go back to Bank 0

(Spies, 2020. p41)

Faculty of Information and Communication Technology


Department of Computer Systems Engineering
Moving Data to a PORT
• A PORT is associated with a
memory location
• Writing data to a port is the
same as writing data to a
memory location
• The code shows how to flash an (Spies, 2020. p41)

LED connected to RB2


• Remember that all the other bits
on the port will be cleared!

Faculty of Information and Communication Technology


Department of Computer Systems Engineering
Compiler Directive -
EQU
• It is used to substitute text
(create an alias)
• The compiler does not
understand the meaning it just
replaces the equated value
when compiling
• Some compilers might already
have the reserved
registers/pins equated (Spies, 2020. p41)

Faculty of Information and Communication Technology


Department of Computer Systems Engineering
Compiler Directive -
ORG
• ORG is used to compile
program code into specific (Spies, 2020. p41)

memory location
• Its primarily used to skip over
the interrupt vector located at
h’04’
• Look at the memory after the
compilation

Faculty of Information and Communication Technology


Department of Computer Systems Engineering
End of Chapter
Any questions?

Faculty of Information and Communication Technology


Department of Computer Systems Engineering
References
• Microchip, 2003. PIC16F62X Data Sheet. [online] Microchip
Technology. Available at:
<https://ww1.microchip.com/downloads/en/DeviceDoc/40300c.pdf>
[Accessed 4 June 2020].
• Spies, J., 2020. An Introduction To Microcontroller Concepts Using The
PIC Microcontroller.

Faculty of Information and Communication Technology


Department of Computer Systems Engineering

You might also like