搜索
bottom↓
回复: 0

tiny13a int0中断问题

[复制链接]

出0入0汤圆

发表于 2012-11-19 13:02:13 | 显示全部楼层 |阅读模式
采用INT0上升沿中断,程序用ISSI仿真没有问题,烧写到芯片里就会上升和下降沿都会触发中断,进入中断程序,请帮忙分析一下是哪个地方有问题
#include <tiny13a.h>

#include <delay.h>

// External Interrupt 0 service routine
interrupt [EXT_INT0] void ext_int0_isr(void)
{
// Place your code here
unsigned char a;  
PORTB.0=1;
PORTB.2=1;
if(!PINB.4)
{
delay_ms(2000);
}
else
{
delay_ms(100);
}

ADMUX=0x23;
delay_us(10);           // Delay needed for the stabilization of the ADC input voltage   
ADCSRA|=0x40;            // Start the AD conversion      
while ((ADCSRA & 0x10)==0);       // Wait for the AD conversion to complete
ADCSRA|=0x10;                                 
a=ADCH;
PORTB.0=0;
if(a<30)          // 1/1000
    {  
    delay_ms(1);
    }
else if(a<50)            // 1/500
    {     
    delay_ms(2);
    }
else if(a<68)           // 1/250
    {   
    delay_ms(4);   
    }

else if(a<88)       // 1/125
    {  
    delay_ms(8);   
    }

else if(a<108)          // 1/64
    {   
    delay_ms(16);
    }     
else if(a<127)          // 1/32
    {
    delay_ms(32);            
    }

else if(a<147)          // 1/16
    {
    delay_ms(64);         
    }

else if(a<167)          // 1/8
    {
    delay_ms(125);        
    }

else if(a<186)          // 1/4
    {   
    delay_ms(250);     
    }

else if(a<206)          // 1/2
    {
    delay_ms(500);   
    }

else if(a<225)          // 1S
    {  
    delay_ms(1000);     
    }
else                // 2S
    {
    delay_ms(2000);     
    }        
PORTB.2=0;
GIFR|=0b01000000;
}




// Declare your global variables here

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


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

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

// 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: Rising Edge
// Interrupt on any change on pins PCINT0-5: Off
GIMSK=0x40;
MCUCR=0x03;
GIFR=0x40;
PCMSK=0x00;

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

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

// ADC initialization
// ADC Clock frequency: 600.000 kHz
// ADC Bandgap Voltage Reference: Off
// ADC Auto Trigger Source: ADC Stopped
// Only the 8 most significant bits of
// the AD conversion result are used
// Digital input buffers on ADC0: On, ADC1: On, ADC2: On, ADC3: On
DIDR0&=0x03;
DIDR0|=0x00;
//ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x81;

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

PORTB.0=1;
PORTB.2=1;

while (1)
      {
      // Place your code here
      }

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

阿莫论坛20周年了!感谢大家的支持与爱护!!

知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-7-24 07:15

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表