Lookdown-lookup
Is it ok to construct two look down tables that refer to the same look up table? I have 360 items to look down through, but pairs of them refer to the same reference item in a look up table. For example, if I have a, b, c, d, e...etc. (180 such items in one look down table) and I have aa, bb, cc, dd, ee...etc. (another 180 items in another look down table), and the look up table has 2, 4, 6, 8, 10...(180 such items in the table), and both "a" and "aa" refer to 2, is such an arrangement feasible? If the item being looked down is "aa," and it's not found in the first table, can it be written so that the search continues to the second table so that the referent "2" can be found and placed in memory?
Or is there a far easier way to do this maneuver?
Or is there a far easier way to do this maneuver?
Comments
z = 0 lookdown x,[5,8,13,21,34,55,89],z IF z=0 THEN lookdown x,[4,7,12,20,33,54,88],z IF z=0 THEN DEBUG "bad luck",CR ELSE lookup z,[..........],k DEBUG "value=", DEC z,TAB,DEC k,CR END
There is a limit on the number of values in a lookdown (=256). Also, LOOKDOWN can use a comparison like > or < rather than the default =.It may be better to not use LOOKDOWN, and instead to store all of the "a"'s and "aa"s as DATA in eeprom, and write a little subroutine to find the match.
If the items in the lookup do in fact form a regular sequence like 2, 4, 6, 8, ..., then a loopup would not be needed at all. Just a math formula to relate the lookdown index to the output number.
[COLOR=red]' MM is month (binary, not BCD), DD is day of month, YY is year (e.g. 11, for leap year) JD=MM-1*30+(MM/9+MM/2)-(MM max 3/3*(YY//4 max 1 +1))+ DD[/COLOR]
Once you have day of year, you can use that for lookup. It is probably good enough to have it done for every 5 or 7 days and interpolate if helpful.
DD = ((d-"0") * 10) + (y-"0") ' 2 * 10 + 3 = 23 ' day of month
MM = ((m - "0") * 10) + (n - "0") ' month of year
When the Stamp encounters something like d="2" or this (d - "0"), it substitutes the ascii code for the thing in quotes. So for d="2" it subsitutes d=$32 (or decimal d=50, same number inside the computer). And for (d - "0") it substitutes (d - $30) or same thing (d - 48) in decimal.
To get from day and month to the sequential day of year is a little more complicated, because of the varying number of days in a month. That was the purpose of the formula I posted above. If you don't care about adjusting for leap years, then it can be simplified to,
JD = (MM - 1 * 30) + (MM/9+MM/2) - (MM max 3 / 3 * 2)+ DD
where MM and DD are integer values as calculated above from the GPS data.
JD then is a Word number that runs from 0 to 364.
In your example, 50514857, the four bytes are d=50 y=51 m=48 n=57.
You are correct: d-"0" is equiv to d-48 is equiv to d-$30. So,
d-48 = 50-48 = 2 y-48 = 51-48 = 3 m-48 = 48-48 = 0 n-48 = 57-48 = 9
Put the 10s and the 1s digits together into two integer bytes for day and month:dd = 2*10 + 3 = 23 mm = 0*10 + 9 = 9
Now into my formula for day of year (keeping in mind the Stamp's order of operations)[COLOR=black]JD = (MM - 1 * 30) + (MM/9+MM/2) - (MM max 3 / 3 * 2)+ DD = ((9 - 1) * 30) + ((9/9) + (9/2)) - ((3/3) * 2) + 23 = (8 * 30) + (1 + 4) - (1 * 2) + 23 = 240 + 5 - 2 + 23 = 266[/COLOR]
So Sep 23rd 2011 is the 266th day of the year. (Oh, in my previous post, I should have said 1 to 365, not 0 to 364!)
You also asked,"What is the ‘ mark..." It is the comment marker. Everything that follows the ' is a comment, not code.