📄 red.c
字号:
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
uint th0,tl0;
uint time;
sbit k0=P1^0;
sbit k1=P1^1;
sbit k2=P1^2;
sbit k3=P1^3;
sbit set=P0^0;
void t0_ser() interrupt 1 using 0 //T0 interrupt 发射频率控制器
{TH0=th0;
TL0=tl0;
set=set^1;
}
void t1_ser() interrupt 3 using 1 //T1定时100ms 作为发射时间控制器
{if(time!=1) {time++;
TH1=-50000/256;
TL1=-50000%256;
}
else{TR0=0;
EA=0;
TR1=0;
time=0;
set=1;}
}
main()
{
uint i,j;
TMOD=0x11;
IP=0x08;
ET0=1;
ET1=1;
time=0;
P2=0xff;
P1=0xff;
while(1)
{
if(P1!=0xff){
i=P1^0xff;
i=i&0x0f;
switch(i)
{ case 8: {th0=-500/256; EA=1;
tl0=-500%256;
TH0=-500/256;
TL0=-500%256; //k3 1khz 0.5ms
TH1=-50000/256;
TL1=-50000%256;
TR0=1;TR1=1;
break;
}
case 4: {th0=-1000/256; EA=1;
tl0=-1000%256;
TH0=-1000/256;
TL0=-1000%256; //k2 500hz 1ms
TH1=-50000/256;
TL1=-50000%256;
TR0=1;TR1=1;
break;
}
case 2: { th0=-5000/256; EA=1;
tl0=-5000%256;
TH0=-5000/256;
TL0=-5000%256; //k1 100hz 5ms
TH1=-50000/256;
TL1=-50000%256;
TR0=1;TR1=1;
break;
}
case 1: { th0=-10000/256; EA=1;
tl0=-10000%256;
TH0=-10000/256;
TL0=-10000%256; //k0 50hz 10ms
TH1=-50000/256;
TL1=-50000%256;
TR0=1;TR1=1;
break;
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -