Upload
others
View
1
Download
0
Embed Size (px)
Citation preview
Lecture 3
EN 318
1
EN 318
2
Status Register
• The STATUS register contains
– Arithmetic status of the ALU
– RESET status
– Bank select bit for data memory.
• As with any register, the STATUS register can
3
• As with any register, the STATUS register can
be the destination for any instruction.
4
Status Register
• Z, DC, C, TO and PD bits are not writable.
– These bits are set or cleared according to device logic.
• For example, CLRF STATUS will clear the upper-three bits and set the Z bit. This leaves the
5
upper-three bits and set the Z bit. This leaves the STATUS register as 000u u1uu (where u = unchanged).
• Only the BCF, BSF, SWAPF and MOVWF instructions should be used to alter the STATUS register because these instructions do not affect any status bit.
PIC Instruction Set
• The instruction set for the PIC16F84
consists of 35 single word instructions
• These are grouped into three major
categories
6
categories
– Byte-oriented
– Bit-oriented
– Literal and control
7
List and Equates
• Before writing your program, you need to describe the
type of device that the program is to be burned to
List p=16F84
• Equate
– Similar to variable declaration in other programming
8
languages.
– Labels are assigned to addresses. Later, whenever that label is
referred to in the program, the compiler looks up its address.
• E.g. Assigns ‘portB’ to the file register located at 0x06.
Port B is always located at this file register.
portB equ 0x06
Sample Program
LIST P=16F84
PORTB equ 0x06
TRISB equ 0x06
STATUS equ 0x03
RP0 equ 0x05
org 0
movlw 0x0FD
9
movlw 0x0FD
movwf PORTB
bsf STATUS, RP0
bcf TRISB 0x080, 1
bcf TRISB 0x080, 2
movlw 0x07F
• Each instruction is a 14-bit word divided into:
• An OPCODE which specifies the instruction type
• One or more operands which further specify the operation of the
instruction.
10
Field Description
11
CLRF
12
CLRW
13
ADDLW
14
ADDWF
15
MOVLW
16
MOVF
17
MOVWF
18
Exercise
• Write a program to clear W and Port B, then add
0x0A to 0x0B and send it out thru Port B.
19
CALL
20
GOTO
21
Example for CALL and GOTOlist p=16F84
goto Main
; Subroutine
Delay
movlw 0xff
movwf 0x0c
L1 nop
decfsz 0x0c,1
goto L1
22
goto L1
return
; Main program
Main
movlw 0x0
tris porta
tris portb
movlw 0xff
movwf portb
call Delay
Exercise
• Write a subroutine to clear PortB and send data
in W to PortB
• Write a program to add 0xA to 0xB and send it to
PortB (use the subroutine)
23
INCF
24
DECF
25
INCFSZ
26
DECFSZ
27
NOP
28
Exercise
• Write a subroutine to delay for 1 msec, given that
your input clock is 4 MHz
29
• Loops & Timing analysis
• Subroutine
30