PDA

View Full Version : variable problems



DmitriK
- 2nd June 2008, 23:34
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.

skimask
- 3rd June 2008, 01:36
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.

DmitriK
- 3rd June 2008, 23:50
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.

Darrel Taylor
- 4th June 2008, 20:22
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.

DmitriK
- 5th June 2008, 20:41
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.

skimask
- 5th June 2008, 21:19
Well, let's see some real code so we can help you figure out the real problem.