Not performing multiplication and division operation with decimal number in PIC

Thread Starter

ecaits

Joined Jan 6, 2014
56
Dear All,

I cannot perform multiplication and division with integer number in pic 16f877 using hi-tech c compiler.


What is reason behind that???
 

MrChips

Joined Oct 2, 2009
30,821
A number of reasons.

Give us some examples of numbers and the results.
Show us your code.

How did you declare your variables, i.e. how many bits did you assign to the variable?
 

Thread Starter

ecaits

Joined Jan 6, 2014
56
Plz find code


#include<pic.h>
#include<htc.h>
#include<stdlib.h>
#include<math.h>

void main()
{

int i=12,d=15,t=0,k=0,b=0,m=0;
float j=0;

t=i;
b=(i*2);
k=i/3;
j=i;
m=i+d;

}
 

tshuck

Joined Oct 18, 2012
3,534
And you verified the answers how?

Since nothing is actually done with these numbers, the compiler may optimize them out - putting volatile ints and floats tells the compiler not to remove them.

Also, your code should have an infinite loop to prevent the controller from getting into undefined operations (typically done with a while (1){} loop).

Also, use code tags when posting code (button that looks like "#", which will put your code between two tags: [CODE ] and [/CODE ] (use without spaces in the tags)).
 

Ian Rogers

Joined Dec 12, 2012
1,136
And you verified the answers how?

Since nothing is actually done with these numbers, the compiler may optimize them out - putting volatile ints and floats tells the compiler not to remove them.

Also, your code should have an infinite loop to prevent the controller from getting into undefined operations (typically done with a while (1){} loop).

Also, use code tags when posting code (button that looks like "#", which will put your code between two tags: [CODE ] and [/CODE ] (use without spaces in the tags)).
That's exactly what's happening!!! Testing your code and making the variables volatile you get to see it working!!

Rich (BB code):
#include<xc.h>  // I use XC8.

#include<stdlib.h>
#include<math.h>

void main()
	{
	volatile int i=12,d=15,t=0,k=0,b=0,m=0;
	volatile float j=0;

	t=i;
	b=(i*2);
	k=i/3;
	j=i;
	m=i+d;

	}
 

t06afre

Joined May 11, 2009
5,934
Setting the Hi-Tech C or XC8 compiler in free mode(or lite mode) also works. If you just want to single step your code and see the result while debugging
 

spinnaker

Joined Oct 29, 2009
7,830
Setting the Hi-Tech C or XC8 compiler in free mode(or lite mode) also works. If you just want to single step your code and see the result while debugging

Not so sure. I have seen the free XC8 still do some crazy things in debug which I can only guess is due to optimization.
 
Top