多次调用函数(Calling a function more than once)

编程入门 行业动态 更新时间:2024-10-22 13:33:48
多次调用函数(Calling a function more than once)

所以我正在使用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..

更多推荐

本文发布于:2023-08-01 19:11:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1363745.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   Calling   function

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!