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; //恢复中断
}