Understanding the Role of Bank Selection in PIC Microcontroller Programming

In summary, the PIC16F690 has two registers, STATUS and TRISA, that can be accessed from any bank. The 'A' bit in the opcode determines which bank the registers are in, and accessing TRISA requires using the bank select bits.
  • #1
El Moriana
33
0
Hi there. Why is it that when programming PIC microcontrollers, you are forced to select the correct bank/page for registers like TRISA, but you can always do operations on STATUS?

From the PIC that I am using (PIC16F690) STATUS is stored in Bank 0 and TRISA is stored in Bank 1.

I get it that it's STATUS that controls which bank you are using but what makes it possible to use it whenever?
 
Engineering news on Phys.org
  • #2
This is because of the 'A' bit in the opcode.
Not setting this bit causes the chip to use the 'access buffer',
consisting of the low part of the first RAM page and the high part of the last RAM page (I/O registers).

Your code works because STATUS is in the high part of the I/O registers page.
Accessing TRISA ,which is in the low part of the I/O registers page, requires you to use
the bank select bits.

Hmmmm doubtful that made it clearer. It took me a while to get the hang of it.
Microchips implementation of RAM in the low-end PIC's is, how shall I put it,
suboptimal.

If you have the chance switch up to the 18F series. These have the INDF/FSR registers for indirect RAM access (so you can forget about the cumbersome banking scheme).
 
  • #3
Your question may be a 'why' question... Why is STATUS readable from any bank? Because the designers thought it important enough to make it so!

'How'? That's just part of the internal connection network (probably--I don't have access to the internal details). If you're familiar with Karnaugh maps, this question is somewhat akin to asking how it's possible to address each element of a contiguous half the Karnaugh map, when, in reality, this is (usually) simpler to do than trying to address one or two elements.
 
  • #4
Ok. Still a bit unclear but I get the gist of it. Thanks =)
 

1. What are PIC microcontroller registers?

PIC microcontroller registers are small, high-speed memory locations within a microcontroller that are used to store data temporarily and perform various calculations and operations. They are an essential part of the microcontroller's architecture and are responsible for controlling the flow of data within the device.

2. How many registers are there in a PIC microcontroller?

The number of registers in a PIC microcontroller can vary depending on the specific model, but most PIC microcontrollers have between 32 and 128 registers. These registers are typically organized into different types, such as general-purpose, special function, and control registers.

3. What is the purpose of general-purpose registers in a PIC microcontroller?

General-purpose registers are used to hold temporary data and perform arithmetic and logical operations. They are typically used for storing intermediate values during program execution and can also be used as input/output ports.

4. How are registers accessed in a PIC microcontroller?

Registers in a PIC microcontroller are accessed using special instructions that allow the microcontroller to read from or write to specific registers. These instructions are part of the microcontroller's instruction set and can be used in software programming to control the data flow within the device.

5. Can the values in PIC microcontroller registers be changed?

Yes, the values in PIC microcontroller registers can be changed through software programming. However, it is important to note that some registers may have specific functions and changing their values could affect the overall operation of the microcontroller. Careful consideration and understanding of the microcontroller's architecture and instruction set is necessary when working with registers.

Similar threads

  • Electrical Engineering
Replies
10
Views
2K
  • Electrical Engineering
Replies
4
Views
5K
  • Programming and Computer Science
Replies
3
Views
1K
  • Electrical Engineering
Replies
2
Views
2K
  • Programming and Computer Science
Replies
6
Views
3K
Replies
8
Views
3K
  • Electrical Engineering
Replies
10
Views
3K
Replies
6
Views
6K
  • Computing and Technology
Replies
5
Views
2K
Replies
4
Views
2K
Back
Top