how to multiply two numbers in c in pic microcontroller?

Status
Not open for further replies.

engr.waqas

Full Member level 3
Joined
Jul 21, 2009
Messages
172
Helped
13
Reputation
26
Reaction score
10
Trophy points
1,298
Location
karachi,Pakistan
Activity points
2,342
how to multiply in c

I want to multiply 819.2 with 0.0048828125 in pic using C language.
anyone can explain me this and give me C coding.
 

multiply microcontroller

void mult()
{
float f;

f=819.2*0.0048828125;

}

the answer is 4
 

multiply two numbers

I hope u had a problem with precision.
u can double or long double for more precise value.
 

c - multiply two numbers

actually i am taking data from a sensor whose output is 4 volt i.e analog input to pic is 4 volt .now for Vref=5 volt, i have step size of 0.0048828125 so i have multiply the output of controller's builtin A\D to 0.0048828125 to get real value that is 4.
How to do this
A\D binary output is stored in 2 registers as in PIC i.e ADRESl & ADRESH
plz help how to multiply value stored in ADRESL & ADRESH to 0.0048828125
 

pic c multiply

float ADnumber = (float)((int)(((int)ADRESH << 8 ) | ADRESL)) * 0.0048828125f

I think that would do it. I would check with a normal C compiler first tho. All this does is transform ADRESL & ADRESH into a 16-bit number, change that to a float, and then multiply it with your constant.
 

multiply number in c

Just because it doesn't have them physically doesn't mean you can't use them virtually. If you are using a C compiler of any variety (MCC18, mikroC, SourceBoost etc) it will use two 8-bit registers for a 16-bit number. That is a really basic concept btw. Trust me, I use only PICs (mainly 18F) and I use 16-bit variables all the time.
 

multiply in pic

That will do it because there is no need of a 16-bit register in this operation.
He is virtually implementing a 16-bit value using 2 8-bit registers.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…