LU - Microprocessor I - Chap11 - The PIC18F Microcontrollers - Bank Switching and Table Processing - FA2017
LU - Microprocessor I - Chap11 - The PIC18F Microcontrollers - Bank Switching and Table Processing - FA2017
The PIC18 provides a total of four distinct addressing modes. They are
as follows:
1. Immediate
2. Direct
3. Register indirect
4. Indexed-ROM
‒ Notice that When the second parameter is not stated, it is assumed to be fileReg (F)
Not all the address space of F80H to FFFH is used by the SFR. The
unused locations are reserved and must not be used by the PIC18
programmer.
The FSR registers have the low-byte and high-byte parts called FSRxL
and FSRxH.
Note that the FSRxH is only 4-bit and the upper 4 bits are not used.
Each of the FSR0, FSR1, and FSR2 registers has an INDF register
associated with it, and these are called INDF0, INDF1, and INDF2.
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 loop.
c. A loop.
Using the "INCF FSR0L, F" instruction to increment the pointer can
cause a problem when an address such as 5FF is incremented.
The instruction "INCF FSR0L, F" will not propagate the carry into the
FSR0H register.
‒ Note: This table shows the syntax for the CLRF instruction, it works for all such
instructions.
Microprocessor I – 4th year Electrical Engineering – Chapter 11 23
Dr. Mohamad Mroué
Auto-increment option for FSR
The auto-decrement or auto-increment affects the entire 12 bits of
the FSRn and has no effect on status register.
‒ This means that FSR0 going from FFF to 000 will not raise any flag.
• LFSR FSR1,0x0120
• LFSR FSR2,0x0150
• MOVFF POSTINC1, POSTINC2
The DB data directive is widely used to allocate ROM program (code) memory in
byte-sized chunks.
DB is used to define an 8-bit fixed data.
‒ The numbers can be in decimal, binary, hex, or ASCII formats.
The DB is used to define ASCII strings.
‒ We must use single quotes (') for a single character or double quotes (") for a string.
To read the fixed data byte, we need an address pointer that points to the
data and a register to store the data when it is brought into the CPU.
‒ TBLPTR is a 21-bit register and is used to point to the byte to be fetched.
TBLPTR is divided into three 8-bit parts.
‒ These are called TBLPTRL (low), TBLPTRH (high), and TBLPTRU (upper), and all are
part of the SFRs.
The other SFR register used for the table processing is TABLAT.
‒ The TABLAT (TABle LATch) register is used for keeping the byte once it is fetched into
the CPU.
21 bit
16 bit
In the PIC, to get the table element we first call the look-up table,
then we add a fixed value to the PCL (low-byte portion of the program
counter) to index into the look-up table.
‒ Upon return from the table, the RETLW instruction will provide the desired
look-up table element in the WREG register.
The TBLWT can be used only with PIC18 chips that have flash ROM for
the program ROM space.
This means that all I/O ports, SFRs, and general purpose RAM areas for the
PIC18 are bit-addressable because they are part of the file register data
RAM.
‒ WREG is also bit-addressable because it is part of the SFRs.
This is a very powerful feature of the PIC18 family.
Of the 8 bits of the BSR, only 4 least-significant bits are used in the
PIC18.
The upper 4 bits are set to zero and are ignored by the PIC18.
The 4-bit BSR gives us 16 banks, and because each bank is 256 bytes,
we cover the entire 4096 (16 * 256 = 4096) bytes of data RAM file
register using bank switching.
Microprocessor I – 4th year Electrical Engineering – Chapter 11 45
Dr. Mohamad Mroué
The BSR register and bank switching
Upon power-on reset, BSR = 0 (0000 binary), which indicates that
only the lowest addresses of data RAM, from 000 to 0FFH, can be
used for the general-purpose register in addition to the SFRs, which
always reside in the last half of bank F.