PDA

View Full Version : newbe wants to know how many VAR's can you have



lecoind
- 23rd June 2012, 21:49
I have a 16f877 chip and have alot of VAR statements like this. The question is haw many VAR statements can you have in a program. Can I replace all these VAR's and use just one VAR because the values will always be the same for different FOR statements. I have this many of VAR's at the beginning of the program. Thanks, Leon

a var byte
b var byte
c var byte
d var byte
e var byte
f var byte
g var byte
h var byte
i var byte
j var byte
k var byte
l var byte
m var byte
n var byte
o var byte
p var byte

I use these like this

(example)
for b= 1 to 100
if b=100 then port1.0

HenrikOlsson
- 23rd June 2012, 22:50
Hi,
The number of variables you can have depends on the amount of RAM in the actual PIC you're using and on the size of the variables you declare (BIT, BYTE, WORD, LONG). For example the 16F877A has 368 bytes of RAM, PBP uses a couple of those for its internal use (~30 or so I think) and the rest is available for you to use. The compiler will throw an error if you're trying to allocate space that aren't available.

It quite common to have a couple of "general purpose" variables used in FOR-NEXT loops etc. You don't have to have a separate one for each loop but obviously it depends on what it your doing.

/Henrik.