Documente Academic
Documente Profesional
Documente Cultură
Language Programming
Hsiao-Lung
H
i L
Chan
Ch
Dept Electrical Engineering
Chang Gung University, Taiwan
chanhl@mail cgu edu tw
chanhl@mail.cgu.edu.tw
Working
g register
g
(WREG)
(
)
MOVLW instruction
MOVLW K
MOVLW 25H
MOVLW 7F2H ; illegal 7F2H > 8 bits (FFH), become F2H
Instruction format
16 bits
ADDLW instruction
ADDLW K
MOVLW 25H
ADDLW 34H
Literal value
WREG register
g
and ALU using
g literal value
up to 2 MB of
program memory
4096 registers
Program
P
Memory
Space
(a portion
of this
space is on
the c
chip)
Program
counter
(PC)
PIC18
CPU
16-bit instruction bus
Data
Memory
Space
(Special
function
registers and
general
purpose
RAM))
Fi
Figure
1.3
1 3 The
Th PIC18 memory spaces
4
File register
g
(data
(
RAM))
Data storage
g
SFRs in PIC18
File registers
g
of PIC12, PIC16, and PIC18
File register
g
allocation in PIC18
PIC18 banks
Bank switching
Access bank
10
MOVWF instruction
Ex. 2
MOVLW 99H
MOVWF 12H
default
f
11
ADDWF fileReg, D
Ex1
MOVLW
MOVWF
MOVLW
ADDWF
(ADDWF
28H
5H
56H
5H, 0
or ADDWF 5H, 1
5H, W or ADDWF 5H, F)
12
WREG, fileReg,
g and ALU in PIC18
13
14
File register
g
instructions
15
COMF instruction
B1
MOVLW 55H
MOVWF PORTB
COMF
PORTB
GOTO
B
16
DECF instruction
3
20H
0x20, F ; loc 20H has 2
0x20, W ; loc 20H still has 2 but WREG = 1
17
MOVF instruction
MOVF
filereg, D
PORTB, W
PORTC
O
AGAIN
18
MOVFF instruction
19
PORTB, PORTC
AGAIN
20
GOTO instruction
32-bit
32
bit instruction
21
22
Status register
g
example
p
23
Status register
g
example
p (cont.)
(
)
24
25
26
Assembling
g and linking
g a PIC program
p g
27
List file
28
29
Program
g
ROM width for PIC18
30
PIC on-chip
p program
p g
ROM address range
g
31
PIC18 Program
g
ROM space
p
32
Reference
33