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.

Arrays Oshon Pic Basic

Status
Not open for further replies.

SwingeyP

Member
Hi can anyone help me with this please?

I want to store a string something like this

DIM bargraph(10) as Byte

bargraph(6) = s_p, #sr, " ", 0, 1, 2, 3, 4, 5, 6, " "

or perhaps three is a better way?

I have this code:

bargraph0:
Lcdcmdout LcdLine2Home
Lcdout s_p, " ", "0 "
WaitMs 1
Goto home
bargraph1:
Lcdcmdout LcdLine2Home
Lcdout s_p, #sr, " ", 0, " "
WaitMs 1
Goto home
bargraph2:
Lcdcmdout LcdLine2Home
Lcdout s_p, #sr, " ", 0, 1, " "

etc.....

It seems to me that it would be great to do something like this here instead

bargraph:
Lcdcmdout LcdLine2Home
Lcdout bargraph(var)
Goto home

that way I could just call 1 line which would read the array element associated with var.

Is this possible?

Regards - Paul
 
hi Paul,
Have you considered using the LOOKUP statement for Strings.??

eg;
FOR DIGIT = 0 TO 9
bargraph = LOOKUP(s_p#sr 0123456), DIGIT
lcdout bargraph
NEXT DIGIT
 
Last edited:
Hello again Eric.

I haven't used lookups before. I just had a quick read of the help file in oshon.

So I could do someting like this then.

mask = LookUp(" ", "0 ", #sr, " ", 0, " ", #sr, " ", 0, 1, " "), var
lcdcmdout s_p, mask

etc...

Regards - Paul
 
Hmmm just realised i'd have to be careful with quotes and commas. Would each parameter require single quotes?
 
I can't get the construct of the strings right. Can anyone help please?

Here's what it is at present.

bargraph0:
Lcdcmdout LcdLine2Home
Lcdout s_p, " ", "0 "
WaitMs 1
Goto freq
bargraph1:
Lcdcmdout LcdLine2Home
Lcdout s_p, #sr, " ", 0, " "
WaitMs 1
Goto freq
bargraph2:
Lcdcmdout LcdLine2Home
Lcdout s_p, #sr, " ", 0, 1, " "
WaitMs 1
Goto freq
bargraph3:
Lcdcmdout LcdLine2Home
Lcdout s_p, #sr, " ", 0, 1, 2, " "
WaitMs 1
Goto freq
bargraph4:
Lcdcmdout LcdLine2Home
Lcdout s_p, #sr, " ", 0, 1, 2, 3, " "
WaitMs 1
Goto freq
bargraph5:
Lcdcmdout LcdLine2Home
Lcdout s_p, #sr, " ", 0, 1, 2, 3, 4, " "
WaitMs 100
Goto freq
bargraph6:
Lcdcmdout LcdLine2Home
Lcdout s_p, #sr, " ", 0, 1, 2, 3, 4, 5, " "
WaitMs 1
Goto freq
bargraph7:
Lcdcmdout LcdLine2Home
Lcdout s_p, #sr, " ", 0, 1, 2, 3, 4, 5, 6, " "
WaitMs 1
Goto freq
bargraph8:
Lcdcmdout LcdLine2Home
Lcdout s_p, #sr, " ", 0, 1, 2, 3, 4, 5, 6, 7, " "
WaitMs 1
Goto freq


So how do I do

mask = LookUp(" ", "0 ", #sr, " ", 0, " ", #sr, " ", 0, 1, " "), var
lcdcmdout s_p, mask

Regards - Paul
 
Hmmm just realised i'd have to be careful with quotes and commas. Would each parameter require single quotes?

hi,
For ASCII characters in the LOOKUP string use double quotes ONLY at each end of the string.

For mixed hex, ascii ("123",22h,31h,"the quick brown fox")
 
I can't get the construct of the strings right. Can anyone help please?

Regards - Paul

hi,
You MUST use a FOR...NEXT loop to select each table character in turn.

Do you need an example.???
 
Last edited:
Thanks Eric.

Just a quickie, I need to start using a procedure buy OSHON gives me error 282. Support for functions and procedures is not enabled. How do I enable them?
 
Thanks Eric.

Just a quickie, I need to start using a procedure buy OSHON gives me error 282. Support for functions and procedures is not enabled. How do I enable them?

hi Paul,
Its an option you have to purchase from Oshonsoft, IIRC it part of the MATH32 support.
 
hi Paul,
Look at this demo option.

Code:
'for demo the strings are 10 characters long
'set the CONST to suit the 1st EEProm address of the string
'EEPROM addresses start a 00
Const name = 0
Const deci = 11
Const oshon = 22
Const pic = 33


Lcdinit
Gosub wr2eep  'write the strings to EEPROM, once ONLY

main:

Lcdcmdout LcdLine1Home
str = name
Gosub str2lcd

Lcdcmdout LcdLine2Home
str = deci
Gosub str2lcd

Lcdcmdout LcdLine3Home
str = oshon
Gosub str2lcd

Lcdcmdout LcdLine4Home
str = pic
Gosub str2lcd

Lcdcmdout LcdClear
Goto main

End                                               

'read a string from EEPROM and displays it
str2lcd:
For addr = str To 99
Read addr, chr
If chr = "," Then Return
Lcdout chr
Next addr
Return                                            

'this section stores the strings in EEprom, only required once.
wr2eep:
For pntr = 0 To 99  'this 99 will fill the EEprom after the text with ","
chr = LookUp("Eric Gibbs,0123456789,Oshonsoft ,PIC 16F877A,"), pntr
Write addr, chr  'write to EEprom
addr = addr + 1
Next pntr

Return
 

Attachments

  • AAesp03.gif
    AAesp03.gif
    6.9 KB · Views: 222
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top