RF433发射程序

RF433发射程序
#define OUTHIGH() (PORTC|=DATA) //设置发射引脚
#define OUTLOW() (PORTC&=(~DATA)) //设置发射引脚

void TxAskByte(BYTE len,BYTE data)
{
BYTE i;
BYTE ch_sebd_datas=data;
for(i=0;i<len;i++)
{
if((ch_sebd_datas&0x01)==0x01)
{
OUTLOW();
Delay(124);//800us
OUTHIGH();
Delay(62); //400us
}
else
{
OUTLOW();
Delay(62); //400us
OUTHIGH();
Delay(124);//800us
}
ch_sebd_datas=ch_sebd_datas>>1;
}
}

u8 wireless_tx_test(u8 temp_data)
{
u8 x;
u8 y;
x = (u8)(TX_Buf[0] ^ TX_Buf[1]);
x = (u8)(x ^ TX_Buf[2]);
x = (u8)(x ^ temp_data);
y = (u8)x ;
y >>= (u8)4 ;
x = (u8)(y ^ x);
return(u8)(x &= 0x0f);
}
/**************************************
**名字:TX_Mode
**功能:进入发射
**入参:
**出参:无
***************************************/

void TX_Mode(BYTE data)
{
BYTE i;
u8 ch_datas=0; //,TX_Buf[3];
BYTE CheckCrc=0;
Get_ID();
GIE = 0; //关中断
for(i=0;i<3;i++)
{
/* while(1)
{
LED_H() ;
Delay(155);//1ms
Delay(62); //400us 1.4 4 400 800
LED_L() ;
Delay(622); //DELAY_4MS
LED_H() ;
Delay(62); //400us
LED_L() ;
Delay(124);//800us
}
*/
CLRWDT();
OUTHIGH();
Delay(155);//1ms
Delay(62); //400us
OUTLOW();
Delay(622); //DELAY_4MS
OUTHIGH();
Delay(62); //400us

	ch_datas=TX_Buf[0];	 //源地址0
	CheckCrc=CheckCrc^ch_datas;
	TxAskByte(8,ch_datas);
	ch_datas=TX_Buf[1];	//源地址1
	CheckCrc=CheckCrc^ch_datas;
	TxAskByte(8,ch_datas);

	ch_datas=TX_Buf[2];	//源地址2
	CheckCrc=CheckCrc^ch_datas;
	TxAskByte(8,ch_datas);
	ch_datas=data;		//发送数据
	CheckCrc=CheckCrc^ch_datas;
	TxAskByte(8,ch_datas);
	
	ch_datas=wireless_tx_test(data);
	TxAskByte(8,ch_datas);
    
    OUTLOW();
    Delay(155);//1ms
    Delay(62); //400us
}
OUTLOW();
GIE = 1;		//恢复中断

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
很抱歉,由于您的问题涉及到特定的技术和编程语言,我需要使用英文回答您的问题以确保准确性和清晰度。 To answer your question, here's an example program for receiving RF433 signals using C51: ``` #include <REG51.H> // Include header file for C51 #define uchar unsigned char #define uint unsigned int sbit RF_IN = P3^2; // Define RF input pin void init_UART() { TMOD |= 0x20; // Timer 1, mode 2: 8-bit auto-reload TH1 = 0xFD; // Set baud rate to 9600bps SCON = 0x50; // Enable serial port, 8-bit data TR1 = 1; // Start timer 1 } void main() { uchar code[] = {0x55, 0xAA, 0x5A}; // Define code to match uchar data; // Variable to store received data init_UART(); // Initialize UART for serial communication while (1) { if (RF_IN == 0) { // Wait for RF signal to start uint i, j; for (j=0; j<8; j++) { // Wait for first bit while (RF_IN == 0); // Wait for high signal while (RF_IN == 1); // Wait for low signal } for (i=0; i<24; i++) { // Loop through each bit while (RF_IN == 0); // Wait for high signal while (RF_IN == 1); // Wait for low signal data <<= 1; // Shift data left by one bit if (RF_IN == 0) // If signal is high data |= 0x01; // Set last bit to 1 } for (j=0; j<8; j++) { // Wait for last bit while (RF_IN == 0); // Wait for high signal while (RF_IN == 1); // Wait for low signal } if (data == code[0] && (data >> 8) == code[1] && (data >> 16) == code[2]) { // If received data matches code SBUF = data; // Send data through UART while (!TI); // Wait for transmission to complete TI = 0; // Reset transmission flag } } } } ``` This program initializes the UART module for serial communication and defines the code to match for receiving RF signals. It then enters an infinite loop where it waits for an RF signal to start. Once a signal is detected, it reads the data bit by bit and compares it to the code. If the received data matches the code, it sends the data through UART for further processing. Please note that this example program is for demonstration purposes only and may need to be adapted for your specific use case. Additionally, it assumes that you have the necessary hardware and libraries installed for working with the C51 and RF433 modules.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值