|
发表于 2007-2-25 00:11:21
|
显示全部楼层
……
unsigned long DCounter = DCOUNTER_ZERO;
……
# define MotorDirection (PINB & 0x10)
……
/***********************************************************
* 函数说明:外中断初始化函数 *
* 说明: 使用外中断0和外中断1 下降沿触发 *
***********************************************************/
void ExternIntInit(void)
{
MCUCR = 0x0A;
GICR = 0xC0;
}
/***********************************************************
* 函数说明:外中断0中断处理程序 *
***********************************************************/
void Int0Isr(void)
{
/*
if (MotorDirection)
{
DCounter ++;
}
else if (DCounter)
{
DCounter --;
}*/
asm("push r20")
asm("push r2");
asm("push r3");
asm("push r4");
asm("push r5");
asm("lds R2,_DCounter"); //Load direct from data space
asm("lds R3,_DCounter+1"); //Load direct from data space
asm("lds R4,_DCounter+2"); //Load direct from data space
asm("lds R5,_DCounter+3"); //Load direct from data space
asm("ldi r20,1");
if (MotorDirection)
{
//DCounter ++;
asm("add r2,r20"); //Add without carry
asm("ldi r20,0");
asm("adc r3,r20"); //Add with carry
asm("adc r4,r20"); //Add with carry
asm("adc r5,r20"); //Add with carry
}
else
{
//DCounter --;
asm("sub r2,r20"); //Add without carry
asm("ldi r20,0");
asm("sbc r3,r20"); //Add with carry
asm("sbc r4,r20"); //Add with carry
asm("sbc r5,r20"); //Add with carry
}
asm("sts _DCounter,R2");
asm("sts _DCounter+1,R3");
asm("sts _DCounter+2,R4");
asm("sts _DCounter+3,R5");
asm("pop r5");
asm("pop r4");
asm("pop r3");
asm("pop r2");
asm("pop r20");
} |
|