我正在尝试使用外部中断来闪烁LED的简单任务。我使用的是ATtiny10,所以只有一个中断引脚(PB2)。
//cpu freq set to 1MHz
#undef F_CPU
#define F_CPU 1000000UL
//io is pin/reg macros.. PB0,PORTB,etc..
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
ISR(INT0_vect) // Interrupt Service Routine for logical change on INT0 (PB2)
{
PORTB = 0X0E; //turn PB0 High
_delay_ms(2000);
}
int main(void)
{
// initializations
//DDRB 1-output,0-input
DDRB = 0x0B; // enable PB0,1,3 as outputs..PB2 is INT0 interrupt... 1011 (3,1,0)
DDRB &= ~0x04; //1011 & w/ 1011 (~0x04) keeps bits as we set them
PORTB = 0x04; // H or L for any DDRB output pins, set all Low, 0100 pulls up PB2 resistor since it is an input
EICRA |= 0x01; //any logical change on INT0 generates interrupt
sei(); //enable global interrupts
while(1){
PORTB = 0X0E; //turn PB0 on w/ LOW signal
_delay_ms(500);
PORTB = 0x0F; //turn all off again
_delay_ms(500);
PORTB = 0X0D; //turn PB1 LOW
_delay_ms(500);
PORTB = 0x0F; //turn all off again
_delay_ms(500);
}
}主要问题:我的中断设置不正确吗?我拔出了INT0引脚PB2的内部电阻。我还没来得及打断这件事。如果需要更多的信息,请告诉我。谢谢大家。
发布于 2019-04-11 22:50:58
我的设置中唯一缺少的项目是设置EIMSK (外部中断掩码)寄存器。当设置为'1‘时,外部中断功能将被启用。有趣的挑战,弄清楚那一个!不要跳过数据表的孩子,否则你会导致更多的问题!!
...
EIMSK = 0x01; //enable external interrupts
EICRA |= 0x01;
sei();
...https://stackoverflow.com/questions/55642020
复制相似问题