Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

7 digit LED Calculator, single, and double operation.

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
daro

Bascom Member



Joined: 15 Nov 2010
Posts: 25

blank.gif
PostPosted: Thu Sep 09, 2021 9:49 am    Post subject: 7 digit LED Calculator, single, and double operation. Reply with quote

Hi,
i making 7 digit LED calculator, and have problem with result, after operation on single and double operation.
I input data from keyboard switches into string:

Code:
Dim Number1 As String * 8
Dim Num As String * 10

Number1 = Number1 + Num 'Num is select by switches.


Same for next operand (Number 2)..As Num you can type dot "." into string to type single number.

Next convert:
Code:
Dim Operand1 As Double
Dim Operand2 As Double
Dim Result As Double

Operand1 = Val(number1)
Operand2 = Val(number2)
Result = Operand1 + Operand2


Now we never know what result is, so never know how long fraction of a Double is.

I trying to INT, and FRAC function but it seems to not work with Double? Single is not enough accurate for me.

Other method is:
Code:
         Num = Str(result)
         Pos = Charpos(num , ".")   'calc dot position on LED display
         Pos = Pos - 1
         Dot(pos) = 1
         Delchars Num , "."

         For I = 1 To 7
            Str_array(i) = Mid(num , I , 1)
            Dig(i) = Val(str_array(i))
         Next

but this result tralling zeros after number (after fraction part).

And is problem with dot position. For example:
111.222+333.444=444.666, and dot position from Pos = Charpos(num , ".") is correct, but 1111.222+3333.444=4444.666, and position is calculated wrong, becouse for example 4444.666 schould be Pos=5, but is 2...why?


For example 111.22 + 333.44, result display: 444.6600 (last two zeros are not needed), schould display _ _ 444.66. _ _ is leading off digits...

What is better way to convert result from a single/double, to array of digit for 7 digit LED display? (without tralling zeros after fraction part)

(BASCOM-AVR version : 2.0.8.2 , Latest : 2.0.8.4 )

EDIT. It seems them Charpos function (Pos = Charpos(num , Search_str)) not work propertly with Double data. When I change Result fot Single, Pos is calculated corectly.
So how to convert Double result in string, or 7 byte array, and read coma position?
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Thu Sep 09, 2021 7:48 pm    Post subject: Reply with quote

Maybe your Bascom needs an update because I dont see the problem in mine 2084 Very Happy

Code:
$regfile = "m328pdef.dat"
$crystal = 16000000
$hwstack=64
$swstack=64
$framesize = 128
$sim

Dim Number1 As String * 20
Dim Number2 As String * 20
Dim Operand1 As Double
Dim Operand2 As Double
Dim Result As Double
Dim Resultstr As String * 20
Dim Pos As Byte

Number1 = "111.22"
Number2 = "333.44"

Operand1 = Val(number1)
Operand2 = Val(number2)
Result = Operand1 + Operand2
Resultstr = Str(result)
Pos = Charpos(resultstr , ".")

Print "First adding " ; Number1 ; " to the " ; Number2 ; " and the result is " ; Result ; " (" ; Resultstr ; "). ";
Print "Result string is " ; Len(resultstr) ; " characters long." ;
Print " The dot is on " ; Pos ; " place."

Number1 = "111.222"
Number2 = "333.444"

Operand1 = Val(number1)
Operand2 = Val(number2)
Result = Operand1 + Operand2
Resultstr = Str(result)
Pos = Charpos(resultstr , ".")

Print "Now adding " ; Number1 ; " to the " ; Number2 ; " and the result is " ; Result ; " (" ; Resultstr ; "). ";
Print "Result string is " ; Len(resultstr) ; " characters long." ;
Print " The dot is on " ; Pos ; " place."

End


 


Back to top
View user's profile Visit poster's website
Evert :-)

Bascom Expert



Joined: 18 Feb 2005
Posts: 2156

netherlands.gif
PostPosted: Thu Sep 09, 2021 8:24 pm    Post subject: Reply with quote

Daro,
Show us your complete code that's not working.
Code from EDC is working, so maybe you do something else wrong.
Low stack?

_________________
www.evertdekker.com Bascom code vault
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum