variable problems


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2008
    Posts
    3

    Default variable problems

    Hello,
    I'm having problems with understanding variables and banks, or actually how to correctly to use variables across banks (using 876A so I have 4 banks; bank0-3)

    What exactly is the difference between these following lines if they are declared at the top? Does it even matter if they are declared at the top or in the middle of the code?

    --------
    btemp1 var byte
    btemp2 var byte bank0
    btemp3 var byte system
    btemp4 var byte bank0 system
    --------

    What is the scope of each of these variables? If I have a variable that needs to retain its value across all the banks, how do I need to declare it?

    I couldn't find any information about variables' scope in PBP manual. Please help.

    Thank you.

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by DmitriK View Post
    I'm having problems with understanding variables and banks, or actually how to correctly to use variables across banks (using 876A so I have 4 banks; bank0-3)
    PBP handles it.

    What exactly is the difference between these following lines if they are declared at the top? Does it even matter if they are declared at the top or in the middle of the code?
    Generally doesn't matter. Style points I suppose. But most prefer the variables at the top so they know what they're getting into before they get into it... And the PBP manual does discuss those different types of variables, albiet not very indepth. Usually the average programmer doesn't need to care.

    What is the scope of each of these variables? If I have a variable that needs to retain its value across all the banks, how do I need to declare it?
    Global scope. PBP doesn't do LOCAL, GLOBAL, PRIVATE, or anything like that (unless you're doing included assembly, but I'm not sure that qualifies).

    I couldn't find any information about variables' scope in PBP manual.
    Read again grasshopper...some of it's in there.

  3. #3
    Join Date
    Jun 2008
    Posts
    3


    Did you find this post helpful? Yes | No

    Default

    Ok thanks although this brings me to another question which is the source of confusion. There are 'accesses' registers which are mirrored across all banks. Why do we need these 'accesses' registers if all variables are global anyway?

    I thought pointers to 'accesses' registers are the "global variables" so to say and everything else (in general purpose registers) is only for corresponding banks.

    P.S. how do i force PBP to keep a certain variable in the 'accesses' area. The way I do it now is

    myvar var byte $70
    myvar1 var byte $71
    etc

    Is that what the "system" modifier is for maybe; to place the var into the 'accesses' area? Although I'm not very sure it is, because I've had more than 16 bytes of variables declared with 'system' modifier and code compiled just fine.

    I can't find any information about variable modifiers; I even searched the PDF file for keywords. Can you please tell me which page it's on in the PBP manual?

    Thanks.

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


    Did you find this post helpful? Yes | No

    Default

    Unless you will be writing part of your program in Assembly Language, there's no need to worry about the PIC's banking system.

    PicBasic Pro handles all that for you.

    The access locations can be useful in ASM, and can save a bunch of CPU time by reducing the number of Bank changes. But PBP does not use that area, for that purpose.

    So just define your variables without ANY modifiers, and everything should work just fine.
    DT

  5. #5
    Join Date
    Jun 2008
    Posts
    3


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    So just define your variables without ANY modifiers, and everything should work just fine.
    I am using ASM for interrupt initialization, but I don't think that would matter as far as variables go. Actually that's the reason why I'm trying to learn about these modifiers; if I let Picbasic handle the variables, my board goes haywire, freezes up and doesn't hold the var values as debugging showed, however everything works if I manually set the vars to set locations.

    I don't know why this is happening, and maybe I coded something wrong or discovered a picbasic bug; not sure, but manually assigning a var to location, say, $70 that are accessed say at 0x0100 to 0x1EC0 address (in other words across all banks), works and letting picbasic handle this var doesn't work.

    Maybe someone has a suggestion actually what might be wrong.

    P.S. watchdog timer kicks in sometimes also because I notice a board reset and I have auto-insert clear watchdog timer set so that really does show that the board froze up.

    Thanks for any information.

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Well, let's see some real code so we can help you figure out the real problem.

Similar Threads

  1. EEPROM Variables (EE_Vars.pbp)
    By Darrel Taylor in forum Code Examples
    Replies: 79
    Last Post: - 26th October 2012, 00:06
  2. Help with sound command in 2 programs
    By hyperboarder in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th July 2007, 20:36
  3. WORD vs BYTE variable lengths
    By bartman in forum General
    Replies: 0
    Last Post: - 28th November 2005, 21:16
  4. Problems with variable - Advise welcome
    By tracking in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 13th June 2005, 18:40
  5. 2k barrier variable problems
    By khufumen in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 20th December 2004, 23:35

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