ME Labs, Inc. 719-520-5323 |
Using Microchip's Floating Point Routines with PICBASIC PRO™
The PICBASIC PRO™ Compiler has several built-in data types: bits, bytes and words, along with arrays of each. All of these types are unsigned integers. This means there is no decimal point so real or floating point numbers cannot be represented. There are several workarounds for this, including multiplying each value by 10 or 100 for calculations and dividing back when it is time to display the value. Microchip has developed several different floating point routines in assembler and placed them on their web site. These routines can be integrated into a PICBASIC PRO program and called, if floating point is a necessity. While it is not that difficult, it is not obvious how to make this work properly. The necessary PICBASIC PRO source code to integrate either the 24-bit or 32-bit Microchip floating point routines into your program, FP.ZIP, may be downloaded. The appropriate floating point routines (Microchip's AN575) are included in this zip. The PICBASIC PRO programs must be compiled using the -ampasm switch to invoke Microchip's assembler. (In MicroCode Studio, click View - Compile And Program Options, then check the box labeled "Use MPASM".) You must have the MPASMWIN assembler installed on your harddrive. It is part of the MPLAB development environment, which is available as a free download from Microchip. The routines are accessed in PICBASIC PRO by setting up specific integer variables (aint and bint) and performing a GOSUB to a floating point routine. The first routine should convert the integer value (aint) to a floating point value. Generally, floating point operations occur between 2 numbers, so a second integer (bint) should also be converted. Next a GOSUB to the required floating point operation, multiply for example, is performed. Finally, the floating point number is converted back into an integer (aint) so that PICBASIC PRO can use it again. These GOSUB routines are created in an additional PICBASIC PRO file that must be INCLUDEd at the beginning of the program. The readme files included in the zip explain the procedures in more detail. Also, several example programs are included. Below is one example program that demonstrates the use of the libraries.
|
Copyright 2022 ME Labs, Inc. PO Box 8250 Asheville NC 28814 (719) 520-5323 (719) 520-1867 fax email: support@melabs.com |
|