LONG will treat the variable as a Word (16 bits) as opposed to a Byte of 8 bits. so the Most you can have is 65535, you`re over 4 times that value, no idea why you get 86 though, unless it`s some sort of wrap-around?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
There was no routine in the LCD library to print Long variables, but adding one seemed like a good idea. So, please try the update from http://gcbasic.sourceforge.net/update.html - if the new LCD Print routine works, I will adapt it for RS232 as well.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I was having problems using LONG variables in a complex program so I wrote this simple one to try to understand what was happening.
I'm using a PIC 18F252.
;Variables
Dim Aa As word
Dim Bb As word
Dim Cc As long
'
Aa = 823
Bb = 346
locate 0, 0
print Aa
locate 1, 0
print Bb
'
Cc = Aa * Bb
locate 2, 0
print Cc
At location 0, 0 on the LCD, I see 823 which was expected.
At location 1, 0 on the LCD, I see 346 which was expected.
But at location 2, 0 on the LCD, I see 86. I expect3ed to see 284758 ( 823 * 346 = 284758).
I've tried DIMing Aa and Bb as LONG but still don't get the correct answer
What am I doing wrong?
LONG will treat the variable as a Word (16 bits) as opposed to a Byte of 8 bits. so the Most you can have is 65535, you`re over 4 times that value, no idea why you get 86 though, unless it`s some sort of wrap-around?
I don't think the LCD library has a routine yet for printing longs so its just printing the low byte of the long Cc.
You could try printing out the four bytes of the long individually in hex -
LCDHex(Cc_E)
LCDHex(Cc_U)
LCDHex(Cc_H)
LCDHex(Cc)
just to check that the calculation is working.
There was no routine in the LCD library to print Long variables, but adding one seemed like a good idea. So, please try the update from http://gcbasic.sourceforge.net/update.html - if the new LCD Print routine works, I will adapt it for RS232 as well.
The Update worked.
Thanks!