[AVR单片机] 无法进入外部中断

[复制链接]
3875|6
 楼主| laichang 发表于 2010-4-23 12:50 | 显示全部楼层 |阅读模式
我在使用MEGA168开发一个项目,需要用到外部中断,但是在测试外部中断(下降沿中断)程序时发现一个问题
   当选用1MHz(内部RC)时,可以产生中断,当选用8MHz(内部RC)时,无法进入外部中断,但是在8MHz时,低电平中断是正常的
   编译器用的是ICCAVR7
   1MHz和8MHz是通过FUSES的CKDIV8设置的
//ICC-AVR application builder : 2010-4-23 9:21:58
// Target : m168
// Crystal: 8.0000Mhz
#include <iom168v.h>
#include <macros.h>
char YY=0;
void port_init(void)
{
PORTB = 0x00;
DDRB  = 0x80;
PORTC = 0x00; //m103 output only
DDRC  = 0x00;
PORTD = 0x08;
DDRD  = 0x00;
}
#pragma interrupt_handler int1_isr:iv_INT1
void int1_isr(void)
{
   if(YY==0)
    {
     PORTB |= 0x80;
     YY=1;
    }
    else
     {
      PORTB &= 0x7f;
      YY=0;
     }
//   EIFR|=2;
//external interupt on INT1
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
MCUCR = 0x00;
EICRA = 0x08; //extended ext ints
EIMSK = 0x02;

TIMSK0 = 0x00; //timer 0 interrupt sources
TIMSK1 = 0x00; //timer 1 interrupt sources
TIMSK2 = 0x00; //timer 2 interrupt sources

PCMSK0 = 0x00; //pin change mask 0
PCMSK1 = 0x00; //pin change mask 1
PCMSK2 = 0x00; //pin change mask 2
PCICR = 0x00; //pin change enable
PRR = 0x00; //power controller
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
//
void main(void)
{
init_devices();
PORTB |= 0x80;
while(1)
{
}
//insert your functional code here...
}
laslison 发表于 2010-4-23 22:24 | 显示全部楼层
在8MHz时,低电平中断是正常的,那怎么就无法进入外部中断?
ershisi 发表于 2010-4-24 22:44 | 显示全部楼层
怎么个回事
易达口香糖 发表于 2010-4-24 22:49 | 显示全部楼层
没发现什么问题
epsmc 发表于 2010-4-27 12:23 | 显示全部楼层
PCMSK0 = 0x00; //pin change mask 0
PCMSK1 = 0x00; //pin change mask 1
PCMSK2 = 0x00; //pin change mask 2
怎么全屏蔽啦,放开对应管脚,用电平变化中断可以试试呢?
xiaoxin1986 发表于 2010-4-27 13:33 | 显示全部楼层
不懂,帮顶一个
a43770 发表于 2013-6-19 17:36 | 显示全部楼层
当INT0 或INT1 中断使能且设定为电平触发时,只要引脚电平被拉低,中断就会产生。若要求INT0 或INT1 在信号下降沿或上升沿触发中断,则I/O 时钟必须工作。会不会是这个原因
您需要登录后才可以回帖 登录 | 注册

本版积分规则

15

主题

18

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部