Shop OBEX P1 Docs P2 Docs Learn Events
"FOR...NEXT" command loops... usin "LOOKUP" — Parallax Forums

"FOR...NEXT" command loops... usin "LOOKUP"

RevCRevC Posts: 12
edited 2009-09-17 21:12 in BASIC Stamp
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.

Comments

  • RiJoRiRiJoRi Posts: 157
    edited 2009-09-17 20:48
    Nasty little bug, there!
    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
  • RevCRevC Posts: 12
    edited 2009-09-17 20:56
    Thank you much RiJoRi... I was really intrigued by this.

    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?
  • RevCRevC Posts: 12
    edited 2009-09-17 21:12
    I guess it doesn't... because index is getting set to 0, and the table does start at 0 for the first table value, it actually does send display the first value which actually is also 0.
Sign In or Register to comment.