#include<reg52.h>
#include<intrins.h>
//#define GUDING //固定失控值/自由自定
#define u8 unsigned char
#define u16 unsigned int //*******晶振设定*******//
#define u32 unsigned long int //内置 12Mhz 16Mhz 24Mhz//
#define WZ12Mhz 1 // 0 1 0 0 //
#define WZ16Mhz 0 // 0 0 1 0 //
#define WZ24Mhz 0 // 0 0 0 1 //
sfr IAP_DATA=0xc2; //**********************//
sfr IAP_ADDRH=0xc3;
sfr IAP_ADDRL=0xc4;
sfr IAP_CMD=0xc5;
sfr IAP_TRIG=0xc6;
sfr IAP_CONTR=0xc7;
sfr P1M0=0x92;//单片机IO口配置寄存器地址
sfr P3M0=0xb2;
//定义指示灯
sbit LED=P3^0;
sbit bind=P3^7;
//定义8个通道输出
sbit CH1=P1^7;
sbit CH2=P1^6;
sbit CH3=P1^5;
sbit CH4=P1^4;
sbit CH5=P1^3;
sbit CH6=P1^2;
sbit CH7=P1^1;
sbit CH8=P1^0;
//定义无线模块的管脚
sbit GIO=P3^2;
sbit MDI=P3^3;
sbit SCK=P3^4;
sbit CSN=P3^5;
u8 code A7105_regs[]={ //模块寄存器设定表
0xff, 0x42, 0x00, 0x14, 0x00, 0xff, 0xff ,0x00, 0x00, 0x00, 0x00, 0x01, 0x21, 0x05, 0x00, 0x50,
0x9e, 0x4b, 0x00, 0x02, 0x16, 0x2b, 0x12, 0x00, 0x62, 0x80, 0x80, 0x00, 0x0a, 0x32, 0xc3, 0x0f,
0x13, 0xc3, 0x00, 0xff, 0x00, 0x00, 0x3b, 0x00, 0x17, 0x47, 0x80, 0x03, 0x01, 0x45, 0x18, 0x00,
0x01, 0x0f, 0xff,
};
u8 code tx_channels[16][16]={ //跳频表
{0x0a, 0x5a, 0x14, 0x64, 0x1e, 0x6e, 0x28, 0x78, 0x32, 0x82, 0x3c, 0x8c, 0x46, 0x96, 0x50, 0xa0},
{0xa0, 0x50, 0x96, 0x46, 0x8c, 0x3c, 0x82, 0x32, 0x78, 0x28, 0x6e, 0x1e, 0x64, 0x14, 0x5a, 0x0a},
{0x0a, 0x5a, 0x50, 0xa0, 0x14, 0x64, 0x46, 0x96, 0x1e, 0x6e, 0x3c, 0x8c, 0x28, 0x78, 0x32, 0x82},
{0x82, 0x32, 0x78, 0x28, 0x8c, 0x3c, 0x6e, 0x1e, 0x96, 0x46, 0x64, 0x14, 0xa0, 0x50, 0x5a, 0x0a},
{0x28, 0x78, 0x0a, 0x5a, 0x50, 0xa0, 0x14, 0x64, 0x1e, 0x6e, 0x3c, 0x8c, 0x32, 0x82, 0x46, 0x96},
{0x96, 0x46, 0x82, 0x32, 0x8c, 0x3c, 0x6e, 0x1e, 0x64, 0x14, 0xa0, 0x50, 0x5a, 0x0a, 0x78, 0x28},
{0x50, 0xa0, 0x28, 0x78, 0x0a, 0x5a, 0x1e, 0x6e, 0x3c, 0x8c, 0x32, 0x82, 0x46, 0x96, 0x14, 0x64},
{0x64, 0x14, 0x96, 0x46, 0x82, 0x32, 0x8c, 0x3c, 0x6e, 0x1e, 0x5a, 0x0a, 0x78, 0x28, 0xa0, 0x50},
{0x50, 0xa0, 0x46, 0x96, 0x3c, 0x8c, 0x28, 0x78, 0x0a, 0x5a, 0x32, 0x82, 0x1e, 0x6e, 0x14, 0x64},
{0x64, 0x14, 0x6e, 0x1e, 0x82, 0x32, 0x5a, 0x0a, 0x78, 0x28, 0x8c, 0x3c, 0x96, 0x46, 0xa0, 0x50},
{0x46, 0x96, 0x3c, 0x8c, 0x50, 0xa0, 0x28, 0x78, 0x0a, 0x5a, 0x1e, 0x6e, 0x32, 0x82, 0x14, 0x64},
{0x64, 0x14, 0x82, 0x32, 0x6e, 0x1e, 0x5a, 0x0a, 0x78, 0x28, 0xa0, 0x50, 0x8c, 0x3c, 0x96, 0x46},
{0x46, 0x96, 0x0a, 0x5a, 0x3c, 0x8c, 0x14, 0x64, 0x50, 0xa0, 0x28, 0x78, 0x1e, 0x6e, 0x32, 0x82},
{0x82, 0x32, 0x6e, 0x1e, 0x78, 0x28, 0xa0, 0x50, 0x64, 0x14, 0x8c, 0x3c, 0x5a, 0x0a, 0x96, 0x46},
{0x46, 0x96, 0x0a, 0x5a, 0x50, 0xa0, 0x3c, 0x8c, 0x28, 0x78, 0x1e, 0x6e, 0x32, 0x82, 0x14, 0x64},
{0x64, 0x14, 0x82, 0x32, 0x6e, 0x1e, 0x78, 0x28, 0x8c, 0x3c, 0xa0, 0x50, 0x5a, 0x0a, 0x96, 0x46},
};
u32 id; //对码ID
u8 chanrow,chancol,chanoffset,channel;
u8 txid[21]={0,0,0,0,0,220,5,220,5,232,3,220,5,220,5,220,5,220,5,220,5};
u8 packet[21];
u8 Htemp[8]={5,5,3,5,5,5,5,5};
u8 Ltemp[8]={220,220,232,220,220,220,220,220};
u8 ch=0;
u16 mss;
bit hch,cb;
#if WZ12Mhz //延时定义
void Delay1ms(){ //@12.000MHz
unsigned char i, j;
_nop_();
_nop_();
i = 10;
j = 83;
do
{
while (--j);
} while (--i);
}
#elif WZ16Mhz
void Delay1ms(){ //@18.432MHz
unsigned char i, j;
_nop_();
_nop_();
i = 18;
j = 234;
do{
while (--j);
} while (--i);
}
#elif WZ24Mhz
void Delay1ms(){ //@24.000MHz
unsigned char i, j;
_nop_();
_nop_();
i = 24;
j = 84;
do{
while (--j);
} while (--i);
}
#else
void Delay1ms() { //@5.5296MHz
unsigned char i, j;
_nop_();
_nop_();
i = 6;
j = 93;
do{
while (--j);
} while (--i);
}
#endif
附件为完整代码
flysky.rar
(3.79 KB, 下载次数: 146)
|