【发布时间】:2015-10-09 15:58:10
【问题描述】:
我遇到了与此代码相同的情况,它解决了我的问题(此代码在不使用延迟功能的情况下使 LED 闪烁,该功能会阻止执行,直到经过设定的时间)
我的问题是 pic 微控制器中是否有与此功能等效的功能?
const int ledPin = 13;
int ledState = LOW;
unsigned long previousMillis = 0; // will store last time LED was updated
const long interval = 1000; // interval at which to blink (milliseconds)
void setup()
{
pinMode(ledPin, OUTPUT);
}
void loop()
{
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval)
{
previousMillis = currentMillis; // save the last time you blinked the LED
// if the LED is off turn it on and vice-versa:
if (ledState == LOW)
{
ledState = HIGH;
}
else
{
ledState = LOW;
}
// set the LED with the ledState of the variable:
digitalWrite(ledPin, ledState);
}
}
我的问题是 xc8 编译器中是否有一个函数或 lib 可以完成与 millis() 函数相同的工作?
谢谢你。
【问题讨论】:
-
不,没有内置任何东西。我经常做的是配置一个 1ms 的定时器中断,我可以在那里跟踪经过的时间。
-
你能给我更多的细节吗,我可以用你说的这个方法,配置一个 1ms 的定时器中断或者如果可能的话给我那个代码,谢谢
-
您使用哪种编译器来编码 PIC?
标签: arduino microcontroller pic