热释电不行 红外对管或者激光对管吧 两个 可以知道是从哪个方向来的
/*公交车下车计数*********************************/
///////****2013年7月3日23:37:19****************/
#include<reg52.h>
sbit key1=P1^0;
sbit key2=P1^1;
bit ldelay=0;
unsigned int code shuzu[]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99};
/*------------------------------------------------
函数声明
------------------------------------------------*/
//void SendStr(unsigned char *s);
int i=0,j=0,k=0,l;
/*------------------------------------------------
串口初始化
------------------------------------------------*/
void InitUART (void)
{
SCON = 0x50; // SCON: 模式 1, 8-bit UART, 使能接收
TMOD |= 0x20; // TMOD: timer 1, mode 2, 8-bit 重装
TH1 = 0xFD; // TH1: 重装值 9600 波特率 晶振 11.0592MHz
TR1 = 1; // TR1: timer 1 打开
EA = 1; //打开总中断
//ES = 1; //打开串口中断
}
/*------------------------------------------------
主函数
------------------------------------------------*/
void main (void)
{
InitUART();
TMOD &= 0xF0; //定时器0运行在模式0 ,13位计数器
// GATE0=0; C/T0#=0; M1=0; M0=0;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256; //则8192μs中断一次
ET0=1; //允许定时器0中断
EA=1; //允许总中断
TR0=1; //启动定时器0
while (1)
{
if(key1==0)
{
if(key2==0)
{
while(key1==0);
i++;
}
}
if(i>0)
{
if(ldelay==1)
{
ldelay=0;
SBUF = shuzu;
while(!TI);
TI = 0;
i=0;
}
}
else
k=0;
}
}
void it_timer0(void) interrupt 1
{
k=k++;
if(k==3000)
{ k=0;
ldelay=1;
}
} |