View previous topic :: View next topic |
Author |
Message |
KenHorse
Joined: 16 Jul 2004 Posts: 523
|
Posted: Mon Sep 11, 2017 4:31 pm Post subject: Lookup using variable? |
|
|
According to the HELP, you can use a variable for the LABEL when using LOOKUP.
"You may also use a variable that holds the address of a label."
Take the following code as an example:
Code: |
Dim TempString As String * 30
Dim TempInt As Integer
Dim Index As Integer
Index =10
TempString = "EEPROM1"
TempInt = LOOKUP(Index , TempString)
Print "TempInt " ; TempInt
End
EEPROM1:
Data 1% , 2% , 3% , 4% , 5% , 6% , 7% , 8% , 9% , 10% , 11% , 12% , 13% , 14% , 15% , 16% , 17% , 18% , 19% , 20% , 21% , 22% , 23% , 24% |
TempInt returns a -1
Instead of using a string, I tried this instead:
Code: |
Dim TempString As String * 30
Dim TempInt As Integer
Dim Index As Integer
Dim TempInt2 As Integer
Index =10
TempInt2 = 3
TempInt = LOOKUP(Index , TempInt2)
Print "TempInt " ; TempInt
End
1:
Data 1% , 2% , 3% , 4% , 5% , 6% , 7% , 8% , 9% , 10% , 11% , 12% , 13% , 14% , 15% , 16% , 17% , 18% , 19% , 20% , 21% , 22% , 23% , 24%
|
And this returns 6144
What am I doing wrong? |
|
Back to top |
|
|
KenHorse
Joined: 16 Jul 2004 Posts: 523
|
Posted: Mon Sep 11, 2017 4:37 pm Post subject: Re: Lookup using variable? |
|
|
KenHorse wrote: | According to the HELP, you can use a variable for the LABEL when using LOOKUP.
"You may also use a variable that holds the address of a label."
Take the following code as an example:
Code: |
Dim TempString As String * 30
Dim TempInt As Integer
Dim Index As Integer
Index =10
TempString = "EEPROM1"
TempInt = LOOKUP(Index , TempString)
Print "TempInt " ; TempInt
End
EEPROM1:
Data 1% , 2% , 3% , 4% , 5% , 6% , 7% , 8% , 9% , 10% , 11% , 12% , 13% , 14% , 15% , 16% , 17% , 18% , 19% , 20% , 21% , 22% , 23% , 24% |
TempInt returns a -1
Instead of using a string, I tried this instead:
Code: |
Dim TempString As String * 30
Dim TempInt As Integer
Dim Index As Integer
Dim TempInt2 As Integer
Index =10
TempInt2 = 1
TempInt = LOOKUP(Index , TempInt2)
Print "TempInt " ; TempInt
End
1:
Data 1% , 2% , 3% , 4% , 5% , 6% , 7% , 8% , 9% , 10% , 11% , 12% , 13% , 14% , 15% , 16% , 17% , 18% , 19% , 20% , 21% , 22% , 23% , 24%
|
And this returns 6144
What am I doing wrong? |
|
|
Back to top |
|
|
six1
Joined: 27 Feb 2009 Posts: 553
|
Posted: Tue Sep 12, 2017 6:51 am Post subject: |
|
|
"Address of a Label" can be done with LOADLABEL _________________ For technical reasons, the signature is on the back of this message. |
|
Back to top |
|
|
KenHorse
Joined: 16 Jul 2004 Posts: 523
|
Posted: Tue Sep 12, 2017 3:43 pm Post subject: |
|
|
six1 wrote: | "Address of a Label" can be done with LOADLABEL |
I'm not sure that's what I'm looking for as I'm not using the $EEPROM directive
But since I'm using a Mega2561, even if it is, I guess I can't do this (Help says it only works for <=64K memory AVRs)
Oh well.....
Last edited by KenHorse on Tue Sep 12, 2017 3:52 pm; edited 1 time in total |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue Sep 12, 2017 3:49 pm Post subject: |
|
|
it should work with >64K also.
lookup was enhanced later to support this. _________________ Mark |
|
Back to top |
|
|
KenHorse
Joined: 16 Jul 2004 Posts: 523
|
Posted: Tue Sep 12, 2017 3:53 pm Post subject: |
|
|
albertsm wrote: | it should work with >64K also.
lookup was enhanced later to support this. |
Doesn't seem to work in the simulator:
Code: |
Dim TempInt As Integer
Dim Index As Integer
Dim A As Integer
Index = 5
TempInt = LOOKUP(Index , A)
Print "TempInt " ; TempInt
End
EEPROM1:
Data 1% , 2% , 3% , 4% , 5% , 6% , 7% , 8% , 9% , 10% , 11% , 12% , 13% , 14% , 15% , 16% , 17% , 18% , 19% , 20% , 21% , 22% , 23% , 24%
A = Loadlabel(EEPROM1) |
This returns -27368 |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue Sep 12, 2017 8:07 pm Post subject: |
|
|
doesnt surprise me
why did you put this : A = Loadlabel(EEPROM1) at the bottom?
you should load the value BEFORE you use the variable A. _________________ Mark |
|
Back to top |
|
|
KenHorse
Joined: 16 Jul 2004 Posts: 523
|
Posted: Tue Sep 12, 2017 8:15 pm Post subject: |
|
|
albertsm wrote: | doesnt surprise me
why did you put this : A = Loadlabel(EEPROM1) at the bottom?
you should load the value BEFORE you use the variable A. |
Point 1 - doesn't matter where I put it, it still doesn't work for me
Point 2 - the HELP says (and shows):
Quote: | Loadlabel will only work for processors with <= 64KB memory.
If you use Loadlabel on an EEPROM label (a label used in the $EEPROM data area) , these labels must precede the Loadlabel function.
This would be ok :
$eeprom ' eeprom image
label1:
data 1,2,3,4,5
label2:
data 6,7,8,9,10
$data ' back to normal mode
dim w as word
w=loadlabel(label2)
This code will work since the loadlabel is used after the EEPROM data labels.
|
Sorry Mark but this is confusing |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue Sep 12, 2017 9:58 pm Post subject: |
|
|
you did not specified the version you use. I use 2080.
so if you use an older version it will not work with >64K.
loadlabel loads the address of a label into a variable.
you could pass this to lookup()
lookup does not work on eeprom data.
you mix up 2 things from the help.
the working code is this :
Code: | Dim TempInt As Integer
Dim Index As Integer
Dim A As Integer
Index = 5
A = Loadlabel(EEPROM1)
TempInt = LOOKUP(Index , A)
Print "TempInt " ; TempInt
End
EEPROM1:
Data 1% , 2% , 3% , 4% , 5% , 6% , 7% , 8% , 9% , 10% , 11% , 12% , 13% , 14% , 15% , 16% , 17% , 18% , 19% , 20% , 21% , 22% , 23% , 24%
|
in the loadlabel help text , there is a remark that when you load the address of a label in EEPROM, you must place the eeprom data before the loadlabel. this because eeprom data is not actual data that ends up in flash but in a file you can use to program the eeprom. _________________ Mark |
|
Back to top |
|
|
KenHorse
Joined: 16 Jul 2004 Posts: 523
|
Posted: Tue Sep 12, 2017 10:15 pm Post subject: |
|
|
albertsm wrote: | you did not specified the version you use. I use 2080.
so if you use an older version it will not work with >64K.
loadlabel loads the address of a label into a variable.
you could pass this to lookup()
lookup does not work on eeprom data.
you mix up 2 things from the help.
the working code is this :
Code: | Dim TempInt As Integer
Dim Index As Integer
Dim A As Integer
Index = 5
A = Loadlabel(EEPROM1)
TempInt = LOOKUP(Index , A)
Print "TempInt " ; TempInt
End
EEPROM1:
Data 1% , 2% , 3% , 4% , 5% , 6% , 7% , 8% , 9% , 10% , 11% , 12% , 13% , 14% , 15% , 16% , 17% , 18% , 19% , 20% , 21% , 22% , 23% , 24%
|
in the loadlabel help text , there is a remark that when you load the address of a label in EEPROM, you must place the eeprom data before the loadlabel. this because eeprom data is not actual data that ends up in flash but in a file you can use to program the eeprom. |
Sorry, using 2.0.7.9 (don't see a license file for 2.0.8.0) |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue Sep 12, 2017 10:18 pm Post subject: |
|
|
my working code will also work for 2079, just not when data is located in pages other than the first.
there is no lic file for 2080, only a full setup. _________________ Mark |
|
Back to top |
|
|
KenHorse
Joined: 16 Jul 2004 Posts: 523
|
Posted: Tue Sep 12, 2017 10:23 pm Post subject: |
|
|
albertsm wrote: | my working code will also work for 2079, just not when data is located in pages other than the first.
there is no lic file for 2080, only a full setup. |
Got it, thanks |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|