Compiler error or am I missing something?

General discussion on mikroC for dsPIC30/33 and PIC24.
Post Reply
Author
Message
Hertz
Posts: 18
Joined: 28 Aug 2007 13:35

Compiler error or am I missing something?

#1 Post by Hertz » 12 Feb 2009 23:26

I have several times seen that when you are calculating a value in a parameter call somethings goes wrong. The code below shows my frustration:

Code: Select all

short unsigned int I2CPORTS[8] = {0xFE, 0xFD, 0xFB, 0xF7, 0xEF, 0xDF, 0xBF, 0x7F};

void PullPort(short unsigned int Port) {

    short unsigned int Address;
    Port -= 6;
    
    Address = (Port&0xF8)>>3;
    dp_I2C_Write(Address, I2CPORTS[(Port&=0x07)]);
    dp_I2C_Write(((Port&0xF8)>>3), I2CPORTS[(Port&=0x07)]); // dosen't work - WHY???
}
As everyone can see (I hope...) Address is calculated with the same formular as when I calculate the value on the fly, before calling dp_I2C_Write. Why does the first call work, but not the second. The value on the stack should be the same but they are not.

Can anyone explain - please...

The funny thing is, that there is no problem with the second parameter. But that value is not so complicated to calculate, and it is only used for computing an index into an array.

Thanks in advance

/Jacob

goran.marinkovic
mikroElektronika team
Posts: 265
Joined: 25 Nov 2008 09:09

#2 Post by goran.marinkovic » 17 Feb 2009 17:29

Hi,

Please post this question on our Support Desk:
http://www.mikroe.com/en/support/
And provide us with piece of code in a project like form that can be compiled
(packed in zip or rar format), which demonstrates the issue you are talking about.
Explain your code as much as possible, how it is supposed to work, when error occur,
what I need to do to reproduce your problem, so I can review it for any possible errors and suggestions.
It is important to send all the files in the project folder, so I can recreate your exact settings and flags of MCU.

Regards

Post Reply

Return to “mikroC for dsPIC30/33 and PIC24 General”