打印
[AVR单片机]

外部中断为何引起复位

[复制链接]
2208|8
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
康鹏鹏|  楼主 | 2015-5-6 13:38 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
//ICC-AVR application builder : 2015/5/5 23:40:48
// Target : T13
// Crystal: 9.6000Mhz

#include <iot13v.h>
#include <macros.h>
#define Led_on PORTB&=0xfe
#define Led_off PORTB|=0x01
#define key1 (PINB&0x08)
#define key2 (PINB&0x10)
#define Light (PINB&0x04)
#define uchar unsigned char
#define uint unsigned int
#define Mode_one_on 50   
#define Mode_one_off 50
#define Mode_two_on 10
#define Mode_two_off 80
#define DJ 1000
uint time=0;
uchar mode=1;
uchar time_on;
uchar time_off;
static uchar shanshuo_time;
void Sleep(void)
{
Led_off;
GIMSK |= 0X60; //外部中断0使能
SEI();
MCUCR|=0x30;    //掉电模式
asm("sleep");
}
/*************************************LED灯控制********************************/
void LED(void)
{
if(mode==1)
{
  if(shanshuo_time<Mode_one_on)Led_on;
  if((shanshuo_time>Mode_one_on)&&(shanshuo_time<(Mode_one_on+Mode_one_off)));Led_off;
  if(shanshuo_time>=(Mode_one_on+Mode_one_off))
  {
   shanshuo_time=0;
  }
}
if(mode==2&&Light!=0)
{
  if(shanshuo_time<Mode_two_on)Led_on;
  if((shanshuo_time>Mode_two_on)&&(shanshuo_time<(Mode_two_on+Mode_two_off)))Led_off;
  if(shanshuo_time>=(Mode_two_on+Mode_two_off))
  {
   Led_off;
   shanshuo_time=0;
  }
}
if(mode==3)Sleep();
}
/*****************按键检查******************************/
uchar Keyscan(void)
{
uchar key_mode;
if(key1==0)key_mode=1;

if(key2==0)key_mode=2;
if(key1!=0&&key2!=0)key_mode=3;
return key_mode;

}
void port_init(void)
{
PORTB = 0x3F;
DDRB  = 0x01;
}

//TIMER0 initialize - prescale:1024
// WGM: Normal
// desired value: 10mSec
// actual value:  9.920mSec (0.8%)
void timer0_init(void)
{
TCCR0B = 0x00; //stop
OCR0A = 0x5D;
OCR0B = 0x5D;
TCNT0 = 0xA3; //set count
TCCR0A = 0x00;
TCCR0B = 0x05; //start timer
}

#pragma interrupt_handler timer0_ovf_isr:iv_TIM0_OVF
void timer0_ovf_isr(void)
{
TCNT0 = 0xA3; //reload counter value
time++;
shanshuo_time++;
if(time>=DJ)Sleep();
}

#pragma interrupt_handler int0_isr:iv_INT0
void int0_isr(void)
{
//external interupt on INT0
time=0;
}

//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
timer0_init();

MCUCR = 0x01;
PCMSK=0X02;
TIMSK0 = 0x02; //timer interrupt sources
GIMSK = 0x60; //interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
void main(void)
{
init_devices();
while(1)
{
  mode=Keyscan();
  
  LED();
}
}

为何我的外部中断,会引起复位呢?实在搞不懂

相关帖子

沙发
JY-DX-JY| | 2015-5-6 16:05 | 只看该作者
干扰。

使用特权

评论回复
板凳
csust_omega| | 2015-5-6 17:34 | 只看该作者
楼主如何确定是由外部中断引起的?查过电源,查过复位引脚了么

使用特权

评论回复
地板
康鹏鹏|  楼主 | 2015-5-6 19:34 | 只看该作者
csust_omega 发表于 2015-5-6 17:34
楼主如何确定是由外部中断引起的?查过电源,查过复位引脚了么

你好  我接线是没有接复位脚的,已经检查清楚。

使用特权

评论回复
5
康鹏鹏|  楼主 | 2015-5-6 19:35 | 只看该作者

你好,请问是什么干扰呢,

使用特权

评论回复
6
JY-DX-JY| | 2015-5-6 19:36 | 只看该作者
我只能想到这个。

使用特权

评论回复
7
康鹏鹏|  楼主 | 2015-5-6 20:06 | 只看该作者
JY-DX-JY 发表于 2015-5-6 19:36
我只能想到这个。

谢谢,主要是低电平触发不会复位,但是引脚电平变化触发就进入复位了

使用特权

评论回复
8
hyhmh| | 2015-5-7 08:58 | 只看该作者
外部中断触发运行的代码死锁?若开了WDT,则会复位。
另一外可能是:外部中断的“信号”已经超出了板上MCU的承受力(与电路、板子设计都有关),引起MCU复位。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

4

帖子

0

粉丝