Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

A little help needed with arrays in PicBasicPro please

Status
Not open for further replies.
Hi Eric and Ian and Mike,

I am using a PIC16F873A, it was handy at the time. :)

And still no joy.

Al

Hi,
This is from the from the PBP Manual
LOOKUP
LOOKUP Index,[Constant{,Constant...}],Var
The LOOKUP statement can be used to retrieve values from a table of 8-bit constants. If Index is zero, Var is set to the value of the first Constant. If Index is one, Var is set to the value of the second Constant. And so on. If Index is greater than or equal to the number of entries in the constant list, no action is taken and Var remains unchanged.
The constant list can be a mixture of numeric and string constants. Each character in a string is treated as a separate constant equal to the character's ASCII value. Array variables with a variable index may not be used in LOOKUP although array variables with a constant index are allowed. Up to 255 (256 for 18Cxxx) constants are allowed in the list.
For B0 = 0 to 5 ' Count from 0 to 5 LOOKUP B0,[“Hello!”],B1 ' Get character number B0 from string to variable B1 Serout 0,N2400,[B1] ' Send character in B1 to Pin0 serially Next B0 ' Do next character LOOKUP2
LOOKUP2 Index,[Value{,Value...}],Var
The LOOKUP2 statement can be used to retrieve entries from a table of Values. If Index is zero, Var is set to the first Value. If Index is one, Var is set to the second Value. And so on. If Index is greater than or equal to the number of entries in the list, no action is taken and Var remains unchanged.
The Value list can be a mixture of 16-bit numeric and string constants and variables. Each character in a string is treated as a separate constant equal to the character's ASCII value. Expressions may not be used in the Value list, although they may be used as the Index value. Array variables with a variable index may not be used in LOOKUP2 although array variables with a constant index are allowed. Up to 85 (256 for 18Cxxx) values are allowed in the list.
LOOKUP2 generates code that is about 3 times larger than LOOKUP. If the Value list is made up of only 8-bit constants and strings, use LOOKUP.
LOOKUP2 B0,[256,512,1024],W1


Try lookup 2, its for variables, lookup is for constants, which I assume have to be declared.
 
Hi Eric and Ian,

First Ian, yes I am setting the Tris.

Eric, Yes I had read the lookup section in the manual but I assumed (maybe wrongly) that I was using constants?

None of the values in my line ever change, they are simply read at different times but say n = 4 will always return 16?

Am I missing something here, well and truly puzzled! But on that note I shall try Lookup 2 and let you know what happens, but from my experience so far I won't hold my breath. hehehe

Al
 
One last thing!!! are the OSC bits set correctly ie.. HS or XT. I forget this alot. Pic won't run if XT is set and a 20mhz xtal is fitted. WDT aswell?

Ian

P.S. if things don't get any better, you can always become a milkman.
 
Last edited:
Update!

Got it going and as expected too! Wonders never cease!

Just a small addition and there it goes.

New code below. Al

Code:
main:

For n = 0 To 7

LookUp2 n,[1, 2, 4, 8, 16, 32, 64, 128], result

PAUSE 1000

PORTB = $00 + RESULT

Next n

Goto main
 
Thanks for all the help and suggestions guys,

This code is actually for my version of a moving sign. Most of the moving code on the net seems to be in ASM or C++ etc and I have no example to follow so right or wrong I decided to start from scratch and just try to do it my way, which is probably the worst way or strangest. After all I had Mike baffled with the code, which I have never seen before.

Anyway now onto strange new ways(to me) to hold the values for all the columns at once, others I have noticed seem to call them Ghost locations, and I certainly believe in ghosts so here I go! :)

Thanks again......Al
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top