用STM8外中断来唤醒停机状态,但只能唤醒一次,为什么????????
#include "iostm8s003f3.h"
#define nop() asm("nop")
#define K1 PD_IDR_IDR4 //按键
#define LED PD_ODR_ODR2 //LED指示,低亮
void delay(unsigned char i)
{
unsigned char j;
j=255;
while(i--)
{
while(j--);
}
}
void main()
{
unsigned char temp;
delay(10);
 D_CR1 |= 0x10; //PD4上拉输入
 D_CR1 |= 0x4; //
 D_DDR |= 0x4; //PD2设置为输出
LED=0;
asm("RIM"); //开总中断
while(1)
{
LED=0;//灯亮;
delay(255);
while (!K1)
{
temp=0;//延时清0
delay(255);
LED=!LED;
}
temp++;
if (temp>20)//按键没按下时,延时再停机
{
temp=0;
 D_CR2 |= 0x10; //开PD4中断
EXTI_CR1 = 0x80; //PD4下降沿中断;
LED=1;//关灯
asm("halt"); //停机
nop();nop();nop();nop();nop();
 D_CR2 = 0x0; //
}
}
}
#pragma vector=0x08//
__interrupt void EXTI_PD()//PD外中断
{
nop();
 D_CR2 = 0x0; //关中断
}
|