📄 rf51.c
字号:
#include <reg51.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
unsigned long datacap;
uchar count,data_count;
sfr AUXR=0x8e;
sbit rfin=P2^7;
sbit led=P1^0;
void init();
bit sync();
bit getdata();
void main()
{
uchar m,n,t;
init();
while(1)
{
while(sync())
getdata();
if(datacap==0x98008501)
{
led=0;
for(m=255;m>0;m--)
for(n=255;n>0;n--);
led=1;
}
if(datacap==0x98008502)
{
for(t=2;t>0;t--)
{ for(m=255;m>0;m--)
for(n=255;n>0;n--);
for(m=255;m>0;m--)
for(n=255;n>0;n--);
led=0;
for(m=255;m>0;m--)
for(n=255;n>0;n--);
led=1;
}
}
if(datacap==0x98008504)
{
for(t=3;t>0;t--)
{ for(m=255;m>0;m--)
for(n=255;n>0;n--);
for(m=255;m>0;m--)
for(n=255;n>0;n--);
led=0;
for(m=255;m>0;m--)
for(n=255;n>0;n--);
led=1;
}
}
datacap=0x00;
}
}
void init()
{
datacap=0x00;
count=0;
data_count=0;
AUXR=0x01;
P1=0xff;
P3=0xff;
//下面3行用于定义T0 工作于方式1(16位模式)
// TMOD=0x01;
// TH0=(65536-100)/256;
// TL0=(65536-100)%256;
//下面2行用于定义T0 工作于方式2(8位自动装入模式)
TMOD=0x02;
TH0=(65536-100)%256;
TL0=(65536-100)%256;
IE=0x82; //开总中断及时钟0中断
TR0=1; //定时器0计时开始
// IE=0x83; //开总中断及外部0和时钟0中断
// IT0=1; //外部中断0为边沿(下降沿)触发
}
bit sync()
{
count=0;
while(!rfin);
if((count<2)||(count>6))
{
return 0;//出错}
}
count=0;
while(rfin);
if((count<25)||(count>35))
{
return 0;//出错}
}
data_count=0;
datacap=0;
return 1;
}
bit getdata()
{
uchar Hlevel_bit,temp;
temp=0x00;
for(;data_count<32;data_count++)
{
count=0;
while(!rfin);
if((count<2)||(count>12))
return 0;//出错
if(count<6)
Hlevel_bit=0;//判断到0的高电平
else //if(count<13)
Hlevel_bit=1;//判断到1的高电平
count=0;
while(rfin);
if((count<2)||(count>12))
return 0;//出错
if(!Hlevel_bit)
{
if(count>6)
datacap=datacap&0xfffffffe;//得到数据0
}
else
{
if(count<7)
datacap=datacap|0x01;//得到数据1
}
if(data_count<31)
datacap<<=1;
}
return 1;
}
void timer0() interrupt 1
{
// TH0=(65536-100)/256;
// TL0=(65536-100)%256;
count++;
}
/*
void ext0() interrupt 0 using 1
{
// uchar m,n;
EX0=0;
// led=0;
// for(m=255;m>0;m--)
// for(n=255;n>0;n--);
// while(sync())
// getdata();
// led=1;
// for(m=255;m>0;m--)
// for(n=255;n>0;n--);
EX0=1;
} */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -