how to create a For loop that "writes..."
orendacl
Posts: 44
Hello,
I want to·write a tag into EEPROM.
I have come up with the following:
WRITE (tagNo - 1 * 10 + idx), RFBuf(idx)
Note: That is as·the following applies:
tagNo······ VAR···· ·Nib
RFBuf······ VAR···· Byte(10)···············'bytes buffer size
I need to put this in a·FOR loop to write all 10 characters (idx 0 through 9) into the·first empty tagNum.·
Note:
The way I cam up with my WRITE statement is that (tagNo - 1 * 10 + idx) gives me·the address in EEPROM for an offset we use a lot in the BS2 (called·'idx') into a tag number 'tagNo'.· Because, that is not the data value we write to the EEPROM...rather·the data·I need to write is temporarily stored in the 10 character array variable RFBuf.
Hence,·to write character 'idx' of my·rf·id tag to 'tagNo', an·inner loop write statement would be:
WRITE (tagNo - 1 * 10 + idx), RFBuf(idx)
So, the question:
How do I write my outer loop?
?
?
?
Thanks, PS - A Final note:
The shell of this code was sourced from a parallax article by a former employee. The for loop he used to read tags was as follows:
Main:
'· LOW Enable··································· ' activate the reader
····· #IF __No_SPRAM #THEN
··· ' wait 2 seconds for hdr + ID
····· SERIN RX, T2400, [noparse][[/noparse]WAIT($0A), STR RFIDBuf\10]
···· #ELSE
··· ' wait 2 seconds for hdr + ID
···· SERIN RX, T2400, [noparse][[/noparse]WAIT($0A), SPSTR 10]
··· #ENDIF
'· HIGH Enable·································· ' deactivate reader
Check_List:
· FOR tagNo = 1 TO LastTag····················· ' scan through known tags; we can declare LastTag to be some number of tags, say 6
··· FOR idx = 0 TO 9···························· ····· ' scan bytes in tag
····· READ (tagNum - 1 * 10 + idx), char·····' get tag data from table
······· IF (char <> RFIDBuf(idx)) THEN Bad_Tag· ' compare tag to table...was Bad_Char
·····NEXT
·
··
I want to·write a tag into EEPROM.
I have come up with the following:
WRITE (tagNo - 1 * 10 + idx), RFBuf(idx)
Note: That is as·the following applies:
tagNo······ VAR···· ·Nib
RFBuf······ VAR···· Byte(10)···············'bytes buffer size
I need to put this in a·FOR loop to write all 10 characters (idx 0 through 9) into the·first empty tagNum.·
Note:
The way I cam up with my WRITE statement is that (tagNo - 1 * 10 + idx) gives me·the address in EEPROM for an offset we use a lot in the BS2 (called·'idx') into a tag number 'tagNo'.· Because, that is not the data value we write to the EEPROM...rather·the data·I need to write is temporarily stored in the 10 character array variable RFBuf.
Hence,·to write character 'idx' of my·rf·id tag to 'tagNo', an·inner loop write statement would be:
WRITE (tagNo - 1 * 10 + idx), RFBuf(idx)
So, the question:
How do I write my outer loop?
?
?
?
Thanks, PS - A Final note:
The shell of this code was sourced from a parallax article by a former employee. The for loop he used to read tags was as follows:
Main:
'· LOW Enable··································· ' activate the reader
····· #IF __No_SPRAM #THEN
··· ' wait 2 seconds for hdr + ID
····· SERIN RX, T2400, [noparse][[/noparse]WAIT($0A), STR RFIDBuf\10]
···· #ELSE
··· ' wait 2 seconds for hdr + ID
···· SERIN RX, T2400, [noparse][[/noparse]WAIT($0A), SPSTR 10]
··· #ENDIF
'· HIGH Enable·································· ' deactivate reader
Check_List:
· FOR tagNo = 1 TO LastTag····················· ' scan through known tags; we can declare LastTag to be some number of tags, say 6
··· FOR idx = 0 TO 9···························· ····· ' scan bytes in tag
····· READ (tagNum - 1 * 10 + idx), char·····' get tag data from table
······· IF (char <> RFIDBuf(idx)) THEN Bad_Tag· ' compare tag to table...was Bad_Char
·····NEXT
·
··
Comments
Also, an error in my post. I changed the original parallax post from jon williams article nuts and volts was using tagNum. I changed that to be tagNo as I use a similar name
Check_List:
FOR tagNo = 1 TO LastTag ' scan through known tags; we can declare LastTag to be some number of tags, say 6
FOR idx = 0 TO 9 ' scan bytes in tag
READ (tagNo - 1 * 10 + idx), char ' get tag data from table
I guess, what I need to ask is...woudl there be a such thing as:
for
do something write(..,..)
For
do something write
I mean, a write within a write?
***Well, I came up with:
WRITE (tagNo - 1 * 10 + idx), RFBuf(idx)
But this needs to go in a FOR loop to write all 10 characters (idx 0 through 9) to the first empty tagNo.
Would we simply use:
FOR tagNum = 1 TO LastTag ' scan through known tags
NEXT
FOR idx = 0 TO 9 ' scan bytes in tag
NEXT
WRITE (tagNum - 1 * 10 + idx), RFIDBuf(idx)
Tried that but after reading the tag, that I passed to write, it isn't getting added in. I have been removing my BS2 from my carrier board so I do not actually know if it is doing anything....kind of shooting in the dark.
Second, the statement being affected by the loop has to be inside the FOR / NEXT loop
Third, you can have nested loops like:
FOR i = 1 to 10
FOR j = 1 to 5
' do something
NEXT ' for variable j loop
NEXT ' for variable i loop
Your suggestion is exactly what i needed. A little but of reading and the whole problem solved. turns out I had all the pieces as you said but the order to place them is what mattered!!!
The FOR loops must be structured properly. For all of you guys that are wondering what happened here,...it was that I was using
FOR
NEXT
FOR
NEXT
This should have been FOR asdfsadfsdfasdfsd
································· FOR
······································ do something
·································· NEXT
································· NEXT
Man what a life saver this forum has been!···································
Could you post your working code for this project
I have been looking to something like this myself·
·I want to Thank You for sharing code if you would
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·Now wanting to learn Spin· Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam