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.

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
 
hi Al,
The PORTB=RESULT should be in the FOR NEXT LOOP....
 
Hi Eric,

Changed the code as you pointed out but still no joy at all. Doh!

Al
 
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
 
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.
 
I mean't the originator's processor, I don't know PBP but the larger processors use LATCB.

Ian

I realised you meant Al's PIC, I posted the type I used as Ref, mainly for Al's guidance..
 
Hi Eric and Ian and Mike,

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

And still no joy.

Al
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top