PIC 16f887 question

Thread Starter

RG23

Joined Dec 6, 2010
304
In my code actually one subroutine is at the address 0x080D which falls in page1

I do access that subroutine during the interrupt service routine

Is there any thing I need to modify in the ISR related to the changes in PCLATH????

Also I tried switching the page just by using
bcf PCLATH,4
bsf PCLATH,3
call subroutine///////which is at location 0x080D9 (page1)

Is this the correct approach???
 

Thread Starter

RG23

Joined Dec 6, 2010
304
@Mark
Just find the biggest and least used calls.

__________________________________________________________

yes in fact I just used the call for the subroutine in other page using the PCLATH modification
 

Markd77

Joined Sep 7, 2009
2,806
Also I tried switching the page just by using
bcf PCLATH,4
bsf PCLATH,3
call subroutine///////which is at location 0x080D9 (page1)

Is this the correct approach???
Nearly:


;bcf PCLATH,4 ; not usually required, should be zero already.
bsf PCLATH,3
call subroutine///////which is at location 0x080D9 (page1)
bcf PCLATH, 3 ;restore so that next call will work OK
 

t06afre

Joined May 11, 2009
5,934
I often use the banksel directive in MPLAB. And it is also a pagesel directine in MPLAB
This directive is used in the following types of code: absolute or relocatable. For information on types of code, see Assembler Operation.
This directive saves you from having to manually code page bit changes. Also, since it automatically generates code, the code is much more portable.
If you are using relocatable code and your device has more than 2k program memory (or 0.5K for 12-bit instruction width devices), it is recommended that you use this directive, especially when code must jump between two or more code sections.
If you wish to indicate the start address of a RETLW table or a jump table for computed GOTOs, you must use the pageselw directive.
You find more deatils in MPASM Assembler help
 

Thread Starter

RG23

Joined Dec 6, 2010
304
Nearly:


;bcf PCLATH,4 ; not usually required, should be zero already.
bsf PCLATH,3
call subroutine///////which is at location 0x080D9 (page1)
bcf PCLATH, 3 ;restore so that next call will work OK

@Markd77

yes it did work if the subroutine is not following a condition

but doesn't work if the subroutine is conditional


For eg:
I had the following part of code where the label723 is at the address 083B

movf count307,0
sublw d'4'
btfsc STATUS,Z
call label840
return

label840:
bcf PCLATH,4
bsf PCLATH,3
call label723
bcf PCLATH,3
return


If you have any idea please let me know

Thanks
 

Markd77

Joined Sep 7, 2009
2,806
That should work OK as long as all the code you posted is within page0 and label723 is in page1. What happens when you single step through the code in the simulator? The contents of the hardware stack window can be useful too.
 

Thread Starter

RG23

Joined Dec 6, 2010
304
@That should work OK as long as all the code you posted is within page0 and label723 is in page1.

Yes all the code I pasted is in page0 and label 723 is in page1 but it did not work

--------------------------------------------------------------------------------------
What happens when you single step through the code in the simulator? The contents of the hardware stack window can be useful too.

What can be concluded from contents of the hardware stack window?
 

t06afre

Joined May 11, 2009
5,934
Use the pagesel directive. And let the assembler take care of the pclatch settings for you. Much more simple, if you ask me
 
Top