Let's analyze why PIC has BANK and PAGE settings from the perspective of PIC's instruction structure. First, let's look at why PIC divides the RAM area into multiple BANKs.
Carefully observe the format of PIC assembly language instructions. A complete assembly language instruction statement is usually like this: label opcode mnemonic operand 1, operand 2; comment. Among them, the main part is 'opcode mnemonic operand 1, operand 2'.
For example:
Instruction: MOVF 33, 1
Operation code mnemonics: MOVF;
Operand 1: 33;
Operand 2: 1;
When the program is compiled, the main part of the instruction statement will be converted into code form, usually: instruction code operand 2 operand 1.
For example, in a mid-range PIC microcontroller with 14-bit instructions:
Instruction: MOVF 33, 1
Converted code: 00 1000 1 011 0011
The instruction code is: 00 1000 (MOVF f, d=00 1000 dfff ffff);
Operand 2: 1 (d = 1);
Operand 1: 011 0011 (f = 33H);
It can be seen that since the instruction code occupies 6 bits, plus the 1 bit occupied by operand 2, only 7 bits are allocated to operand 1. That is to say, the maximum value of operand 1 can only be '111 1111' (7FH), so the direct addressing range of 'MOVF' can only be between 00H and 7FH. The situation of other instructions for register operations is basically the same, so the PIC microcontroller with a 14-bit instruction number divides every 125 (00H~7FH, 80H~FFH... and so on) registers into a BANK, and defines RP1 and RP0 of the STATUS register as BANK setting bits. When writing a program, to operate a certain register, you must first set the BANK setting bit to switch to the BANK where the register is located.
For example, the EECON1 register (address 18CH) of PIC16F877 must be addressed by setting the BANK. At this time, the address data is composed of 'BANK value + operand 1', where 'BANK value' = 'RP1 RP0'.
For example:
Instruction: BSF EECON1,1;
Code after instruction conversion: 0101 001 000 1100;
At this time, if the 'BANK value' = 3, the addressed address data will be '11 + 000 1110' (18CH); if the BANK value is 0, the addressed address data will be '00 + 000 1110' (0CH), which will result in an error.
We can use the same method to analyze the PAGE setting of PIC. For example, a page of PIC16C5X has 512 instructions. Its 'GOTO' instruction is as follows: '101 k kkkk kkkk' ('GOTO' instruction has no operand 2). We can see that the operand 1 of this instruction can only be '1 1111 1111' (1FFH), so in the PIC16C5X chip with 12 bits of instruction, the 'GOTO' instruction can only jump directly within the range of 512 instructions (000H~1FFH, 200H~3FFH, ...). For the same reason, the PIC16C5X's 'CALL' instruction ('1011 kkkk kkkk') can only call a subroutine within the range of 256 instructions (000H~0FFH, 200H~2FFH, ...), so when programming PIC16C5X, the entry for calling a subroutine should be placed in the first half of the page.
In the PIC16F87X microcontroller with 14-bit instruction bits, the 'GOTO' instruction code is '101 kkk kkkk kkkk', and the 'CALL' instruction code is '100 kkk kkkk kkkk', and their addressing range is '111 1111 1111' (3FFH). Therefore, in the PIC16F87X microcontroller, the length of a page is 3FFH = 2048 instructions (2K). And in use, when using the 'CALL' instruction, there is no need to put the subroutine entry in the upper half of the page.
Previous article:PIC16F877A internal EEPROM read and write experiment using internal functions
Next article:What are the possible reasons why the PIC microcontroller system keeps resetting when it is turned on?
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- [Me and Yatli] + First acquaintance
- TI's new automotive linear LED driver TPS92613-Q1 with enhanced heat dissipation
- Do you need to persist?
- What are the common reasons for LED errors?
- Need help choosing safer lithium batteries?
- STM32H743IIT6 core board schematic diagram
- [BearPi-HM Nano, play Hongmeng "touch and go"] Part 1: Unboxing summary
- AD9 usage issues
- TI Blog - Tips for Debugging Audio Amplifiers
- How is the 4-20mA output circuit of a pressure sensor or temperature sensor usually implemented?