完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
嗨,那里。根据XC8手册:在这个上下文中需要一个表达式,它可以在编译时被计算为常数,例如:这里是我的代码:看起来case标签不能是函数传递的变量,有什么方法来实现这个代码吗?还是只有我能重新实施?
以上来自于百度翻译 以下为原文 Hi, there. As per XC8 manual: In this context an expression is required that can be evaluated to a constant at compile time, for example: int a; switch(input) { case a: /* oops! cannot use variable as part of a case label */ input++; } Here is my code: void LED1FlashCtrl(uint8_t startingPoint, uint16_t interval){ static uint16_t i; switch(i){ case startingPoint: LED1 ^= 1; i++; break; case (startingPoint+interval): LED1 ^= 1; i++; break; case (interval+interval): i = startingPoint; break; default: i++; break; } } It seems that case label can't be the variable which is passed by function, is there any method to implement this code? or only I can re-implement it? |
|
相关推荐
2个回答
|
|
|
|
|
|
|
|
|
HI,而不是Switter…,您可以使用:If(),否则If()构造:如果您想检测每个间隔的精确开始和结束,可能有更多的条件,但是如果函数调用参数在调用之间改变?迈西尔
以上来自于百度翻译 以下为原文 Hi, Instead of switch..., you may use: if(), else if() construct for this: ... if ( i < startingPoint) // Too early? { ...} else if ( i < startingPoint + interval) // First interval. { i++; LED1 = 1; } else if ( i < startingPoint + interval + interval) // Second interval { i++; LED1 = 0; } else // Next period { i = startingPoint; } There may be more conditions if you want to detect exact start and end of each interval, but if function call arguments change between calls? Mysil |
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
454 浏览 0 评论
5793 浏览 9 评论
2334 浏览 8 评论
2224 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3529 浏览 3 评论
1121浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1094浏览 1评论
我是Microchip 的代理商,有PIC16F1829T-I/SS 技术问题可以咨询我,微信:A-chip-Ti
872浏览 1评论
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
460浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-1 16:23 , Processed in 1.228654 second(s), Total 74, Slave 57 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
1753