【发布时间】:2014-12-17 15:53:25
【问题描述】:
所以我使用的微型是 PIC 18F。
如果 Alarm_Status.bits.b3 设置为本质上只是一个开关,则会创建警报。第一个 sn-p 代码可以正常工作
BS(TRISB,7); // Bund sw port=input.
DelayMs(2); // will rise is bund SW open
if(RB7){
if(Control.bits.BUND_ENABLE){ // if bund alarm enabled
if(Alarm_Status.bits.b3){ // if already set
DU_Reason.bits.EmergencyDialIn=1; // alarm!
}
}
Alarm_Status.bits.b3=0; // Bund Sw Open
}
else Alarm_Status.bits.b3=1; // Bund Sw Closed
BC(TRISB,7);
但是我只想在开关设置一段时间而不是直接设置开关时报警。该函数每秒调用一次。谁能指出我出错的方向。
int count = 0;
int fixedCount = 20;
BS(TRISB,7); // Bund sw port=input.
DelayMs(2); // will rise is bund SW open
if(RB7){
if(Control.bits.BUND_ENABLE){ // if bund alarm enabled
if(Alarm_Status.bits.b3){ // if already set
count +=10; //count increased by 10
}
if(count == fixedCount) {
DU_Reason.bits.EmergencyDialIn=1;// alarm!
count = 0;
}
}
Alarm_Status.bits.b3=0; // Bund Sw Open
}
else
count = 0;
Alarm_Status.bits.b3=1; // Bund Sw Closed
BC(TRISB,7);
【问题讨论】:
-
count变量应该是全局变量。 -
“Bund”不是英文的吧?似乎是一个重要的词。
-
显示你所知道的外滩是英文 你听说过外滩传感器吗,显然不是。无论如何,感谢亚历克斯宣布它在全球范围内工作得很好,干杯。
-
@Alex Farber 或 NewLook。建议发布答案并接受它以关闭此帖子。
-
C 不是 Python - 缩进无关紧要。第二个块中的最后三行缩进,好像它们应该在
else块中执行,但它们没有括在大括号中({ })。因此,只有count = 0;特定于else案例。其他两行每次都运行。
标签: c counter microcontroller pic