PDA

View Full Version : array in constant?



SpiritHunter
- 2nd August 2007, 11:51
hi every one. i am fresh here. i got a problem with coding about arrays.

what i wanted to do is to create an array which have a series of constants that i won't be changing during runtime.

i believe there is a code which is like " a var byte[10] " is possible but this required the pic's ram and the ram is pretty limited. so, can i create the array as in constant or as code which i can den use later on?

futher more, how to put in data in array mode? which some thing like " a[] = {1 2 3 4 5 6 7} "

thank you

Bruce
- 2nd August 2007, 12:28
LOOKUP a,[1,2,3,4,5,6,7],b.

a & b would be byte variables. a = the index pointer. b = the byte variable
the constant value from the table is placed in.

a = 1
LOOKUP a,[1,2,3,4,5,6,7],b

b now = 2.

This creates a constant array in ROM similar to const char a[]={1,2,3,4,5,6,7};
in C where b=a[1].

SpiritHunter
- 2nd August 2007, 12:47
this means that i can put
LOOKUP A,[.......],B

but how can i refer to the A later on?

eg. lookup a,[ 1 2 3 ],b

den how can i do like x= a[1] + a[2] ?

Bruce
- 2nd August 2007, 13:43
If you need x= a[1] + a[2] then you'll need to create a standard array of
RAM variables.

Or do something like this;


Main:
a = 1
GOSUB GetConst
X = b
a = 2
GOSUB GetConst
X = X + b ' now X = a[1]+a[2]
GOTO Main

GetConst:
LOOKUP a,[1,2,3,4,5,6,7],b
RETURN

SpiritHunter
- 2nd August 2007, 14:30
thanks alot bruce, i think i understand already. will try out 2moro.

SpiritHunter
- 5th August 2007, 13:10
wow.. thanks.... o ya... 1 more question... how many constant can i write in a single bracket? and... is there a problem if i write like this?

LOOKUP a,[1,2,3,4,5,6,7
,b

SpiritHunter
- 5th August 2007, 13:12
wow.. thanks.... o ya... 1 more question... how many constant can i write in a single bracket? and... is there a problem if i write like this?

LOOKUP a,[1,2,3,4,5,6,7
,8,9,10],b

Acetronics2
- 5th August 2007, 14:31
how many constant can i write in a single bracket? and... is there a problem if i write like this?

LOOKUP a,[1,2,3,4,5,6,7
,8,9,10],b

Hi, SH

Will 255 for a 16F series and 256 for a 18F series be enough ??? ( LOL !!!)

...

Note this type of array takes a lot of room ( like with assembler ... 1 prog line per value + 1 ) and you might think at it when choosing your PIC ...

PbP doesn't deal so well with room for this function ... and lots of room is lost with big lookup tables !!!

Alain

SpiritHunter
- 8th August 2007, 10:12
Hi, SH

Will 255 for a 16F series and 256 for a 18F series be enough ??? ( LOL !!!)

...

Note this type of array takes a lot of room ( like with assembler ... 1 prog line per value + 1 ) and you might think at it when choosing your PIC ...

PbP doesn't deal so well with room for this function ... and lots of room is lost with big lookup tables !!!

Alain

? 255 only? i am thinking of at less 500... as i need to bit map all the char in ascii which is at less need 101x5

ya.. i know it takes alot of memory. and i have chosen 16F877A to do the job. i hope 8k is enough for the constants, I2C and a serial communication... if not enough, then i am in big troble.. haha...

so... 16F877A can only allocate 255 in 1 lookup table? if so, den i need to separate the bit map codings.

Acetronics2
- 8th August 2007, 10:43
Hi,

Those are PbP limits !!! ... for LOOKUP ...

you can also use an external pre-programmed EEPROM or use some READCODE ( see manual for the limits )... if your code space allows it ....

note ... DATAs for READCODE can be loaded as an "include" file ... generated by your computer ! ( with "word", or much better "Excel" ...)

Alain

SpiritHunter
- 15th August 2007, 05:45
thanks Acetronics, i can deal with the more then 255 problem.

now another problem is that

how can i write

lookup a,[1,2,3,4,5,6,...........,255],b

in multiple line? and adding comment in the end of each line?

eg:
lookup a,[1,2,3,4,5,6,7,8,9,10, ; line 1
11,12,13,14,15, ; line 2
.................... ],b

mackrackit
- 15th August 2007, 07:14
lookup a,[1,2,3,4,5,6,_ 'never tried comments on each line
7,8,9,10,....,255],b ' but the normal way should work

SpiritHunter
- 16th August 2007, 09:55
just add _ behind each line. got it... thanks

SpiritHunter
- 18th August 2007, 09:23
thanks guys, not that the compiling part is finish, it's time to put it in the 16f877a and test it.
the coding alone is around 6kb already. haha...