Professional Documents
Culture Documents
PIC Microcontrollers: Chapter 7: Addressing Modes, Bank Switching, Table Processing
PIC Microcontrollers: Chapter 7: Addressing Modes, Bank Switching, Table Processing
PIC Microcontrollers: Chapter 7: Addressing Modes, Bank Switching, Table Processing
▫ Or this
▫ Because FSR0, FSRl, and FSR2 are 12-bit registers they cannot fit into
the SFR address space unless they are split into pieces of an 8-bit size.
▫ That is exactly what PIC18 has done.
▫ The FSR registers have the low-byte and high-byte parts called FSRxL
and FSRxH, as shown in the SFR table.
▫ we see FSR0L and FSR0H, representing the low and high parts of the 12-
bit FSR0 register.
▫ Note that the FSRxH is only 4-bit and the upper 4 bits are not used.
• Example: Write a program to copy the value 55H into RAM memory
locations 40H to 45H using
(a) Direct addressing mode.
(b) Register indirect addressing mode without a loop.
(c) A loop.
MOVLW 55H
LFSR 0,0x40
MOVWF INDF0
INCF FSR0L,F
MOVWF INDF0
INCF FSR0L,F
MOVWF INDF0
INCF FSR0L,F
MOVWF INDF0
INCF FSR0L,F
MOVWF INDF0
Gaby A.H- M.S. Fall 2017 - 2018
COUNT EQU 0x10
MOVLW 0x5
MOVWF COUNT
LFSR 0,0x40
MOVLW 0x55
B1 MOVWF INDF0
INCF FSR0L,F
DECF COUNT,F
BNZ B1
30 = ('H')
31 = ('E')
32 = ('L')
33 = ('L')
34 = ('O')
▫ Adding these two numbers gives “0011 1111” B (3FH), which is not BCD!
▫ A BCD number can only have digits from 0000 to 1001 (or 0 to 9).
▫ In other words, adding two BCD numbers must give a BCD result.
▫ The result above should have been 17 + 28 = 45 (0100 0101).
▫ To correct this problem, the programmer must add 6 (0110) to the low digit: 3F +
06 = 45H.
▫ The same problem could have happened in the upper digit (for example, in 52H +
87H = D9H).
▫ Again, 6 must be added to the upper digit (D9H + 60H = 139H) to ensure that the
result is BCD (52 + 87 = 139).
▫ This problem is so widespread that most microprocessors such as the PIC 18
have an instruction to deal with it.
▫ In the PIC18 instruction "DAW" is designed to correct the BCD addition
problem.
MOVLW 0
MOVWF H_Byte
ADDWF 0x40,W
DAW
BNC N_1
INCF H_Byte,F
N_1 ADDWF 0x41,W
DAW
BNC N_2
INCF H_Byte,F
N_2 ADDWF 0x42,W
DAW
BNC N_3
INCF H_Byte
N_3 ADDWF 0x43,W
DAW
BNC N_4
INCF H_Byte,F
N_4 MOVWF L_Byte
ORG 500H
DATA1 DB D'28'
DATA2 DB B'00110101'
DATA3 DB 0x39
ORG 510H
DATA4 DB 'Y'
DATA5 DB '2','0','0','5'
ORG 518H
DATA6 DB "Hello ALI"
END