"FOR...NEXT" command loops... usin "LOOKUP"
RevC
Posts: 12
Here is the code in use
' {$STAMP BS2}
' {$PBASIC 2.5}
index VAR Nib
OUTH = %00000000
DIRH = %11111111
DEBUG "index OUTH ", CR,
"
", CR
FOR index = 0 TO 16
LOOKUP index, [noparse][[/noparse] %11100111, %10000100, %11010011,
%11010110, %10110100, %01110110,
%01110111, %11000100, %11110111, %11110110,
%11110101, %00110111, %01100011, %10010111,
%01110011, %01110001, %01111110 ], debug
DEBUG " ", DEC2 index, " ", BIN8 OUTH, CR
PAUSE 500
NEXT
DIRH = %00000000
END
I am a newbie in case you're wondering.
I'm working with the 7 segment LED, BS2 on the education board.
The above code is from the book, I modified it so it'll display the character 0 to F instead of just 0 thru 9. That worked OK, but when I tried to make it go from 0 to G, the code just created a loop. It bahaved as if I had a "DO...LOOP" command instead of "FOR...NEXT".
I was wondering why when I went from " 0 to 15" all worked ok but then when I changed to "0 to 16" it just loops? Again this is in the "FOR...TO" part.
' {$STAMP BS2}
' {$PBASIC 2.5}
index VAR Nib
OUTH = %00000000
DIRH = %11111111
DEBUG "index OUTH ", CR,
"
", CR
FOR index = 0 TO 16
LOOKUP index, [noparse][[/noparse] %11100111, %10000100, %11010011,
%11010110, %10110100, %01110110,
%01110111, %11000100, %11110111, %11110110,
%11110101, %00110111, %01100011, %10010111,
%01110011, %01110001, %01111110 ], debug
DEBUG " ", DEC2 index, " ", BIN8 OUTH, CR
PAUSE 500
NEXT
DIRH = %00000000
END
I am a newbie in case you're wondering.
I'm working with the 7 segment LED, BS2 on the education board.
The above code is from the book, I modified it so it'll display the character 0 to F instead of just 0 thru 9. That worked OK, but when I tried to make it go from 0 to G, the code just created a loop. It bahaved as if I had a "DO...LOOP" command instead of "FOR...NEXT".
I was wondering why when I went from " 0 to 15" all worked ok but then when I changed to "0 to 16" it just loops? Again this is in the "FOR...TO" part.
Comments
A NIB is 4 bits, it can hold values of 0..15 (%0000..%1111). 16 is %10000, so the NIB gets loaded with %0000, which creates an infinite loop!
--Rich
You wont believe that I actually was just going over that when you posted the reply. I wonder what's happening inside the BS2 microcontroller that causes to loop.
Is it true then that if I tell to go from "0 TO 0" than it'll loop?