biying 发表于 2014-5-13 07:57:59

用CodeWizardAVR编译attiny13A和attiny85,INT0死活不能用

如题,代码只是一个测试INT0的最小程序,请解决过的朋友帮忙给看一下,这是源码

/*****************************************************
This program was produced by the
CodeWizardAVR V2.05.1b Evaluation
Automatic Program Generator
?Copyright 1998-2011 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

Project :
Version :
Date    : 2014-5-8
Author: Freeware, for evaluation and non-commercial use only
Company :
Comments:


Chip type               : ATtiny85
AVR Core Clock frequency: 8.000000 MHz
Memory model            : Small
External RAM size       : 0
Data Stack size         : 128
*****************************************************/

#include <tiny85.h>
#include<delay.h>
// Pin change interrupt service routine
//interrupt void pin_change_isr(void)
interrupt void ext_int0_isr(void)
{
// Place your code here
PORTB&=0xfe;
}

// Declare your global variables here

void main(void)
{
// Declare your local variables here

// Crystal Oscillator division factor: 1
#pragma optsize-
CLKPR=0x80;
CLKPR=0x00;
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif

// Input/Output Ports initialization
// Port B initialization
// Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
// State5=1 State4=1 State3=1 State2=1 State1=1 State0=1
//PORTB=0x3F;
//DDRB=0x3F;
DDRB = 0x3F;             //将所有I/O口均初始化为输出状态
   PORTB = 0x3F;
   DDRB&=0XFD;       //PCINT1设为输入
   PORTB=0X3F;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=0xFF
// OC0A output: Disconnected
// OC0B output: Disconnected
TCCR0A=0x00;
TCCR0B=0x00;
TCNT0=0x00;
OCR0A=0x00;
OCR0B=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=0xFF
// OC1A output: Disconnected
// OC1B output: Disconnected
// Timer1 Overflow Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
PLLCSR=0x00;

TCCR1=0x00;
GTCCR=0x00;
TCNT1=0x00;
OCR1A=0x00;
OCR1B=0x00;
OCR1C=0x00;

// External Interrupt(s) initialization
// INT0: Off
// Interrupt on any change on pins PCINT0-5: On
//GIMSK=0x20;
//MCUCR=0x00;
//PCMSK=0x02;
//GIFR=0x20;
GIMSK=0x40;
MCUCR=0x00;
GIFR=0x40;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;

// Universal Serial Interface initialization
// Mode: Disabled
// Clock source: Register & Counter=no clk.
// USI Counter Overflow Interrupt: Off
USICR=0x00;

// Analog Comparator initialization
// Analog Comparator: Off
ACSR=0x80;
ADCSRB=0x00;
DIDR0=0x00;

// ADC initialization
// ADC disabled
ADCSRA=0x00;

// Global enable interrupts
#asm("sei")

while (1)
      {
      // Place your code here
       #asm("sei")            // 开放全局中断       while(1);
      }
}

biying 发表于 2014-5-16 06:01:22

INT0没有响应,仿真也是如此,有哪位朋友知道原因,请告知一下!

biying 发表于 2014-5-24 00:01:44

本帖最后由 biying 于 2014-5-24 01:16 编辑

根据马老师的指点,我重新新建了工程,修改了程序后,INT0终于有反应了。我发现个现像,当设置为任意电平触发时,快速按下再放开按键,等再次开中断时,依然会再执行中断程序一次,似乎像是有记忆能力一样,也就是说第二次开中断时,会先对比上一次中断时的电平状态。


但是ATTINY85依然不能用INT0

/*****************************************************
This program was produced by the
CodeWizardAVR V2.05.1b Evaluation
Automatic Program Generator
?Copyright 1998-2011 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

Project :
Version :
Date    : 2014-5-23
Author: Freeware, for evaluation and non-commercial use only
Company :
Comments:    PB3和PB4接LED灯,PB1为INT0接按键


Chip type               : ATtiny13A
AVR Core Clock frequency: 9.600000 MHz
Memory model            : Tiny
External RAM size       : 0
Data Stack size         : 16
*****************************************************/

#include <tiny13a.h>
#include<delay.h>
// External Interrupt 0 service routine
interrupt void ext_int0_isr(void)
{
// Place your code here
GIMSK=0x00; //禁用INT0中断,等合适的时候再打开
GIFR=0x40;
PORTB ^= 1<<4;
}

// Declare your global variables here

void main(void)
{
// Declare your local variables here

// Crystal Oscillator division factor: 1
#pragma optsize-
CLKPR=0x80;
CLKPR=0x00;
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif

// Input/Output Ports initialization
// Port B initialization
// Func5=In Func4=Out Func3=Out Func2=Out Func1=In Func0=Out
// State5=P State4=1 State3=1 State2=1 State1=P State0=1
PORTB=0x3F;
DDRB=0x1D;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=0xFF
// OC0A output: Disconnected
// OC0B output: Disconnected
TCCR0A=0x00;
TCCR0B=0x00;
TCNT0=0x00;
OCR0A=0x00;
OCR0B=0x00;

// External Interrupt(s) initialization
// INT0: On
// INT0 Mode: Low level
// Interrupt on any change on pins PCINT0-5: Off
GIMSK=0x40;
MCUCR=0x01;
GIFR=0x40;

// Timer/Counter 0 Interrupt(s) initialization
TIMSK0=0x00;

// Analog Comparator initialization
// Analog Comparator: Off
ACSR=0x80;
ADCSRB=0x00;
DIDR0=0x00;

// ADC initialization
// ADC disabled
ADCSRA=0x00;

// Global enable interrupts
#asm("sei")

while (1)
      {
      // Place your code here
      delay_ms(4000);
      PORTB ^= 1<<3;
      GIMSK=0x40;
      }
}

xinhoujue 发表于 2014-5-27 18:06:32

看下ATtiny85和ATtiny13A的寄存器名字是否一样~~~~~

biying 发表于 2014-5-27 19:01:01

xinhoujue 发表于 2014-5-27 18:06
看下ATtiny85和ATtiny13A的寄存器名字是否一样~~~~~

谢谢提醒,原来TINY13A的INT0是PB1,而TINY85的INT0是PB2,原来看的数据手册是中文的TINY13A,误以为同一系列应该是一样的,就忽略了TINY85的引脚定义,再次感谢你的提醒!
页: [1]
查看完整版本: 用CodeWizardAVR编译attiny13A和attiny85,INT0死活不能用