Anyone have a simple example of how I can do something like this but with larger numbers then 65535?
Counter VAR WORD
Loop:
Counter = Counter + 1
lcdout $FE, line1,"Counter:", #Counter
PAUSE 100
Goto Loop
Anyone have a simple example of how I can do something like this but with larger numbers then 65535?
Counter VAR WORD
Loop:
Counter = Counter + 1
lcdout $FE, line1,"Counter:", #Counter
PAUSE 100
Goto Loop
Well, the obvious, if using an 18F partIf you don't have an 18F part and all you want is a simple counter then perhaps something like this might work (not tested), it should count to 655 milions and a bit beyond:Code:Counter VAR LONG Main: ' Don't use Loop as a label, it's a reserved word. Counter = Counter + 1 lcdout $FE, line1,"Counter:", DEC Counter ' I think there's a problem with using # with LONG PAUSE 100 Goto Main
/Henrik.Code:TenThousands VAR WORD Ones VAR WORD Ones = Ones + 1 If Ones = 10000 THEN Ones = 0 TenThousands = TenThousands + 1 ENDIF LCDOUT $FE, line1, Counter: " IF TenThousands > 0 THEN LDCOUT DEC TenThousands, DEC4 Ones ELSE LCDOUT DEC Ones ENDIF
I'll bet that even if you own PBP3 and a 18F series chip, the code Henrik posted, will be using less memory and will be much faster than using Long variables.
Ioannis
Thanks for the feedback Fredrick!
Just a note, you don't need PBP3 to use LONGs, support for that were added in v2.5.
You do need an 18F part though. But, as Ioannis said, for a simple counter like that it's probably not worth the "cost" having them enabled.
/Henrik.
Bookmarks