|
采用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, 杜汶泽)
|