CHK?RP question


Closed Thread
Results 1 to 7 of 7

Thread: CHK?RP question

  1. #1
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107

    Default CHK?RP question

    I have quite a few assembly language code blocks in my PBP program. In order to insure communication between PBP and asm, I have declared the variables in BANK0, but now I'm out of bank0 space.

    I believe that CHK?RP can keep track of the bank the variables are in, but I can't find any good "tutorial". Can someone please enlighten me as to its use?
    Charles Linquist

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    CHK?RP, RST?RP, banksel, STATUS,RP?, BSR ...
    With so many BANK options, we may need a government bailout!

    <hr><pre>MyVarW VAR WORD<br>MyVarB1 VAR BYTE BANK1</pre>When you create a variable in PBP, you have no idea where that variable is located in RAM. (unless you specify the bank)
    Normally PBP takes care of all that for you. But when working with ASM it's up to you to figure out where they are..

    For 16F's, you have to change the STATUS,RP0 and RP1 bits.
    For 18F's, the value of the BSR selects the bank.
    The new 16F1xxx chips also have a BSR.

    It can be pretty confusing to find just were those variables are.

    With MPASM, you can use banksel to find which bank they are in.
    The following line will select Bank1, because that's the bank that was specified for the MyVarB1 variable above.

    &nbsp; &nbsp; banksel _MyVarB1

    At this point, you can use any of the opcodes like MOVF, MOVWF, ADDWF, SUBWF etc. on the MyVarB1 variable.

    Then if you want to access another variable, you'd do the same thing again with that variable's name.
    Code:
        movlw   10h         ; load 16 into WREG
        banksel _MyVarB1    ; find the bank for MyVarB1 (bank1)
        movwf   _MyVarB1    ; put the value in the variable
    
        movlw   20h         ; load 32 into WREG
        banksel _MyVarW     ; find the bank for MyVarW (unknown)
        movwf   _MyVarW     ; put value in lowbyte
        clrf    _MyVarW + 1 ; clear the highbyte
    For each one of those banksel's it will generate a MOVLB xx opcode to load the BSR register (with 18F's and 16F1's). With 16F's it takes two instructions to set both bits in the STATUS register.

    It won't matter if it's already pointing to that bank, it'll still add more code to change to the bank it's already in. For long ASM programs with variables in unknown banks, the extra code can really add up.

    Enter CHK?RP.

    This does the same thing as banksel, except that it keeps track of what bank it's in, and only generates code if it actually needs to change banks.
    It does this by setting the ASM variable PREV_BANK every time it changes banks.
    In some circumstances, this can save a lot of code space.

    Of course, there are good and bad with both methods.
    With CHK?RP, since you don't know whether it will be generating code or not, it becomes difficult to add up instruction cycles for the "Time critical" routines. Whereas you always know that banksel will generate code, so you can just add those in to calculate real time.

    With banksel, it's very important, that you return the bank to 0 before exiting ASM.
    The PREV_BANK variable will still say it's in bank0, so if you don't make sure it's really in bank0, PBP will get very confused.

    When using CHK?RP, you don't have to put it back to bank0 because PBP knows what bank it's in, and will just continue on.

    RST?RP will reset back to bank0, if you were using CHK?RP.
    It also updates PREV_BANK.
    It will have no affect after a banksel.<hr>
    There are many problems that can happen when using CHK?RP and goto's or branch's in the asm routine.
    If you jump over a CHK?RP with a goto, then PREV_BANK won't reflect the correct bank, and the next CHK?RP may not select the correct bank.
    PBP overcomes that with the L?GOTO, L?CALL and LABEL?L macro's, which I won't go into here, but you can probably guess that I'm leaning towards you using banksel. It's really much easier.
    Just make sure you put it back to bank0 when you're done.

    &nbsp; &nbsp; banksel 0

    HTH,

    P.S. Unless you are using other PBP macro's like MOVE?BB, BIT?GOTO etc. in which case it's best to use CHK?RP.
    Where's that bailout when you need one?
    Last edited by Darrel Taylor; - 4th December 2009 at 08:32. Reason: P.S.
    DT

  3. #3
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Smile

    Now I'm *REALLY* glad I asked that question!

    Darrel,

    I'm moving up to ARM9's for my next project, and I'm hoping that you know something about Keil 'C' . I'm going to need a lot of help!
    Charles Linquist

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Charles Linquis View Post
    Now I'm *REALLY* glad I asked that question!
    Then I'm *REALLY* glad I answered it.

    I'm moving up to ARM9's for my next project, and I'm hoping that you know something about Keil 'C' . I'm going to need a lot of help!
    ARM9? Sorry I only have 2 ARM's.
    Keil "C" ... is that part of a boat?
    Not a clue.
    <br>
    DT

  5. #5
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    Uh oh! Looks like if I want any REAL help from you I'm going to have to figure out how to make an 8723 do USB + RS232 + 8 channels of I2C + 22 I/O + 6 channels of A->D + 100Mbit Enet (SSH protocol) while running Linux (required by customer).
    Charles Linquist

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    It's a deal ...

    IF you can teach me "Pentatonic Scales" without my fingers going all wacko?

    DT

  7. #7
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    I'm in trouble.
    Charles Linquist

Similar Threads

  1. Timer0 Instant Interrupts Question
    By wmarchewka in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 14th December 2009, 05:29
  2. Crystals & Caps - Super noob question??
    By kevj in forum General
    Replies: 4
    Last Post: - 24th September 2007, 17:11
  3. PIC16F684 Program question
    By Nicholas in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th December 2006, 14:30
  4. Question for a math guru
    By Christopher4187 in forum General
    Replies: 3
    Last Post: - 22nd November 2006, 09:45
  5. Please answer my first question
    By John_001 in forum Off Topic
    Replies: 1
    Last Post: - 15th September 2006, 06:49

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts