News:

;) This forum is the property of Proton software developers

Main Menu

how to convert variable that come from serin to float?

Started by hitronics, Feb 20, 2021, 09:59 AM

Previous topic - Next topic

hitronics

I connect bluetooth module to pic chip then using serin command to get data "1.25" how to convert incoming data to float & save on eeprom?

FiremanTR

Dim abc As Float
Dim a[4] As Byte
Symbol abc1 = abc.Word0
Symbol abc2 = abc.Word1

abc1.LowByte  =a[0]
abc1.HighByte =a[1]
abc2.LowByte = a[2]
abc2.HighByte =a[3]


"abc" float variable from buffer "a"


Dim abc As Float
Dim volt As Byte
Dim mV As Byte
Dim sample As Word


sample =abc *100
volt = sample /100
mV =sample //100


We convert sample = float to integer with 100
We divide the integer "sample" by 100 to get the value of byte "volts".
We obtained the whole number of "samples", the remainder from 100, the value of byte "mV".

is it that way?


The best thing I know is that I know nothing
__SOCRATES__

top204

If you are using an enhanced 14-bit core device, 18F device, PIC24 device or a dsPIC33 device, another way is to receive the data into a string and convert the string into a floating point variable using the StrToFloat procedure located in the "Strings.inc" library file.

Include the "Strings.inc" file at the top of your program and the procedures within it are automatically available for you. Any procedures that are not used within the library will not be included in your program. i.e. A true library mechanism!

The compiler's library files are all located in the users includes directory that is installed with the compilers: "C:\Users\User Name\PDS\Includes"



hitronics

Quote from: top204 on Feb 20, 2021, 03:25 PMIf you are using an enhanced 14-bit core device, 18F device, PIC24 device or a dsPIC33 device, another way is to receive the data into a string and convert the string into a floating point variable using the StrToFloat procedure located in the "Strings.inc" library file.

Include the "Strings.inc" file at the top of your program and the procedures within it are automatically available for you. Any procedures that are not used within the library will not be included in your program. i.e. A true library mechanism!

The compiler's library files are all located in the users includes directory that is installed with the compilers: "C:\Users\User Name\PDS\Includes"




I want to use small chip as 12F675
I did not find Strings.inc

TimB


Use a supported device that is capable of using strings like the PIC18F13K22

Great little device


top204

Tim's correct.

The "old" 14-bit core devices are not suitable for floating point or strings, or many of the enhancements that the compiler offers because they have so little, fragmented, RAM.

The compiler supports floating point with them, but not Strings because of their dreadful RAM organisation, and because thay are now approx 15 years out of date with their internal hardware. :-)

The newer enhanced 14-bit core devices are better because they have more RAM, operate faster, and have an internal mechanism that makes indirect access to the RAM linear, but they are not as good as the 18F devices.


John Drew

If you are stuck with the pic12 you can use the solution from PRO-TR. I use that method.

If you are like me I often have a stock of Pics and I like to press existing stock into service.
 
Otherwise if you're needing to buy in then you are better off getting an 18F as Tim and Les advise and the string solution is more flexible.
John

hitronics

thanks for your suggestions
by the way, proton can support LGT8F684 & LGT8F690?

TimB


Ref "LGT8F684 & LGT8F690"

The short answers is no. You could try compiling for the pic its copied off and then see if the hex works.

If you are really trying to use the dirt cheap alternative then you must want to sell 10's of 1000's of them. In that case you need to invest in the appropriate compiler.

What is preventing you using a newer device?

top204

As Tim stated, probably not. Unless they are exact copies of the PIC16F684 and PIC16F690 devices.

However, looking at some of the specification for them, there does seem to be differences in the peripherals, but if the mnemonic set is the same and the RAM locations etc, they may work.

Why would a company copy such an outdated microcontroller? Do they operate any faster then PIC microcontrollers, as the SX devices used to do? It's a shame the SX devices were not advanced, instead of keeping them with the dreadful 12-bit architecture. They were blisteringly fast, and an 18F type SX equivalent operating at, something like, 200MHz would be wonderful. :-)


hitronics

I think they offer cheaper price, it seems many Chinese & Indian factories used these chips, for me now I am playing with small chip to do project as Ac current meter connected to bluetooth and build mobile app to monitor & control current