#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit wei=P2^4;
sbit wei1=P2^5;
sbit beep=P2^0;
sbit sensor=P0^7;
sbit sensor1=P0^6;
uchar flag1;
uchar flag;
void chuankou(uchar temp)
{
uchar table1[]={1,2};
uchar m;
PCON=0x00;
SCON=0x50;
TMOD=0x20;
TH1=0xE6;
TL1=0xE6;
TR1=1;
for(m=0;m<2;m++)
{
SBUF=table1[temp];
while(TI==0);
TI=0;
}
}
void delay(uint t)
{
while(t--);
}
void Test_Voltage(void)
{
if(sensor==0&sensor1==1)
{
delay(10000);
if(sensor == 0)
{
flag1 = 1;
}
else
{
flag1 == 0;
}
}
else
{
flag1 == 0;
}
}
void action(void)
{
if(flag1 == 1)
{
wei=0xfe;
P0 = 0x25;
beep = 0;
chuankou(1);
delay(10000);
beep = 1;
delay(10000);
wei=0xfd;
}
else
{
wei=0;
P0 = 0x03;
}
}
void Test_Voltage1(void)
{
if(sensor1==0&sensor==1)
{
delay(10000);
if(sensor1==0)
{
flag = 1;
}
else
{
flag = 0;
}
}
else
{
flag = 0;
}
}
void action1(void)
{
if(flag == 1)
{
wei=0xfe;
P0 = 0x9f;
beep = 0;
chuankou(0);
delay(10000);
beep = 1;
delay(10000);
wei=0xfd;
}
else
{
wei=0;
P0 = 0x03;
}
}
void main(void)
{
while(1)
{
Test_Voltage();
action();
Test_Voltage1();
action1();
}
}
红外感应.C(44): warning C275: expression with possibly no effect
|