Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

[MPLAB] Multiplication (*) doesn't work

Status
Not open for further replies.

John27

New Member
Hello everyone !

MPLAB (8.9) makes me crazy and I would like to get your help in order to fix it.
My program is very simple :

Code:
#include "33EP512MU810.h"
#DEVICE ICD = true, ICD = 3

#FUSES NOPROTECT, NOWRT, NOGSSK, NOAPLK, NOWDT, noPUT,HS, CKSFSM, PLLWAIT, NOIOL1WAY, noIESO, NOJTAG,debug

void main(void){
float z=5.0;
z=z*10.0;
}


I use MPLAB SIM and in the end, the value of z is 100 instead of 50 (I monitored the value via the Watch)
Why ? Can you help me ?

Thanks
 
It is generally undefined what happens with local variables after you leave "main".

I would insert

C:
while(1);

at the end of the "main" and put a breakpoint in there.

I would also make sure that z is used somewhere, because otherwise it doesn't matter what value gets assigned to it, so the compiler could have optimized your manipulations away.[/CODE]
 
I would also make sure that z is used somewhere, because otherwise it doesn't matter what value gets assigned to it, so the compiler could have optimized your manipulations away.

An easy fix for this is to declare the variable volatile. On a PC you could just output it to the screen, but in a uC it can a bit harder to use a variable in a way that doesn't effect the operation of the code, but also can't be optimized out by the compiler. By marking it as volatile the compiler knows there is more to the variable than there appears and any code that references it will be run as written.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top