• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer

Electrical Engineering News and Products

Electronics Engineering Resources, Articles, Forums, Tear Down Videos and Technical Electronics How-To's

  • Products / Components
    • Analog ICs
    • Battery Power
    • Connectors
    • Microcontrollers
    • Power Electronics
    • Sensors
    • Test and Measurement
    • Wire / Cable
  • Applications
    • 5G
    • Automotive/Transportation
    • EV Engineering
    • Industrial
    • IoT
    • Medical
    • Telecommunications
    • Wearables
    • Wireless
  • Learn
    • eBooks / Handbooks
    • EE Training Days
    • Tutorials
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • White Papers
    • Design Guide Library
    • Digital Issues
    • Engineering Diversity & Inclusion
    • LEAP Awards
    • Podcasts
    • DesignFast
  • Videos
    • EE Videos and Interviews
    • Teardown Videos
  • EE Forums
    • EDABoard.com
    • Electro-Tech-Online.com
  • Bill’s Blogs
  • Advertise
  • Subscribe

PIC 16F and register banking explained

July 27, 2016 By Aimee Kalnoskas

by Jon Wilder

Microchip PICAs some of you have noticed, the internal RAM in the PIC 16F appears to be arranged in “banks”. Each bank holds 128 RAM registers total. The first 128 RAM locations are in bank 0, the next 128 RAM locations are in bank 1, so on and so forth.

But hold on…is this REALLY the case? If it is, then why is it that when we indirect address via the FSR pointer register that we can access 256 RAM locations without having to bank select?

Because this isn’t what’s really going on.

iRAM on a PIC 16F is a contiguous space. It starts at address 0x000 and ends at 0x1FF. However, some locations within this space are unimplemented. The datasheet states that iRAM is divided up into 4 banks of 128 registers each. Why is this?

The reason is because there is a limitation in the instructions that the PIC uses to address iRAM locations (basically all of the instructions which have an “f” in them). Byte-oriented instructions which address the registers are in the format of –

Code (text):
PIC 16F

Bit-oriented operations (bsf, bcf, btfss and btfsc) are in the format of –

Code (text):
PIC 16F 2
The opcode is the instruction itself. In the first table, DST is the destination bit that tells the PIC whether to store the result in W (0) or in the file register (1) who’s address is in bits AD0-AD6. In the second table, the 4 MSBs are the instruction, the 3 “BIT” bits are the bit that the instruction will be executed on (0-7), while AD0-AD6 are the address in the file where the bit to be manipulated resides.

Notice AD0-AD6…that’s only 7 address bits!

Basically, instructions which directly address the iRAM register locations can only provide 7 of the address bits. Since 7 bits can only count to 0x7F (decimal 127), this limits the instruction itself to only access 128 RAM locations on its own…hence the limitation.

So how can we overcome the limitation so that we can address the entire iRAM space? With the addition of two more bits of course, but where would they come from?

Simple…the STATUS register!

We’ve all heard them referred to as the “bank select” bits but this is just a convention that Microchip decided to use for its “register banking” concept. Bits RP1 and RP0 (Register Page 1 and Register Page 0 respectively) serve as the upper 2 address bits for instructions which directly address the iRAM locations.

So say for instance we wanted to move a value in W to register TRISA, which has iRAM address 0x85 (b’010000101). The instruction could not supply the leading “01” in the address, so these two bits must come from register bits RP0 and RP1. So prior to writing the contents of W to register TRISA, we must first execute these two instructions –

bsf STATUS,RP0
bcf STATUS,RP1

This makes bit RP1 a 0 while making bit RP0 a 1, which gives us the leading “01” in TRISA’s address.

Now we want to write to PORTA, which resides at iRAM address 0x05 (b’000000101′). Now the leading two bits must be cleared to access location 0x05 –

bcf STATUS,RP0
bcf STATUS,RP1

This clears both of our RP bits, giving us the two leading zeros at the beginning of our instruction, while the remaining 7 bits come from the instruction itself.

With indirect addressing using the FSR register, we only need 1 more bit. This is because the FSR is an 8 bit register so it can address up to 256 iRAM locations on its own. Its 9th bit comes from bit IRP (Indirect Register Page) in the STATUS register.

With a more conventional processor like the Intel 8051, a mov instruction is 8 bits long, followed by 1 or 2 more bytes that provide the address(es) that the mov instruction is being executed on. With an instruction set of this nature, no iRAM ‘banking’ is required. But since the PIC is a RISC processor with a single 14 bit instruction word, there will be limits to what can be done and how things must be done, and this is one of them.

If we were to use the FSR to indirectly address register TRISA, we could simply load the FSR with the value of 0x85, load W with the immediate value to write to TRISA, then load the value in W into the INDF register without having to bank select. This is because register FSR is an 8 bit register and can supply 8 of the 9 address bits on its own. However, we must ensure that bit IRP in the STATUS register is clear prior to doing this otherwise we would end up writing to iRAM register address 0x185 instead of 0x085.

So there you have it…PIC 16F register banking explained.

The post PIC 16F and register banking explained appeared first on Microcontroller Tips.

You Might Also Like

Filed Under: Featured, Microcontroller Tips Tagged With: electrotechonline

Primary Sidebar

EE Engineering Training Days

engineering

Featured Contributions

Five challenges for developing next-generation ADAS and autonomous vehicles

Robust design for Variable Frequency Drives and starters

Meeting demand for hidden wearables via Schottky rectifiers

GaN reliability milestones break through the silicon ceiling

From extreme to mainstream: how industrial connectors are evolving to meet today’s harsh demands

More Featured Contributions

EE Tech Toolbox

“ee
Tech Toolbox: Internet of Things
Explore practical strategies for minimizing attack surfaces, managing memory efficiently, and securing firmware. Download now to ensure your IoT implementations remain secure, efficient, and future-ready.

EE Learning Center

EE Learning Center
“ee
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.
“bills
contribute

R&D World Podcasts

R&D 100 Episode 10
See More >

Sponsored Content

Advanced Embedded Systems Debug with Jitter and Real-Time Eye Analysis

Connectors Enabling the Evolution of AR/VR/MR Devices

Award-Winning Thermal Management for 5G Designs

Making Rugged and Reliable Connections

Omron’s systematic approach to a better PCB connector

Looking for an Excellent Resource on RF & Microwave Power Measurements? Read This eBook

More Sponsored Content >>

RSS Current EDABoard.com discussions

  • ADS optimization cockpit window does not open
  • How to simulate power electronics converter in PSpice?
  • How to fix error code 3221226356 on Ansys electronic desktop 2020 R1?
  • MOSFET thermal noise in Weak vs Strong inversion
  • Voltage mode push pull with extra DC blocking capacitor

RSS Current Electro-Tech-Online.com Discussions

  • Is AI making embedded software developers more productive?
  • Can I make two inputs from one??
  • Why can't I breadboard this oscillator?
  • Cataract Lens Options?
  • Leakage Current to Earth Through Mains-Powered Multimeter?
Search Millions of Parts from Thousands of Suppliers.

Search Now!
design fast globle

Footer

EE World Online

EE WORLD ONLINE NETWORK

  • 5G Technology World
  • Analog IC Tips
  • Battery Power Tips
  • Connector Tips
  • DesignFast
  • EDABoard Forums
  • Electro-Tech-Online Forums
  • Engineer's Garage
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips

EE WORLD ONLINE

  • Subscribe to our newsletter
  • Teardown Videos
  • Advertise with us
  • Contact us
  • About Us

Copyright © 2025 · WTWH Media LLC and its licensors. All rights reserved.
The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media.

Privacy Policy