【发布时间】:2016-04-12 06:24:45
【问题描述】:
我正在尝试使用中断来切换与 Arduino Uno 的引脚。这是我目前所拥有的:
const int outputPin = 12;
void setup() {
pinMode(outputPin, OUTPUT);
// initialize Timer0
noInterrupts(); // disable all interrupts
TCCR0A = 0;
TCCR0B = 0;
TCNT0 = 0;
OCR0A = 255;
TCCR0B |= (1 << WGM12); // CTC mode
TCCR0B |= (1 << CS12);
TCCR0B |= (1 << CS10); // 1024 prescaler
TIMSK0 |= (1 << OCIE1A); // enable timer compare interrupt
interrupts(); // enable all interrupts
}
ISR(TIMER0_COMPA_vect){
digitalWrite(outputPin,digitalRead(outputPin)^1); //Toggle pin
}
我正在使用示波器读取引脚上的电压,当我更改 OCR0A 的值时,没有任何变化。我不确定为什么什么都没有改变。我还想补充一点,没有错误。
感谢您的帮助!
【问题讨论】:
标签: arduino arduino-uno