View Full Version : two variables on LCD
savnik
- 25th June 2008, 19:57
I have two variables
Var1 var word
Var2 var word
The var1 is always 1 and the var2 is anything from 0 to 65535.
var1 = 00000000 00000001
var2 = 11111011 11010000
var1 + var2 = 00000000 00000001 11111011 11010000
Decimal = 130000
I want to show on LCD as Result = 1300,00
How to show the result on LCD;
skimask
- 25th June 2008, 21:42
I have two variables
Var1 var word
Var2 var word
The var1 is always 1 and the var2 is anything from 0 to 65535.
var1 = 00000000 00000001
var2 = 11111011 11010000
var1 + var2 = 00000000 00000001 11111011 11010000
Decimal = 130000
I want to show on LCD as Result = 1300,00
How to show the result on LCD;
Here we go again...
1) Get the update for PBP 2.50A. Handles LONG (31 bit variables, +/- 2,000,000,000)
2) Split the variable up the hard way...
original var1 = $1
original var2 = $fbd0
Add a small subroutine in your program to make it so that each word 'handles' 4 digits, so you end up with:
varhigh var word 'in this case it will be 0
varmed var word 'in this case should end up with 0013
varlow var word 'in this case should end up with 0000
Shouldn't be THAT hard.
Darrel Taylor
- 25th June 2008, 22:21
This is adapted from the thread ...
32-bit Variables and DIV32, Hourmeter 99999.9
http://www.picbasic.co.uk/forum/showthread.php?t=1942
Should work, but I haven't tested the modification.
BigVar VAR WORD[2] ; 32-bit (Dword)
Var1 VAR BigVar(1)
Var2 Var BigVar(0)
Result Var Word
Remainder Var Word
;----[Load a 32-bit (Dword) variable into PBP registers, Prior to DIV32]-----
Asm
PutMulResult?D macro Din
MOVE?BB Din, R2
MOVE?BB Din + 1 , R2 + 1
MOVE?BB Din + 2, R0
MOVE?BB Din + 3, R0 + 1
RST?RP
endm
EndAsm
;====[Simple loop to test Big Numbers]=======================================
Start:
Var1 = 1
Var2 = %1111101111010000
MainLoop:
LCDOUT $FE,1 ; clear screen
Gosub ShowBigNumber
PAUSE 1000
Var2 = Var2 + 1
if Var2 = 0 then Var1 = Var1 + 1
goto MainLoop
;================================================= ==========
;----[Display 32-bit value with 2 decimals using LCDOUT]---------------------
ShowBigNumber:
@ PutMulResult?D _BigVar
Result = DIV32 1000
Remainder = R2
LCDOUT $FE, 2 ; Home Cursor
IF Result > 0 then
LCDOUT Dec Result, DEC1 Remainder/100,".",DEC2 Remainder//100
else
LCDOUT DEC Remainder/100,".",DEC2 Remainder//100
endif
return
HTH,
DT
savnik
- 25th June 2008, 23:23
Thank you Darrel.
It's work fine.
Only i put out the two lines
Var2 = Var2 + 1
if Var2 = 0 then Var1 = Var1 + 1
Darrel Taylor
- 26th June 2008, 01:02
Only i put out the two lines
Var2 = Var2 + 1
if Var2 = 0 then Var1 = Var1 + 1
Exactly what you should have done. http://www.picbasic.co.uk/forum/images/icons/icon14.gif
Thanks for the update.
DT
Powered by vBulletin® Version 4.1.7 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.