#define F_CPU 16000000UL // 16 MHz #include <stdio.h> #include<avr/io.h> #include<avr/interrupt.h> #include <util/delay.h> unsigned char time_us=0x00; unsigned char i=0; unsigned char u=0;
//volatile int main() {
DDRA=0x00; PORTA=0x00; DDRB=0xFF; PORTB=0x00; DDRC=0x00; PORTC=0x00; DDRD=0x00; PORTD=0xFF; MCUCR=0x02; //上升沿觸發(fā) GICR=0x40;//in0使能 SREG=0x80; while(1) {
u=0x01;}}
ISR(INT0_vect) { _delay_us(u);PORTB=(0xFF);}
求助:中斷程序里 _delay_us(u); 的變量u 會(huì)使 我的中斷程序執(zhí)行件變長(zhǎng)。 請(qǐng)高手指點(diǎn) 我的目的是希望PORTB在中斷觸發(fā)2uS左右動(dòng)作,并且希望時(shí)間可調(diào)。
例如 我若 使用 _delay_us(2) 執(zhí)行兩微秒 是正常的;使用 _delay_us(u);時(shí) 執(zhí)行時(shí)間會(huì)變成 60多微秒。 |