首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ISR INTO_vect设置

ISR INTO_vect设置
EN

Stack Overflow用户
提问于 2019-04-11 22:25:57
回答 1查看 292关注 0票数 0

我正在尝试使用外部中断来闪烁LED的简单任务。我使用的是ATtiny10,所以只有一个中断引脚(PB2)。

数据表

代码语言:javascript
复制
//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的内部电阻。我还没来得及打断这件事。如果需要更多的信息,请告诉我。谢谢大家。

EN

回答 1

Stack Overflow用户

发布于 2019-04-11 22:50:58

我的设置中唯一缺少的项目是设置EIMSK (外部中断掩码)寄存器。当设置为'1‘时,外部中断功能将被启用。有趣的挑战,弄清楚那一个!不要跳过数据表的孩子,否则你会导致更多的问题!!

代码语言:javascript
复制
...
EIMSK = 0x01; //enable external interrupts 
EICRA |= 0x01;

sei();
...
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55642020

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档