Forum - MCS Electronics

Author Message
daro

Joined: 15 Nov 2010
Posts: 25

Posted: Thu Sep 09, 2021 9:49 am    Post subject: 7 digit LED Calculator, single, and double operation.

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?
EDC

Joined: 26 Mar 2014
Posts: 757

Posted: Thu Sep 09, 2021 7:48 pm    Post subject:

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

 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

Evert :-)

Joined: 18 Feb 2005
Posts: 2134

 Posted: Thu Sep 09, 2021 8:24 pm    Post subject: 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
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
 All times are GMT + 1 Hour Page 1 of 1

 Jump to: Select a forum BASCOM AVR/8051----------------BASCOM-AVRBASCOM-8051BASCOM-ARDUINOShare your working BASCOM-8051 code hereShare your working BASCOM-AVR code hereBASCOM BETA-SLA BASCOM Related----------------EASY TCP/IPAVR-DOSAR7212KokkeKat FAT-free SD card libBASCOM Project Blog Other Stuff----------------VariousPCB'sRoboticsNew WebSiteAnnouncementsAVR Archive----------------BASCOM-AVR ArchiveBASCOM-8051 ArchiveBASCOM-AVR Unsupported versionsEasy TCP/IP ArchiveBASCOM-EDB
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