Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Mathematical operations involving fractions in picbasic

Status
Not open for further replies.

emavil

Member level 2
Joined
Oct 18, 2005
Messages
53
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,288
Activity points
1,738
operations involving fractions

Hi, I would like to know how to perform multiplication and division in PICBasic involving fractions. Computations like conversion of degrees Celsius to Deg. Fahr. How do we send such values to LCD
 

picbasic celsius fahrenheit conversion

Picbasic handles only integer numbers or variables, so the best way to convert celsius to fahrenheit degrees is to use WORD variables (16 bits wide) and shift numbers 10 or 100 times greater and do the calculations step by step.

For example:

Convert 25 degrees celsius to fahrenheit:

F = C x 9 / 5 + 32

First define two variables as word
Fahr var word (can handle up to 65535)
Cels var word

Then

Cels = 2500 '(100 times 25, will keep a good precision)
Fahr = Cels x 9 '2500 x 9 = 22500
Fahr = Fahr / 5 '22500 / 5 = 4500
Fahr = Fahr + 320 '4500+3200 = 7700

Now you have the variable Fahr with a value 100 times greater than the real value, considering the decimal point 2 positions left, the real value is 77 degrees fahrenheit.

Just use the command DIG to separate digits into 4 or 5 single digits (create separate variables) and send them one by one via LCDOUT command (insert LCDOUT "." between the correct digits). Check the manual for details.
 

picbasic word math operations

Can this handle negative temps?

Tornado
 

No, the variables and all math operations are unsigned and integers (8 or 16 bits). One solution is to create signal flags (compare variables before subtraction) and consider them in the calculations.

Another solution is to use the FP routines that can handle signed floating point numbers, but it spends a lot of memory and resources of the PICs.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top