Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Banks in PIC Microcontrollers

Status
Not open for further replies.

baberjaved

New Member
I cannot seem to understand this concept from anywhere but Can someone explain to me why do we need to select certain Banks while programming PIC mCU's... and how do I know if i have selected the correct Bank?
 
Simply because different GPR's and special registers are in different banks, you 'know' you have selected the correct bank because you specifically do it - refer to the datasheet for which registers are in which bank (some are in multiple banks as well).
 
Because pic instructions are only 14 bit each then only 7 bits were available to contain a ram address, this meant that the chip could only access 128 bytes of ram. To get around this limitation, Microchip added 2 more bits to the STATUS register that act as bits 8 and 9 of the ram address, this makes the addressable ram a much more usable 512 bytes. These 2 additional bits are referred to as the bank bits and you have to set and clear them in order to access the different banks of ram. Some of these ram locations contain special function registers and so this ram is referred to as SFRs and the other locations are referred to as file registers (FRs). The only way to know where a certain SFR is is by consulting the data sheet.

Mike.
 
When I was starting out, I always tried to look at things in a real world example -- basically, in layman's terms. My understanding of bank switching was this;

Imagine you have 4 cupboard doors -- you store the majority of dinnerware in the first, the second has glasses, the third has dessert plates/bowls, the fourth has coffee/tea cups.

For the majority of your dinner party, you will access the first cupboard, where the majority of your dinnerware is stored. However, you are in need of glasses and have asked a guest to get them for you -- but your guest doesn't know what cupboard to go to to find glasses, unless you tell them -- if you don't they will come back and say "the glasses are not in cupboard 1" (they looked in cupboard 1 because it was the closest cupboard -- and they're not smart enough to go to the next cupboard -- unless you upgrade your guests to 18F's!). You then tell your guest that the glasses are in cupboard 2 -- they can then find them when they go to look for them.

So, if you don't tell the microcontroller where the glasses are stored, it will open the cupboard it is closest to, and if the glasses are not there, it will not be able to find them.

When you break it down to it's simplest form, it's quite easy to understand.

"Microcontroller -- I want glasses -- they are in cupboard 2 -- go get them."

"Microcontroller -- I want dessert bowls -- they are in cupboard 3 -- go get them."

"Microcontroller -- I want the SFR 'my_var' -- it is in Bank 3 -- go get it."
 
Status
Not open for further replies.

Latest threads

Back
Top