Jump to content

Bank Switch Problem Within Switch

Recommended Posts

Viewing the .asm for the following code...


within case 0: RP0 is set to access pie1 in bank 1.


the switch is then exitted and execution returns to the top of the while loop.


execution then breaks after the test of ccpr1l != 0xaa because RP0 is still set,

(pointing to bank 1) and ccpr1l is in bank 0.


additional notes:

if a variable assignment (pie1 = 0x04) is used to access pie1 instead of the

clear_bit(), RP0 seems to be properly reset.


if the case statement containing clear_bit(pie1, xx) is the last case within the

switch, RP0 seems to be properly reset.


I don't believe that the specific registers referred to in banks 0 and 1 are significant. They just happened to be the ones I was using when I observed this issue.


When run in the debugger within the IDE, when execution breaks at the test of ccpr1l, the debugger gives the following message:

Can't locate source line for the current instruction.


I'm using the C2C compiler in SourceBoost IDE ver 5.9.1



-- Jeff




#include <system.h>


// required by piccont4.pat to save interrupt context

char _w_cont@0x7F, _w_cont_1@0xFF, _w_cont_2@0x17F, _w_cont_3@0x1FF;

char _status_sav@0x7E, _fsr_sav@0x7D, _pclath_sav@0x7C;

// above included just because i build for 16F873



char var1 = 0;




// init register in bank 0 and never change it

ccpr1l = 0xaa;



if running correctly, this program never exits.

var1 is incremented to a non-existent case, and the only way to

exit the while(1) is for the value of ccpr1l to change from 0xaa.




// if register changes, quit

if(ccpr1l != 0xaa)





case 0:

var1 = 1;

clear_bit(pie1, TMR1IE); // changes RP0 to get to bank 1


// if the following is added here, execution is correct

// asm bcf STATUS, RP0



case 1:

// an additional do nothing case.

// if the change to RP0 (clear_bit in the above case) is within

// the last case of the switch, RP0 is handled correctly.

var1 = 2;



} // end switch(var1)

} // end while(1)

} // end main()

Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...