So I'm programming a PIC using a CCS compliler. I'm using timer interrupt and this interrupt calls a function, called chronometer, that I wrote twice. This is how it goes
void timer2_isr()
{
j++;
l++;
z++;
if (j==1)
{
timero=1;
btndly=1;
j=0;
}
user1= chronometer(x, l);
user2= chronometer(pad.deger, z);
}
This function returns a struct and takes 2 integers as an argument. It works fine, when I just call the function once. However when, as in this case, I call the function twice, user2 is just equal to whatever user1 is and the code is not even working correctly. Any idea why?
chrono chronometer(int enable, int milicounter)
{
chrono time;
if(enable==1 && milicounter>=25) // Eğer kronometre aktif haldeyse
{
milicounter=0;
time.sec++;
if(time.sec==60)
{
time.sec=0;
time.min++;
}
if(time.min==60)
{
time.min=0;
time.hour++;
}
if(time.hour==24)
time.hour=0;
}
return time;
}
似乎您开始使用time struct而不重置其成员,从而导致了意外的结果..即使以某种方式进行了初始化..它没有引用输入参数,所以显然结果将是相同的。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.