|
#include<reg51.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit IN1=P2^0;
sbit IN2=P2^1;
sbit IN3=P2^2;
sbit IN4=P2^3;
sbit IN11=P2^4;
sbit IN21=P2^5;
sbit IN31=P2^6;
sbit IN41=P2^7;
sbit beet=P1^3;
sbit TRIG=P1^2;
sbit ECHO=P1^1;
sbit led=P1^4;
sbit p10=P1^0;
sbit lin=P1^2;
sbit hong=P3^3;
sbit LED=P0^0;
uint pwm,push,push1,shu,flag,flagg,butt[5]=0,j,i,num,time,lednum;
/*void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}*/
void init()
{
IN1=0;
IN2=0;
IN3=0;
IN4=0;
IN11=0;
IN21=0;
IN31=0;
IN41=0;
LED=1;
TMOD=0X21;
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
TH1=0xfd;
TL1=0xfd;
TR0=1;
ET0=1;
TR1=1;
REN=1;
SM0=0;
SM1=1;
ES=1;
EA=1;
beet=1;
num=0;
lednum=0;
push=187;
lin=1;
hong=1;
}
void time1() interrupt 1
{
TH0=(65536-100)/256;
TL0=(65536-100)%256;
pwm++;
if(pwm<=push)
p10=1;
else
p10=0;
if(pwm>=200)
pwm=0;
if(led==0)
{
time++;
if(time==1000)
{
time=0;
if(num==0)
beet=1;
if(num==2)
beet=0;
if(num==3)
beet=1;
if(num==5)
beet=0;
num++;
if(num==10)
num=0;
}
}
}
void ser() interrupt 4
{
ES=0;
if(RI==1)
{
RI=0;
shu=SBUF;
if((shu==0x4f)&&(j==0))
{
butt[j]=shu;
flag=1;
}
else if(flag==1)
{
j++;
butt[j]=shu;
if(j>=2)
{
j=0;
flag=0;
flagg=1;
}
}
ES=1;
}
}
void liang()
{
LED=0;
}
void mie()
{
LED=1;
}
void qian()
{
IN1=1;
IN2=0;
IN3=1;
IN4=0;
IN11=1;
IN21=0;
IN31=1;
IN41=0;
}
void hou()
{
IN1=0;
IN2=1;
IN3=0;
IN4=1;
IN11=0;
IN21=1;
IN31=0;
IN41=1;
}
void you()
{
IN1=0;
IN2=1;
IN3=0;
IN4=1;
IN11=1;
IN21=0;
IN31=1;
IN41=0;
}
void zuo()
{
IN1=1;
IN2=0;
IN3=1;
IN4=0;
IN11=0;
IN21=1;
IN31=0;
IN41=1;
}
void ting()
{
IN1=0;
IN2=0;
IN3=0;
IN4=0;
IN11=0;
IN21=0;
IN31=0;
IN41=0;
}
void ling()
{
lin=0;
}
void lig()
{
lin=0;
}
void hf()
{
while(hong!=1)
{
lin=0;
ting();
}
}
void main()
{
init();
hf();
while(1)
{
if(led==1)
{
TR0=0;
ET0=0;
beet=1;
lednum=0;
if(flagg==1)
{
flagg=0;
if((butt[0]==0x4f)&&(butt[1]==0x4e))
{
switch(butt[2])
{
case 0x41:qian();break;
case 0x42:hou();break;
case 0x43:zuo();break;
case 0x44:you();break;
case 0x46:ting();break;
case 0x31:ling();break;
case 0x32:lig();break;
case 0x34:mie();break;
case 0x33:liang();break;
}
}
}
}
/* if(led==0)
{
if(lednum==0)
ting();
else
lednum=0;
lednum++;
//TR0=1;
//ET0=1;
if(flagg==1)
{
flagg=0;
if((butt[0]==0x4f)&&(butt[1]==0x4e))
{
switch(butt[2])
{
case 0x41:qian();break;
case 0x42:hou();break;
case 0x43:zuo();break;
case 0x44:you();break;
case 0x45:ting();break;
}
}
}
}*/
}
}
|
|