PIC microcontroller about PAGE and BANK

Publisher:快乐飞翔Latest update time:2016-12-07 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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. 


Reference address:PIC microcontroller about PAGE and BANK

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?

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号