萝丽-三代控及接收机源代码
立即下载
资源介绍:
简单易用
#include //Large编译,否则xdata异常
#include
#include //显示需要的图形数据
#define u8 unsigned char
#define u16 unsigned int
#include
/*****************************************************/
//STC12 系列新增寄存器
sfr IPH=0xb7;
sfr P4=0xc0;
sfr P4SW=0xbb;
sfr P1ASF=0x9d;
sfr P4M0=0xb4;
sfr P3M0=0xb2;
sfr P3M1=0xb1;
sfr P2M0=0x96;
sfr P0M0=0x94;
sfr ADC_CONTR=0xbc;
sfr ADC_RES=0xbd;
sfr ADC_RESL=0xbe;
sfr BRT=0x9c;
sfr AUXR=0x8e;
sfr WAKE_CLKO=0x8f;
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 CCON = 0xD8; //PCA control register
sbit CCF0 = CCON^0; //PCA module-0 interrupt flag
sbit CCF1 = CCON^1; //PCA module-1 interrupt flag
sbit CR = CCON^6; //PCA timer run control bit
sfr CMOD = 0xD9; //PCA mode register
sfr CL = 0xE9; //PCA base timer LOW
sfr CH = 0xF9; //PCA base timer HIGH
sfr CCAPM0 = 0xDA; //PCA module-0 mode register
sfr CCAP0L = 0xEA; //PCA module-0 capture register LOW
sfr CCAP0H = 0xFA; //PCA module-0 capture register HIGH
sfr CCAPM1 = 0xDB; //PCA module-1 mode registers
sfr CCAP1L = 0xEB; //PCA module-1 capture register LOW
sfr CCAP1H = 0xFB; //PCA module-1 capture register HIGH
/*************************************************/
//LCD引脚定义
sbit CS=P0^6;
sbit RST=P0^7;
sbit RS=P4^6;
sbit SDA=P4^5;
sbit CLK=P4^4;
sbit LEDA=P2^5;
/**************************************************/
//NRF24L01 引脚定义
sbit CE=P0^0;
sbit SCK=P0^1;
sbit MDO=P0^2;
sbit IRQ=P0^3;
sbit MDI=P0^4;
sbit CSN=P0^5;
/*************************************************/
//I/O定义
sbit buzzer=P3^4;
sbit PPM=P3^3;
sbit KEY=P4^7;
sbit K1=P3^0;
sbit K2=P3^1;
sbit K3=P3^7;
sbit K4=P3^6;
sbit K5=P3^2;
sbit K6=P3^5;
sbit SA=P2^0;
sbit SB1=P2^1;
sbit SB2=P2^2;
sbit SC1=P2^3;
sbit SC2=P2^4;
sbit SD=P2^6;
sbit SE=P2^7;
/***********************************************/
//数据、标志位
u8 bdata DATA;
sbit D_7=DATA^7;
sbit D_6=DATA^6;
sbit D_5=DATA^5;
sbit D_4=DATA^4;
sbit D_3=DATA^3;
sbit D_2=DATA^2;
sbit D_1=DATA^1;
sbit D_0=DATA^0;
//ROM存储
#define Model_length 117 //模型数据 长度 宏定义
#define Version 0xAC //系统版本 A13
u8 Model_number=0,Model_current=0,Model_addrH=2;
bit Model_change,Model_reset,reset_action;
u8 TEMP_DATA[351];
bit ROM_enable;
bit Data_system,Data_model;
bit save_action;
bit calibration_action,calibration_ok;
//显示
u8 word[10];
u8 WW[11][6];
bit LCD_big;
bit LCD_light=1;
bit LCD_reverse;
u8 LCD_vop=42;
u8 boot_screen=0;
bit boot_screen_en=1;
//时钟
bit event1,event2,event3;
u8 t1=0,t2=0,t3=0;
bit flag_20ms;
u8 Master_clock,second=0,minute=0,hour=0;
u8 clock2,second2=0,minute2=0;
u8 clock_set=5,clock_switch=0;
bit clock_go;
u16 throttle_idle=0;
u8 delay_time=0;
u8 flash_time=0;
//蜂鸣器
bit Message_AlarmClock,Message_LowPower;
u8 Message_KeyTone=0,Message_DataReturn_bad=0;
u8 beep=0,sound=0;
bit Sound_enable=1;
//菜单模式
bit PPM_OUT,PPM_IN,RC_TX,IR_TX,RC_check;
bit config_change,star=1,RC_check_star;
u8 menu=0,menu_1=0,menu_2=0,menu_3=0;
u8 line=0,line_1=0,line_2=0,line_3=0;
u8 last_line=0;
//按键
bit KS,KS_long_press;
u8 KS_press_time;
bit key1,key2,key3,key4,key5,key6;
bit s1,s2,s3,s4,s5,s6;
bit s1_long_press,s2_long_press,s3_long_press,s4_long_press,s5_long_press,s6_long_press;
u8 s1_press_time,s2_press_time,s3_press_time,s4_press_time,s5_press_time,s6_press_time;
bit key_time;
bit increase,decrease,up,down,left,right;
//ADC
u16 data adc[8],adc_buff[8];
u8 t_adc=0;
u8 Battery_1s=1,VLD1=35,VLD2=70;
u16 battery_voltage;
char v_trim1=0,v_trim2=0;
bit USB_5V;
//硬件配置
//u8 Right_throttle;
bit throttle_lock,Throttle_check=1,Auto_lock,Trim_step;
u8 tt=0;
u8 middle_change_last;
u16 value0,value1;
u8 IN_mapping[8];
bit recover;
bit NRF_config_change,config_change;
bit first;
u16 CH1_max=600,CH2_max=600,CH3_max=600,CH4_max=600;
u16 CH1_min=400,CH2_min=400,CH3_min=400,CH4_min=400;
u8 CH1_offset=51,CH2_offset=51,CH3_offset=51,CH4_offset=51;
u16 CH_value[4];
u8 ratio_switch=0;
bit use_new_ratio;
//无线通信
bit cancel,connecting;
u8 TX_power=3;
bit CD;
u8 data RC_TX_state=0;
u8 t_check,t_hopping,NRF_error=0;
u8 CD_data[16];
u8 NRF_mapping[8];
u16 NRF_buff[8];
u8 timer2=0,timer3=0,receive=0;
u8 rx_sum,FUCK_sum=0;//坑爹的xdata,定义成rx不能用,定义成FUCK就能用了
u8 address[5];
u8 hopping[5];
u8 code address_0[5]={'L','O','V','E','!'};//使用LOVE作为对频暗语
u8 tx_buff[11],tx_data[11],rx[11]={0,0,0};
u8 tx_order[11];
u8 TX_protocol=3;
u8 Power_V=70,Chip_V=40,TX_min=60,RX_min=60;
//接收机设置
u8 receiver_mode[8];
bit Receiver_change;
bit NRF_change;
char out_control[8];
u16 out_control_data[8];
//PPM
u8 T_l,T_h;
u8 t_ppm=0,t_PPMout=0;
int PPM_DATA[8]={0,0,0,0,0,0,0,0};
int data PPM_buff[8];
u16 data PPMout[8]={500,600,800,200,1000,0,100,300};
u8 PPM_mapping[8]={0,1,2,3,4,5,6,7};
u8 train_switch=0;
bit train_output;
u8 PPM_updata=0;
char PPM_offset=0;
//自动控制
u8 auto_switch=0,auto_mode=2;
char auto_middle=-100,auto_star=-50,auto_end=50;
u8 auto_speed=10;
int auto_value=0;
u16 auto_max,auto_min;
bit auto_h,auto_l=0;
//开关
u8 Switch_A,Switch_B,Switch_C,Switch_D,Switch_E;
u8 Combination_Switch=0,Com_Swt_IN1=0,Com_Swt_IN2=0;
u8 Com_Swt_out[6]={16,29,42,55,68,81};
u8 Com_Swt_mapping=4;
u8 Return_alarm_switch=0;
//通道运算
int data operation[8];
char CH_middle[8];
bit ratio_mode;
u8 CH_ratio[2][8];
u8 New_ratio[2][4]={60,60,60,60,60,60,60,60};
u8 CH_inverted[8];
u8 CH_middle_change=0;
u8 mixer_name;
bit mixer1,mixer2,mixer3,mixer4;
u8 mixer1_same,mixer1_contrary;
u8 mixer2_same,mixer2_contrary;
u8 mixer3_same,mixer3_contrary;
u8 mixer4_same,mixer4_contrary;
//曲线运算
u8 curve_buff[51];
u8 index_number=0;
bit index_change;
char last_index;
char CH_index[3];
u8 point_num=3,curve_num=0;
u8 turnning_point[5][7];
u16 throttle;
/***********************************************************/
//延时函数
void Delay1ms() //@12.000MHz
{
unsigned char i, j;
i = 12;
j = 168;
do
{
while (--j);
} while (--i);
}
void delay_ms(u16 i) //延时毫秒
{
while(i--)
Delay1ms();
}
/**********************************************************/
//ROM操作函数、数据读写控制
u8 EEPROM_read(u8 address_H,u16 address_L) //读数据
{
IAP_CMD=0x01;
if(address_L>255)
{
IAP_ADDRH=address_H+1;
IAP_ADDRL=address_L-255;
}
else
{
IAP_ADDRH=address_H;
IAP_ADDRL=address_L;
}
IAP_TRIG=0x5a;
IAP_TRIG=0xa5; _nop_();
return IAP_DATA;
}
void EEPROM_write(u8 address_H,u16 address_L,u8 byte) //写入数据
{
IAP_CMD=0x02;
IAP_DATA=byte;
if(address_L>255)
{
IAP_ADDRH=address_H+1;
IAP_ADDRL=address_L-255;
}
else
{
IAP_ADDRH=address_H;
IAP_ADDRL=address_L;
}
IAP_TRIG=0x5a;
IAP_TRIG=0xa5; _nop_();
}
void EEPROM_clean(u8 address_H) //擦除数据
{
IAP_CMD=0x03;
IAP_ADDRH=address_H;
IAP_ADDRL=0;
IAP_TRIG=0x5a;
IAP_TRIG=0xa5;_nop_();
}
void Data_change(u8 m)//数据改变
{
if(m==1)Data_system=1;
if(m==2)Data_model=1;
event3=1,t3=0;//刷新事件3定时器
}
void DATA_read1() //读取系统参数
{
u8 i;u16 sum=0,sum_read;
IAP_CONTR=0x83;
for(i=0;i<74;i++)
{
sum+=EEPROM_read(0,i);
}
sum_read=EEPROM_read(0,74);//读校验和
sum_read<<=8;
sum_read+=EEPROM_read(0,75);
if(EEPROM_read(0,0)!=Version||sum!=sum_read)
{
first=1;
RC_T