想用外部中断下降沿检测一个光强变化,结果现在写的程序触发一次下降沿进两次中断,求高手帮忙看一下为什么?红色我是认为可能出错的地方
初始化程序:
#include <stc12c5a60s2.h>
#include<lcd1602_zixie.h>
#define uchar unsigned char
#define uint unsigned int
const int BOCHANG=560;
const float LONG;
const double E=5215.1261 ;
float ZHESHELV=1.35,YAQIANG=12.03;
sbit key1 = P1^0;
sbit key2 = P1^1;
sbit key3 = P3^7;
unsigned char num=0;
uchar time_num=0;
void delay_ms(uint time) //延时函数延时time毫秒
{
uint i,j;
for(i = 0;i < time;i ++)
for(j = 0;j < 930;j ++);
}
void main()
{
Init();//液晶初始化
EA=1;
IT0=0;
ET0=1;
TMOD=0X01;//定时器0以方式1计数
TL0=0XB0;
TH0=0X3C;
while(1)
{
if(key1==0)
{
delay_ms(5);
write_com(0X01); //清屏
num=0;
write_string("Start count num",0x80);
EX0=1;
}
/* if(key2==0)
{
write_com(0X01); //清屏
delay_ms(5);
EX0=0;
write_string("Result of num",0x80);
if((num%2)==1)
num=(num+1)/2;
else
num=num/2;
write_num(num,0xc0);
} */
if(key3==0) //复位键
{
write_com(0X01); //清屏
EX0=0;
num=0;
time_num=0;
}
}
}
void time0() interrupt 1
{
TR0=0;
TL0=0XB0;
TH0=0X3C;
if(time_num<20)
{
time_num++;
TR0=1;
}
else
{
time_num=0;
EX0=1;//开外部中断0
TR0=0;
// num--;
}
}
void exint0() interrupt 0
{
EX0=0;
num++;
write_num(num,0xc0);
TR0=1;//开定时器0
} |