所以我正在使用CCS编译器编程PIC。 我正在使用定时器中断,这个中断调用了一个名为chronometer的函数,我写了两次。 这是怎么回事
void timer2_isr() { j++; l++; z++; if (j==1) { timero=1; btndly=1; j=0; } user1= chronometer(x, l); user2= chronometer(pad.deger, z); }此函数返回一个结构,并将2个整数作为参数。 当我只调用一次函数时它工作正常。 但是,当在这种情况下,我调用该函数两次时,user2等于user1是什么,代码甚至无法正常工作。 知道为什么吗?
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; }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; }最满意答案
看来你开始使用时间结构而不重置它的成员,导致意外的结果..即使它以某种方式初始化..它没有引用输入参数,所以显然结果将是相同的..
It seems you are starting to use the time struct without resetting it's members, resulting in unexpected results.. And even if it is somehow initialized.. it does not refer to the input parameters, so obviously the result will be the same..
更多推荐
发布评论