Files
moyuhai 02f1638ef2 V1.0
2026-06-12 09:12:35 +08:00

138 lines
2.7 KiB
C

#ifndef _rf_send_C_
#define _rf_send_C_
/*********************************************************************************************************************/
#include "ca51f5_config.h"
#include "includes\ca51f5sfr.h"
#include "includes\ca51f5xsfr.h"
#include "includes\gpiodef_f5.h"
#include "Library\Includes\delay.h"
#include "rf_send.h"
sbit Pin_rf = P0^7;
unsigned char D0,D1;
unsigned int idata ID;
unsigned char RF_Time; //用于控制RF发送间隔时间
unsigned char Send433_Status = 0; //发送过程的状态
unsigned int Send433_Time = 0; //记录433发送数据的高低电平时间
unsigned char Yaokong_Data[3]={0};
unsigned char Send433_Byte_Cont=0;//记录发送一组433数据的字节数
unsigned char Send433_Bit_Cont = 0; //记录发送位
unsigned char Temp=0;
unsigned char Chose_Data_En=0;//使能选择一组433数据的第N个字节
void Send433_Byte(void) //100us执行一次
{
switch (Send433_Status)
{
case 0: //同步头高
Pin_rf = 1;
if (++Send433_Time >= 4)//高电平400us
{
Send433_Time = 0;
Send433_Status = 1; //进入同步头低
}
break;
case 1://同步头低电平
Pin_rf = 0;
if (++Send433_Time >= 120)//电平12300us
{
Send433_Time = 0;
Send433_Status = 2; //进入发送24位
}
break;
case 2:
if(!Chose_Data_En)//还没开始发送 或者上次已经发送完一个字节才使能选择
{
Chose_Data_En=1;
Temp=Yaokong_Data[Send433_Byte_Cont];
//Send433_Byte_Cont++;
}
Send433_Time++;
if (Temp & 0x80) //1
{
if (Send433_Time <= 12)
{
Pin_rf = 1;
}
else if (Send433_Time >= 13)
{
Pin_rf = 0;
if (Send433_Time == 16)
{
Send433_Time = 0;
Temp <<= 1;
Send433_Bit_Cont++;
}
}
}
else//0
{
if (Send433_Time <= 4)
{
Pin_rf = 1;
}
else if (Send433_Time >= 5)
{
Pin_rf = 0;
if (Send433_Time == 16)
{
Send433_Time = 0;
Temp <<= 1;
Send433_Bit_Cont++;
}
}
}
if (Send433_Bit_Cont == 8)//发送完一字节
{
Send433_Bit_Cont = 0;
Chose_Data_En=0;//使能选择下一个字节
if(++Send433_Byte_Cont==3)
{
Send433_Byte_Cont=0;
if(flagStart == 1)
{
Send433_Status = 3; //结束脉冲
}
else
{
Send433_Status = 0; //一帧数据发送完毕
// if(WheelSliderPosition == -1)
// {
// Send433_Status = 3;
// }
}
}
}
break;
case 3:
if (++Send433_Time <= 4)
{
Pin_rf = 1;
}
else
{
Pin_rf = 0;
Send433_Time = 0;
// flagStart = 0;
Send433_Status = 0;
TR0 = 0; //定时器0禁止
}
break;
default:
break;
}
}
#endif