2934 views|0 replies

1379

Posts

0

Resources
The OP
 

Application skills/PIC series microcontroller programming basics [Copy link]

1. Basic format of the program
First introduce two pseudo instructions:
EQU ¡ª¡ª label assignment pseudo instruction
ORG ¡ª¡ª address definition pseudo instruction
After RESET, the instruction counter PC of PIC16C5X is set to all "1", so the reset addresses of several types of PIC16C5X chips are:
PIC16C54/55: 1FFH
PIC16C56: 3FFH
PIC16C57/58: 7FFH
Generally speaking, there is no unified format required for PIC source code, and everyone can write it according to their own style. But here we recommend a clear and concise format for reference.
TITLE This is ... ; Program title
--------------------------------------
Name definition and variable definition
--------------------------------------
----F0 EQU 0

¡¡¡¡RTCC EQU 1
¡¡¡¡PC EQU 2
¡¡¡¡STATUS EQU 3
¡¡¡¡FSR EQU 4
¡¡¡¡RA EQU 5
¡¡¡¡RB EQU 6
¡¡¡¡RC EQU 7 ¡¡
¡¡¡¡¡¡¡¡¡¡¡¡ ©¯
¡¡¡¡PIC16C54 EQU 1FFH £»Chip reset address
¡¡¡¡PIC16C56 EQU 3FFH
¡¡¡¡PIC16C57 EQU 7FFH
¡¡¡¡£»-----------------------------------------
¡¡¡¡ORG PIC16C54 GOTO MAIN £»Enter the main program at the reset address
¡¡¡¡ORG 0 £»Start storing the program at 0000H
¡¡¡¡;-----------------------------------------
¡¡¡¡£»Subroutine area
¡¡¡¡;-----------------------------------------
¡¡¡¡DELAY MOVLW 255
¡¡¡¡¡¡¡¡¡¡ ©¯
¡¡¡¡¡¡¡¡ ¡¡RETLW 0
¡¡¡¡£»------------------------------------------
¡¡¡¡£»Main program area
¡¡¡¡;------------------------------------------
¡¡¡¡MAIN
¡¡¡¡¡¡¡¡¡¡ MOVLW B'00000000'
¡¡¡¡¡¡¡¡¡¡ TRIS RB £»RB has been defined as 6 by the pseudo instruction, that is, port B
¡¡¡¡¡¡¡¡¡¡¡¡ ©¯
¡¡¡¡LOOP
¡¡¡¡¡¡¡¡¡¡¡¡BSF RB, 7 CALL DELAY ¡¡¡¡¡¡¡¡¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡BCF RB, 7 CALL DELAY
¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ©¯
¡¡¡¡¡¡¡¡¡¡¡¡GOTO LOOP
¡¡¡¡£»-------------------------------------------
¡¡¡¡¡¡¡¡¡¡¡¡ END £»End of program
Note: The MAIN label must be in page 0.
2. Basics of Programming
1) Set the input/output direction of the I/O port
The I/O ports of PIC16C5X are all bidirectional and programmable, that is, each I/O line can be set as input or output by the program. This process is implemented by writing the I/O control register TRIS f. If the written value is "1", it is input; if the written value is "0", it is output.
-----------MOVLW 0FH ; 0000 1111 (0FH)
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Input and output
¡¡¡¡¡¡¡¡¡¡¡¡TRIS 6 ; Write 0FH in W to the B port controller,
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ; The high 4 bits of B port are output, and the low 4 bits are input.
¡¡¡¡¡¡¡¡¡¡¡¡MOVLW 0C0H ; 11 000000 (0C0H)
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ RB4, RB5 output 0 RB6, RB7 output 1
2) Check if the register is zero
If you want to determine whether the content of a register is zero, it is very simple. Take register F10 as an example:

MOVF 10, 1; F10¡úF10, the result affects the zero mark status bit Z

BTFSS STATUS, Z; if F10 is zero, jump
to GOTO NZ; Z=0 means F10 is not zero, jump to the program at label NZ
¡¡¡¡¡¡¡¡¡¡¡¡ ©¯; Z=1 means F10=0, process the program

3) Compare the sizes of two registers
To compare the sizes of two registers, you can subtract them and then judge based on the status bit C. Note that putting the result of the subtraction into W will not affect the original values of the two registers.
For example, to compare the sizes of registers F8 and F9:
-------------MOVF 8,0; F8¡úW
¡¡¡¡¡¡¡¡¡¡¡¡ SUBWF 9,0; F9¡ªW (F8)¡úW
¡¡¡¡¡¡¡¡¡¡¡¡ BTFSC STATUS, Z; Check if F8=F9 or not
¡¡¡¡¡¡¡¡¡¡¡¡ GOTO F8=F9
¡¡¡¡¡¡¡¡¡¡¡¡ BTFSC STATUS, C; If C=0, jump
¡¡¡¡¡¡¡¡¡¡¡¡ GOTO F9>F8; C=1, the result of subtraction is positive, F9>F8
¡¡¡¡¡¡¡¡¡¡¡¡ GOTO F9<
F9; C=0, the result of subtraction is negative, F9<F8
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ©¯
¡¡¡¡ 4) Program that loops n times
¡¡¡¡If you want to loop a program n times, you can use a register as a counter. In the following example, F10 is used as a counter to loop the program 8 times.
¡¡¡¡¡¡¡¡¡¡¡¡ COUNT EQU 10 ; define F10 name as COUNT (counter)
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ©¯
¡¡¡¡¡¡¡¡¡¡¡¡ MOVLW 8
¡¡¡¡¡¡¡¡¡¡¡¡ MOVWF COUNT LOOP ; loop body
¡¡¡¡¡¡LOOP
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ©¯
¡¡¡¡¡¡¡¡¡¡¡¡ DECFSZ COUNT, 1 ; COUNT decrements by 1, if the result is zero, jump to
¡¡¡¡¡¡¡¡¡¡¡¡ GOTO LOOP ; if the result is not zero, continue looping
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ©¯ ; if the result is zero, jump out of the loop
¡¡¡¡ 5) "IF...THEN..." format program
¡¡¡¡The following takes the "IF X=Y THEN GOTO NEXT" format as an example.
¡¡¡¡¡¡¡¡¡¡¡¡ MOVF X, 0 ; X¡úW
¡¡¡¡¡¡¡¡¡¡¡¡ SUBWF Y, 0 ; Y¡ªW (X)¡úW
¡¡¡¡¡¡¡¡¡¡¡¡ BTFSC STATUS, Z ; X=Y No
¡¡¡¡¡¡¡¡¡¡¡¡ GOTO NEXT ; X=Y, jump to NEXT to execute.
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ©¯ ; X¡ÙY
¡¡¡¡ 6) "FOR...NEXT" format program
¡¡¡¡"FOR...NEXT" program makes the loop execute within a certain range. The following example is a program in the format of "FOR X=0 TO 5". F10 puts the initial value of X, and F11 puts the final value of X.
¡¡¡¡¡¡¡¡¡¡¡¡START EQU 10
¡¡¡¡¡¡¡¡¡¡¡¡DAEND EQU 11
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ©¯
¡¡¡¡¡¡¡¡¡¡¡¡MOVLW 0
¡¡¡¡¡¡¡¡¡¡¡¡MOVWF START £» 0¡úSTART£¨F10£©
¡¡¡¡¡¡¡¡¡¡¡¡MOVLW 5
¡¡¡¡¡¡¡¡¡¡¡¡MOVWF DAEND £» 5¡úDAEND£¨F11£©
¡¡¡¡ LOOP
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ©¯
¡¡¡¡¡¡¡¡¡¡ INCF START£¬1 £» START value plus 1
¡¡¡¡¡¡¡¡¡¡ MOVF START£¬0
¡¡¡¡¡¡¡¡¡¡ SUBWF DAEND£¬0 £» START=DAEND £¿ £¨X=5 No£©
¡¡¡¡¡¡¡¡¡¡ BTFSS STATUS£¬Z
¡¡¡¡¡¡¡¡¡¡ GOTO LOOP £» X£¼5, continue loop
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ©¯ £» X£½5, end loop
¡¡¡¡ 7) Program in the format of "DO WHILE¡­¡­END" The program in the format of
¡¡¡¡"DO WHILE¡­¡­END" executes the loop when the condition is met. The following example is a program in the format of "DO WHILE X=1". F10 puts the value of X.
¡¡¡¡¡¡¡¡¡¡ X EQU 10
¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ©¯
¡¡¡¡¡¡¡¡¡¡ MOVLW 1
¡¡¡¡¡¡¡¡¡¡ MOVWF X £»1¡úX£¨F10£©, as the initial value
¡¡¡¡ LOOP
¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ©¯
¡¡¡¡¡¡¡¡¡¡ MOVLW 1
¡¡¡¡¡¡¡¡¡¡ SUBWF X£¬0
¡¡¡¡¡¡¡¡¡¡ BTFSS STATUS£¬Z £»X£½1 or not?
¡¡¡¡¡¡¡¡¡¡ GOTO LOOP £»X£½1 continue loop
¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ©¯ £»X¡Ù1 jump out of loop
8) Table lookup program
Table lookup is a frequently used operation in programs. The following example converts decimal 0 to 9 into 7-segment LED digital display values. If RB0 to RB6 of port B are used to drive the a to g segments of the LED, the following relationship exists:
(The image data of this file has been lost!)
Assuming the LEDs are common anodes, the line segment values corresponding to the numbers 0 to 9 are as follows:
The PIC table lookup program can be implemented by using the subroutine's feature of returning values. Specifically, in the main program, first get the table data address and put it into W, then call the subroutine. The first instruction of the subroutine puts W into PC, then the program jumps to the data address, and then the "RETLW" instruction puts the data into W and returns to the main program. The following program uses F10 to put the table header address.
-----------MOVLW TABLE £»Table header address¡úF10 ¡¡
¡¡¡¡¡¡¡¡¡¡¡¡MOVWF 10
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ©¯
¡¡¡¡¡¡¡¡¡¡¡¡MOVLW 1 £»1¡úW, prepare to get the segment value of ¡°1¡±
¡¡¡¡¡¡¡¡¡¡¡¡ADDWF 10,1 £»F10+W = data address of ¡°1¡±
¡¡¡¡¡¡¡¡¡¡¡¡CALL CONVERT
¡¡¡¡¡¡¡¡¡¡¡¡MOVWF 6 £»Set the segment value to port B, light up LED
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ©¯
¡¡¡¡CONVERT MOVWF 2 £»W¡úPC TABLE
¡¡¡¡¡¡¡¡¡¡¡¡RETLW 0C0H £»¡°0¡± segment value
¡¡¡¡¡¡¡¡¡¡¡¡RETLW 0F9H £»¡°1¡± segment value
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ©¯
¡¡¡¡¡¡¡¡¡¡¡¡RETLW 90H £»¡°9¡± segment value
9) "READ...DATA, RESTORE" format program
The "READ...DATA" program reads one data in the data table each time, then adds 1 to the data pointer to prepare for the next data. In the following program, F10 is used as the starting address of the data table, and F11 is used as the data pointer.
-----------POINTER EQU 11 ; define F11 name as POINTER
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ©¯
¡¡¡¡¡¡¡¡¡¡¡¡MOVLW DATA
¡¡¡¡¡¡¡¡¡¡¡¡MOVWF 10 ; data table header address ¡ú F10
¡¡¡¡¡¡¡¡¡¡¡¡CLRF POINTER ; data pointer clear
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ©¯
¡¡¡¡¡¡¡¡¡¡¡¡MOVF POINTER, 0 ¡¡
¡¡¡¡¡¡¡¡¡¡¡¡ADDWF 10, 0 ; W = F10 + POINTER
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ©¯
¡¡¡¡¡¡¡¡¡¡ INCF POINTER, 1 ; pointer plus 1
¡¡¡¡¡¡¡¡¡¡ CALL CONVERT ; call subroutine, get table data
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ©¯
¡¡¡¡CONVERT MOVWF 2 ; data address ¡ú PC
¡¡¡¡DATA RETLW 20H ; data
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ©¯
¡¡¡¡¡¡¡¡¡¡ RETLW 15H ; data
If you want to execute "RESTORE", just execute a "CLRF POINTER".
10) Delay program
If the delay time is short, you can simply let the program execute several no-operation instructions "NOP" in succession. If the delay time is long, you can use a loop to implement it. The following example uses F10 to calculate and repeat the loop 100 times
¡¡¡¡¡¡ ----MOVLW D'100'
¡¡¡¡¡¡¡¡¡¡ MOVWF 10
¡¡¡¡LOOP DECFSZ 10, 1; F10¡ª1¡úF10, if the result is zero, jump
¡¡¡¡¡¡¡¡¡¡ to GOTO LOOP
¡¡¡¡¡¡¡¡¡¡¡¡ ©¯
The delay time is calculated by the time it takes to execute the instructions in the delay program. If a 4MHz oscillation is used, each instruction cycle is 1¦ÌS. Therefore, the single-cycle instruction time is 1¦ÌS, and the double-cycle instruction time is 2¦ÌS. In the above example, the LOOP loop delay time is: (1+2)*100+2=302 (¦ÌS). Inserting a no-operation instruction in the loop can extend the delay time:
-----------MOVLW D'100'
¡¡¡¡¡¡¡¡¡¡¡¡MOVWF 10
¡¡¡¡LOOP NOP
¡¡¡¡¡¡¡¡¡¡¡¡ NOP
¡¡¡¡¡¡¡¡¡¡¡¡ NOP
¡¡¡¡¡¡¡¡¡¡¡¡DECFSZ 10,
¡¡¡¡¡¡¡¡¡¡¡¡1 GOTO LOOP
¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ©¯
Delay time = (1+1+1+1+2)*100+2=602 (¦ÌS).
The delay time can be greatly extended by nesting several loops. The following example uses 2 loops to delay:
-----------MOVLW D'100'
¡¡¡¡¡¡¡¡¡¡¡¡MOVWF 10
¡¡¡¡LOOP MOVLW D'16'
¡¡¡¡¡¡¡¡¡¡¡¡MOVWF 11
¡¡¡¡LOOP1 DECFSZ 11,1
¡¡¡¡¡¡¡¡¡¡¡¡GOTO LOOP1
¡¡¡¡¡¡¡¡¡¡¡¡DECFSZ 10,1
¡¡¡¡¡¡¡¡¡¡¡¡GOTO LOOP
¡¡¡¡¡¡¡¡¡¡¡¡ ©¯
Delay time = 1 + 1 + [1 + 1 + (1 + 2) * 16 - 1 + 1 + 2] * 100 - 1 = 5201 (¦ÌS)
11) Use of RTCC counter
RTCC is a pulse counter. Its counting pulse has two sources, one is the external signal input from the RTCC pin, and the other is the internal instruction clock signal. The program can be used to select one of the signal sources as input. RTCC can be used by the program for timing; the program reads the RTCC register value to calculate the time. When RTCC is used as an internal timer, the RTCC pin needs to be connected to VDD or VSS to reduce interference and current consumption. The following program uses RTCC for delay:
-----------RTCC EQU 1
¡¡¡¡¡¡¡¡¡¡¡¡ ©¯
¡¡¡¡¡¡¡¡¡¡¡¡CLRF RTCC £» RTCC cleared to 0
¡¡¡¡¡¡¡¡¡¡¡¡MOVLW 07H
¡¡¡¡¡¡¡¡¡¡¡¡OPTION £» Select preset multiple 1: 256 ¡ú RTCC
¡¡¡¡ LOOP MOVLW 255 £» RTCC count final value
¡¡¡¡¡¡¡¡¡¡¡¡SUBWF RTCC, 0
¡¡¡¡¡¡¡¡¡¡¡¡BTFSS STATUS, Z £» RTCC = 255?
¡¡¡¡¡¡¡¡¡¡¡¡GOTO LOOP
¡¡¡¡¡¡¡¡¡¡¡¡¡¡©¯
In this delay program, the RTCC register increases by 1 every 256 instruction cycles (division ratio = 1:256). Assuming the chip uses a 4MHz oscillation, then:
Delay time = 256*256 = 65536 (¦ÌS)
The RTCC is self-oscillating. When it is counting, the program can do other things. It only needs to read it at regular intervals and detect its count value.
12) Addressing of register bank (BANK)
For PIC16C54/55/56, there are 32 registers and only one bank, so there is no bank addressing problem. For PIC16C57/58, there are 80 registers, divided into 4 banks (BANK0-BANK3). In the description of F4 (FSR), we know that bit6 and bit5 of F4 are register bank addressing bits, and their corresponding relationship is as follows:
When the chip is powered on and reset, bit6 and bit5 of F4 are random, and non-powered RESET keeps the original state unchanged.
The following example writes data to the 30H and 50H registers of BANK1 and BANK2.
Example 1. (Assume that the current bank is BANK0)
----------MOVWF 10H ; DATA¡ú30H
¡¡¡¡¡¡¡¡¡¡¡¡BCF 4,5
¡¡¡¡¡¡¡¡¡¡¡¡BSF 4,6 ;bit6=1,bit5=0 select BANK2
¡¡¡¡¡¡¡¡¡¡¡¡MOVWF 10H ;DATA¡ú50H
From the above example, we can see that to read or write registers in a bank, we must first operate the bank addressing bit in F4. In practical applications, after power-on reset, we usually clear bit 6 and bit 5 of F4 to 0 to point to BANK0, and then point to the corresponding bank as needed.
Note that in the example, when writing numbers to the 30H register (BANK1) and the 50H register (BANK2), the register address in the instruction "MOVWF 10H" is "10H", instead of the "MOVWF 30H" and "MOVWF 50H" expected by the reader. Why?
Let's review the instruction table. In all the register-related instruction codes of PIC16C5X, the register addressing bits only occupy 5 bits: fffff, which can only address 32 (00H-1FH) registers. Therefore, to address 80 registers, we need to use the two-bit body addressing bits PA1 and PA0. When we set the body addressing bits PA1 and PA0 to point to a BANK, the instruction "MOVWF 10H" will put the content of W into the corresponding register in this BANK (10H, 30H, 50H, or 70H).
Some designers may have different understandings of the concept of volume location when they first encounter it. Here is an example:
Example 2: (Assume that the current bank is selected as BANK0)
-----------MOVLW 55H¡¡
¡¡¡¡¡¡¡¡¡¡¡¡MOVWF 30H; to transfer register 55H to 30H
¡¡¡¡¡¡¡¡¡¡¡¡MOVLW 66H
¡¡¡¡¡¡¡¡¡¡¡¡MOVWF 50H; to transfer register 66H to 50H
It is wrong to think that "MOVWF 30H" can definitely put W into 30H, and "MOVWF 50H" can definitely put W into 50H. This is because the actual effect of these two instructions is "MOVWF 10H", and the reason has been explained above. Therefore, the final result of this program in Example 2 is F10H=66H, and the actual F30H and F50H are not operated.
Suggestion: To make the program of bank address selection clear, it is recommended to use more name definition symbols to write the program, so as to avoid confusion. Example 3: Assume that the registers of BANK0, BANK1, and BANK2 are used in the program as follows:
-------------A EQU 10H; BANK0
¡¡¡¡¡¡¡¡¡¡¡¡¡¡B EQU 10H; BANK1
¡¡¡¡¡¡¡¡¡¡¡¡¡¡C EQU 10H; BANK2
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ©¯
¡¡¡¡¡¡¡¡¡¡¡¡¡¡FSR EQU 4
¡¡¡¡¡¡¡¡¡¡¡¡¡¡Bit6 EQU 6
¡¡¡¡¡¡¡¡¡¡¡¡¡¡Bit5 EQU 5
¡¡¡¡¡¡¡¡¡¡¡¡¡¡DATA EQU 55H
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ©¯
¡¡¡¡¡¡¡¡¡¡¡¡¡¡MOVLW DATA
¡¡¡¡¡¡¡¡¡¡¡¡¡¡MOVWF A ¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡BSF FSR,Bit5
¡¡¡¡¡¡¡¡¡¡¡¡¡¡MOVWF B;DATA¡úF30H
¡¡¡¡¡¡¡¡¡¡¡¡¡¡BCF FSR,Bit5
¡¡¡¡¡¡¡¡¡¡¡¡¡¡BSF FSR,Bit6
¡¡¡¡¡¡¡¡¡¡¡¡¡¡MOVWF C; DATA¡úF50H
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ©¯
If the program is written like this, I believe that the location selection will not be easy to make mistakes
13) Program jumps and calls across pages
The following introduces the page concept of the program storage area of PIC16C5X and an example of the application of the page address bits PA1 and PA0 in the F3 register.
(1) ¡°GOTO¡± across pages
Example: Assume that the current program is on page 0 (PAGE0), and you want to use "GOTO" to jump to a certain
KEY on page 1 (PAGE1).
------------STATUS EQU 3
¡¡¡¡¡¡¡¡¡¡¡¡ PA1 EQU 6
¡¡¡¡¡¡¡¡¡¡¡¡ PA0 EQU 5
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ©¯
¡¡¡¡¡¡¡¡¡¡¡¡ BSF STATUS, PA0; PA0=1, select PAGE page
¡¡¡¡¡¡¡¡¡¡¡¡ GOTO KEY; jump to page 1 KEY
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ©¯
¡¡¡¡¡¡¡¡¡¡¡¡ KEY NOP; program of page 1
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ©¯
(2) ¡°CALL¡± across pages

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ Example : Assume that the current program is on page 0 (PAGE0), and now you want to call the subroutine DELAY placed on page 1 (PAGE1).
------------BSF STATUS, PA0; PA0=1, select PAGE1 page
¡¡¡¡¡¡¡¡¡¡¡¡ CALL DELAY; cross-page call
¡¡¡¡¡¡¡¡¡¡¡¡ BCF STATUS, PA0; restore the address of page 0©¯
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ DELAY
¡¡¡¡¡¡¡¡¡¡¡¡ NOP; subroutine of page
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ 1©¯
Note: The program sets the page address for cross-page CALL. Be sure to restore the original page address after returning from the subroutine.
(3) Programming of cross-page jumps and calls
Readers who have read this must be asking: When I write the source program (.ASM), I don't pay attention to the storage address of each instruction. How do I know that this GOTO needs to cross pages, and that CALL needs to cross pages? Indeed, when you start writing the source program, you don't know when a cross-page jump or call will occur, but when you assemble the source program, it will be automatically given. When the assembly result shows:
¡¡¡¡¡¡¡¡¡¡¡¡ XXX (address) "GOTO out of Range"
¡¡¡¡¡¡¡¡¡¡¡¡ XXX (address) "CALL out of Range"
This indicates that your program has cross-page jumps and calls, and the corresponding page addresses have not been set before these cross-page GOTO and CALL in your program. At this time, you should check the .LST file generated by the assembly, find these GOTO and CALL, and check which page the address they are going to jump to is located, and then return to the source program (.ASM) to make necessary modifications. Until your source program passes the assembly (0 Errors and Warnnings).
(4) Link to program page
The connection between the four pages of the program should be processed. It is generally recommended to use the following format: That is, after entering another page, immediately set the corresponding page address bit (PA1, PA0). Page processing is the most troublesome part of PIC16C5X programming, but it is not difficult. As long as you do a practical programming exercise, you will be able to master it.
This post is from Microchip MCU
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Related articles more>>

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved ¾©B2-20211791 ¾©ICP±¸10001474ºÅ-1 µçÐÅÒµÎñÉóÅú[2006]×ÖµÚ258ºÅº¯ ¾©¹«Íø°²±¸ 11010802033920ºÅ
¿ìËٻظ´ ·µ»Ø¶¥²¿ Return list