Dave
Always wear safety glasses while programming.
Hi Dave,
It can't ever be more than 3000ms because the highest value possibly returned by Random is 65535, anything larger won't fit in the WORD variable. We multiply that by 1000 and divide it by 21845 resulting in 3000. So, with these numbers it's simply impossible to get anything "larger" than 3000.
/Henrik.
Me and Rube have a lot in common, he draws them and I make themGoldberg is best known for a series of popular cartoons he created depicting complex devices that perform simple tasks in indirect, convoluted ways.
Hi Henrik, I can appreciate that, I thought it was just cool to be able to see the numbers via the Serial Communicator.It can't ever be more than 3000ms because the highest value possibly returned by Random is 65535, anything larger won't fit in the WORD variable. We multiply that by 1000 and divide it by 21845 resulting in 3000. So, with these numbers it's simply impossible to get anything "larger" than 3000.
What did you think of the way in which I made the program run using VARS: X,Y and Z?
Dave
Hi Dave,
Nothing wrong at all with the way you did it. However, it seems to me you are "wasting" four bytes of RAM with the use of Y and Z. If you don't need to massage the intermediate results it's perfectly OK to simply use a single WORD variable, like/Henrik.Code:X VAR WORD RANDOM X X = X * 1000 X = DIV32 21845 SEROUT2 PORTC.3, 16780, [DEC X, 13, 10]
Hi Henrik,
Here's a strange thing (and I'll re-check this later). I originally ran the code as yours above and the output was something like: 2411-341-11-0-0-0-0-0. After only a few cycles it started outputting zero's.
I may well have made a 'typo' myself here so I'll re-check and re-run later today.
Dave
Last edited by LEDave; - 10th July 2010 at 10:41.
Hi Dave,
Actually, it looks like you got me on this one... I'll HAVE to start verifying what I write before trying to look like I know what I'm talking about ;-) Don't know what's going on here, I'll have to try a few things out.
/Henrik.
EDIT: OK, I'm not sure exactly what's going on but this does seem to work:Thanks Dave for catching that and letting me know!Code:RANDOM X Y = X * 1000 Y = DIV32 21845
Last edited by HenrikOlsson; - 10th July 2010 at 11:31.
Henrik,
I think our student has been reading the manual and caught the "dummy" var in the examples given.
I think our student has also increased in rank!
Maybe now he is
NEWBIE.2
![]()
Dave
Always wear safety glasses while programming.
Bookmarks