A little help needed with arrays in PicBasicPro please

Status
Not open for further replies.

bigal_scorpio

Active Member
Hi to all,

I am still learning Pic Basic Pro and have come up with a problem in understanding Arrays!

From the manual I understand how to define the Arrays name and size eg. sharks VAR BYTE [10] gives an Array with 10 elements and I think I understand how to access the elements. BUT what I am baffled about is the method of loading the data I want into the array?

I mean to say, continuing the manuals shark theme, if I wanted the array to consist of tiger, great white, lemon, nurse etc, what is the actual syntax I would use to make the array and where would this line/s be placed? IE inside the main, before main or after main?

Any example would be most welcome.

Thanks for looking...........Al
 
I'm not sure that PBP allows multidimensional arrays! An array of strings has usually two dimensions ie. names[10][string length] . To do this you will need to make n' arrays of fixed length ( longest text ) and initialize them individually (laborious) The easiest way for you to do this is with the lookup command

Code:
        For B = 0 to 5			        ' Count from 0 to 5
		LOOKUP B,[“Hello!”],B1	' Get character number B from string to variable B1
		array[B] = B1	                ' Send character in B1 to array
	Next B				        ' Do next character

This is the example from the manual

Cheers Ian
 
Last edited:
Hi Ian,

Still baffled mate. The following code compiles and burns with no errors but does nothing at all.

I have leds connected to PortB and ground and expected them to light as the program stepped through the lookup.

I am obviously not getting something about the lookup!

Any help please.......Al
Code:
 MAIN:
 
 FOR N = 0 TO 7
 
 LOOKUP N ,[1,2,4,8,16,32,64,128], RESULT
 
 NEXT N
 
 PAUSE 1000
 
 PORTB = RESULT
 
 GOTO MAIN
 
 END
 
And the Pause 1000! or you won't see anything.

Cheers Ian
 
Have you set PORTB as an output? What size limiting resistors are in place.

Cheers Ian
 
Hi Eric and Ian,

Yes I did Ians too but didn't see his post until after I had posted your reply.

Here is the new code but still not working as expected, not a flicker!

PS fuses set to MCLR off, WDT off, PWR on BOD off

Al
Code:
 MAIN:
 
 FOR N = 0 TO 7
 
 LOOKUP N ,[1,2,4,8,16,32,64,128], RESULT
 
 PAUSE 1000
 
 PORTB = RESULT
 
 NEXT N
 
 GOTO MAIN
 
 END
 
I hate to ask this (watching fingers) are the LED's the right way round?

Cheers Ian
 
hi Al,
This runs in Oshonsoft, had to make a few changes.


Code:
AllDigital

Dim n As Byte
Dim result As Byte

TRISB = 0

main:

For n = 0 To 7

result = LookUp(1, 2, 4, 8, 16, 32, 64, 128), n

'PAUSE 1000

PORTB = [B][COLOR=Red]RESULT[/COLOR][/B]

Next n

Goto main

End

Woops, corrected an error in my listing...
 
Last edited:
Hi Eric....Thanks I will have to try that out, just never addressed an entire port like that.
 
Just as an after thought What processor are you using?

Ian
 
I mean't the originator's processor, I don't know PBP but the larger processors use LATCB.

Ian
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…