通过51仿真器能不能看出红外遥控器的脉冲宽度?我的意思是用2个中断测正脉冲宽度,在程序里定义一个数组,把每个脉冲的时间存入数组,这样有问题吗?我在Keil里看数组,结果都是有2个间隔是0,难道脉冲很短测不出吗?
#include<d:keilC51INCmath.h> #include<d:keilC51INCabsacc.h> #include<d:KeilC51INCintrins.h> #include<d:KeilC51INCstring.h> #include<d:KeilC51INCstdio.h> #include <reg52.h>
#define uint unsigned int #define uchar unsigned char #define ulong unsigned long
#define code0_min 700 #define code0_max 500
#define code1_min 1400 #define code1_max 1900
uchar idata m_ncounter;//接受的一桢数据位数 uint idata m_wcode;//接收下来的数据 uint idata m_wircode;
uint xdata wcountervalue[100] ; sbit BEEP = P1^0; uint data flag;
#if 0 void delay_100us(void) { uchar i=48; while(--i); } #endif
//初始化 void MCU_Init() { EA = 1; TMOD = 0x11; ET0 = 0; ET1 = 0; TH0 = 0; TL0 = 0; TR0 = 0; EX0 = 1; EX1 = 0; IT0 = 1; //下降沿触发中断 IT0 = 1;
m_wcode = 0; // P1 = 0; // TH1 = 0x4C; //TL1 = 0x00; //TR1 = 1; BEEP = 1; }
void IR_int0() interrupt 0 //外部中断(脉冲后沿) { EX0 = 0; TR0 = 1; EX1 = 1; EX0 = 1;
}
void IR_int1() interrupt 2 //外部中断(脉冲后沿) { EX1 = 0; TR0 = 0; flag++; wcountervalue[flag] = TH0; wcountervalue[flag]=(wcountervalue[flag] <<8); wcountervalue[flag]=wcountervalue[flag] + TL0; TH0 = 0; TL0 = 0; if(flag == 40) { BEEP = 0; } EX1 = 1; }
void main() { MCU_Init(); while(1) { ; } } |