只是为了方便阅读和理解,所以未做详细的正确性检查。

因为能力所限,程度中还是保留了很多跳转(goto)语句。

主循环已经完成,发上来供大家参考

int main(void)

{

if(0 == Prepare_Lock_Or_Fuse_Read() & 0x80)

{

while(1);

}

Disable_Watchdog();

Initialize stack();

switch_power_off();

Ports_initialization();

Clear_r0_r25();

Clear_ram();

Random = 1;

// Set default programmed parameters

set_default_parameters();

// Read all programmed parameters

read_all_eeprom_parameters();

// Initialize ADC

Initialize_Adc();

// Set beep strength

Beep_Strength = Pgm_Beep_Strength;

//Set initial arm variable

Initial_Arm = 1;

//关中断

cli();

//???蜂鸣123

wait200ms();

beep_f1();

wait30ms();

beep_f2();

wait30ms();

beep_f3();

wait30ms();

#if MODE <= 1        ; Main or tail

//Wait for receiver to initialize

wait1s();

wait200ms();

wait200ms();

wait100ms();

#endif

init_no_signal:

while(1)

{

cli();

temp1 = 250;

do

{

temp2 = 250;

do

{

if(0 == (Read_Rcp_Int() & (1 << Rcp_In)))

{

goto bootloader_done;

}

}while(--temp2 != 0);

}while(--temp1 != 0);

if(Be_Bootloader())

{

Booterloder();

while(1);

}

bootloader_done:

decode_parameters();

decode_settings();

set_bec_voltage();

find_throttle_gain();

Beep_Strength = Pgm_Beep_Strength;

switch_power_off();

//Timer0: clk/8 for regular interrupts

TCCR0 = (1 << CS01);

//Timer1: clk/8 for commutation control and RC pulse measurement

TCCR1B = (1 << CS11);

//Timer2: clk/8 for pwm

TCCR2 = (1 << CS21);

//Initialize interrupts and registers

TIFR = (1<

TIMSK = (1<

//Initialize comparator

Comp_Init();

wait1ms();

//Enable all interrupts

sei();

//Measure number of lipo cells

Measure_Lipo_Cells();

//Reset stall count

sts        Stall_Cnt = 0;

//Initialize RC pulse

Rcp_Int_First(); //Enable interrupt and set to first edge

Rcp_Int_Enable();// Enable interrupt

Rcp_Clear_Int_Flag();// Clear interrupt flag

Flags2 &= ~(1<

wait200ms();

Flags0 |= (1<

Temp4 = 3;//                                                ; Number of attempts before going back to detect input signal

measure_pwm_freq_start:

Temp3 = 12//                                                ; Number of pulses to measure

measure_pwm_freq_loop:

//Check if period diff was accepted

if(Rcp_Period_Diff_Accepted == 0)

{

Temp3 = 12;        //                                        ; Reset number of pulses to measure

if(0 == --Temp4)

{

continue;

};

}

wait30ms();        //                                                ; Wait 30ms for new pulse

if(0 == (Flags2 & (1 << RCP_UPDATED)))//; Is there an updated RC pulse available - proceed

{

continue;

}

Flags2 &= ~(1<

if(New_Rcp < RCP_VALIDATE) goto measure_pwm_freq_start; //New_Rcp太小

Temp1 = Curr_Rcp_Pwm_Freq;//                        ; Store as previous flags for next pulse

Prev_Rcp_Pwm_Freq = Temp1;//

// Store current flags for next pulse

Curr_Rcp_Pwm_Freq = (Flags3 & ((1<

if(Curr_Rcp_Pwm_Freq != Temp1) goto measure_pwm_freq_start;//                        ; Go back if new flags not same as previous

if(--Temp3 != 0) goto measure_pwm_freq_loop;//                        ; Go back if not required number of pulses seen

//Clear measure pwm frequency flag

Flags0 &= ~(1<

//Set up RC pulse interrupts after pwm frequency measurement

Rcp_Int_First();//                                        ; Enable interrupt and set to first edge

Rcp_Clear_Int_Flag();//                                ; Clear interrupt flag

Flags2 &= ~(1<

if(Pgm_Enable_PWM_Input        == 0)//                ; Check if PWM input is enabled

{

Flags2 |= (1<

//__zlf__原程序此处是否正确???

Flags3 &= (!((1<

}

//Test whether signal is OnShot125

Flags2 &= ~(1 << RCP_PPM_ONESHOT125);//        ; Clear OneShot125 flag

Rcp_Outside_Range_Cnt = 0;//                ; Reset out of range counter

wait100ms();//                                        ; Wait for new RC pulses

if((0 != (Flags2 & (1 << RCP_PPM))) &&// If flag is not set (PWM) - branch

(Rcp_Outside_Range_Cnt >= 10))// Check how many pulses were outside normal PPM range (800-2160us)

{

Flags2 |= (1<

}

//; Validate RC pulse

validate_rcp_start:

do

{

wait3ms();//                                                ; Wait for next pulse (NB: Uses Temp1/2!)

Temp1 = RCP_VALIDATE;//                                ; Set validate level as default

if(0 != (Flags2 & ( 1<< RCP_PPM)))

{

Temp1 = 0;//                                                ; Set level to zero for PPM (any level will be accepted)

}

}while (New_Rcp < Temp1);//New_Rcp太小

//; Beep arm sequence start signal

cli();//                                                                ; Disable all interrupts

beep_f1();//                                                ; Signal that RC pulse is ready

beep_f1();//                                                ; Signal that RC pulse is ready

beep_f1();//                                                ; Signal that RC pulse is ready

sei();//                                                                ; Enable all interrupts

wait200ms();

// Arming sequence start

Gov_Arm_Target = 0;//        ; Clear governor arm target

arming_start:

do

{

#if MODE >= 1//        ; Tail or multi

if(Pgm_Direction != 3)        //        ; Check if bidirectional operation

{

#endif

wait3ms();

if((Pgm_Enable_TX_Program >= 1)|| //; Start programming mode entry if enabled

(Initial_Arm >= 1))//                ; Yes - check if it is initial arm sequence

{

do

{

if(0 == (Flags2 & (1 << RCP_PPM)))

{

//PWM tx program entry

if(New_Rcp < RCP_MAX)//                        ; Is RC pulse max?

{

break;//        ; No - branch

}

while(New_Rcp >= RCP_STOP)//New_Rcp >= RCP_STOP

{

cli();//                                                ; Disable all interrupts

beep_f4();

sei();//                                                ; Enable all interrupts

wait100ms();

}

while(New_Rcp < RCP_MAX);

{

cli();//                                                ; Disable all interrupts

beep_f1();

wait10ms();

beep_f1();

sei();//                                                ; Enable all interrupts

wait100ms();

}

program_by_tx();//                        ; Yes - enter programming mode

}

//; PPM throttle calibration and tx program entry

#if MODE <= 1        //; Main or tail

temp8 = 8;//                                ; Set 3 seconds wait time

#else

temp8 = 3;//                                ; Set 1 second wait time

#endif

for(;temp8 != 0; tmp8--)

{

Flags3 |= (1<

cli();

find_throttle_gain();//                ; Set throttle gain

sei();

wait100ms();//                        ; Wait for new throttle value

cli();//                                                ; Disable interrupts (freeze New_Rcp value)

Flags3 &= ~(1<

find_throttle_gain();//                ; Set throttle gain

Temp7 = New_Rcp;//                        ; Store new RC pulse value

sei();                                                //; Enable interrupts

if(New_Rcp        < (RCP_MAX/2))// Is RC pulse above midstick?

{

goto arm_target_updated;//                ; No - branch

}

wait1ms();

cli();//                                                ; Disable all interrupts

beep_f4();

sei();                                                ; Enable all interrupts

}

average_throttle();

#if MODE <= 1        //; Main or tail

Pgm_Ppm_Max_Throttle = Temp7 - 5;//                                ; Subtract about 2% and ensure that it is 250 or lower

#else

Pgm_Ppm_Max_Throttle = Temp7;

#endif

wait200ms();

cli();

success_beep();

sei();

for(Temp8 = 10; Temp8 != 0; Temp8--)//                                ; Set 3 seconds wait time

{

Flags3 |= (1<

cli();

find_throttle_gain();//                ; Set throttle gain

sei();

wait100ms();

cli();                                                //; Disable interrupts (freeze New_Rcp value)

Flags3 &= ~(1<

find_throttle_gain();//                ; Set throttle gain

Temp7 = New_Rcp;//                        ; Store new RC pulse value

sei();                                                ; Enable interrupts

if(New_Rcp >= (RCP_MAX/2))//                ; Below midstick?

{

Temp8 = 10;//                                ; Set 3 seconds wait time

continue;//        ; No - start over

}

wait1ms();

cli();//                                                ; Disable all interrupts

beep_f1();

wait10ms();

beep_f1();

sei();                                                ; Enable all interrupts

}

average_throttle();

Temp1 = Pgm_Ppm_Min_Throttle = Temp7 + 5;//        ; Add about 2% (subtract negative number), ; Min throttle in Temp1

Temp2 = Pgm_Ppm_Max_Throttle - 130;//                        ; Subtract 130 (520us) from max throttle

if((Pgm_Ppm_Max_Throttle < 130) ||

(Pgm_Ppm_Max_Throttle - 130 < Temp1)

{

Pgm_Ppm_Max_Throttle = Temp1 + 130;//Make max 520us higher than min

}

wait200ms();

cli();

store_all_in_eeprom();

success_beep_inverted();

sei();

wait100ms();

cli();

find_throttle_gain();//                ; Set throttle gain

sei();

}while(New_Rcp < RCP_MAX);

program_by_tx();//                        ; Yes - enter programming mode

}

if(New_Rcp >= Gov_Arm_Target)//                ; Is RC pulse larger than arm target?

{

Gov_Arm_Target = Temp1;// Yes - update arm target

}

arm_target_updated:

wait100ms();//                        ; Wait for new throttle value

Temp1 = RCP_STOP;//                ; Default stop value

if(Pgm_Direction == 3)//                ; Check if bidirectional operation

{

Temp1 = (RCP_STOP+4);//                ; Higher stop value for bidirectional

}

#if MODE >= 1//        ; Tail or multi

}

#endif

}while(New_Rcp >= Temp1);//No below stop

//; Beep arm sequence end signal

cli();//                                                ; Disable all interrupts

beep_f4();//                                ; Signal that rcpulse is ready

beep_f4();//                                ; Signal that rcpulse is ready

beep_f4();//                                ; Signal that rcpulse is ready

sei();//                                                ; Enable all interrupts

wait200ms();

//; Clear initial arm variable

Initial_Arm = 0;

//; Armed and waiting for power on

wait_for_power_on:

while(1)

{

Power_On_Wait_Cnt_L = 0;// Clear wait counter

Power_On_Wait_Cnt_H = 0;// Zero

do

{

Power_On_Wait_Cnt_L++;//        ; Increment low wait counter

if(Power_On_Wait_Cnt_L == 0xFF)// Counter wrapping (about 3 sec)?

{

Power_On_Wait_Cnt_H++;//        ; Increment high wait counter

Temp1 = 25;//                        ; Approximately 1 min

if(Pgm_Beacon_Delay = 1)

else if(Pgm_Beacon_Delay = 2)

{

Temp1 = 50;//                        ; Approximately 2 min

}

else if(Pgm_Beacon_Delay = 3)

{

Temp1 = 125;//                ; Approximately 5 min

}

else if(Pgm_Beacon_Delay = 4)

{

Temp1 = 250;//                ; Approximately 10 min

}

else

{

Power_On_Wait_Cnt_H = 0;//Reset counter for infinite delay

}

if(Power_On_Wait_Cnt_H >= Temp1)//                                ; Check against chosen delay

{

switch_power_off();//                ; Switch power off in case braking is set

wait1ms();

Power_On_Wait_Cnt_H--;// Decrement high wait counter

Power_On_Wait_Cnt_L = 0; Set low wait counter

Beep_Strength = Pgm_Beacon_Strength;

cli();//                                                ; Disable all interrupts

beep_f();//                                ; Signal that there is no signal

sei();//                                                ; Enable all interrupts

Beep_Strength = Pgm_Beep_Strength;

wait100ms();//                                ; Wait for new RC pulse to be measured

}

}

wait10ms();

if(Rcp_Timeout_Cntd == 0)

{

if(0 != (Flags2 & (1 << RCP_PPM)))//; If ppm and pulses missing - go back to detect input signal

{

goto init_no_signal;

}

}

Temp1 = RCP_STOP;

if(0 == (Flags2 & (1 << RCP_PPM)))

{

Temp1 = (RCP_STOP+5);//         ; Higher than stop (for pwm)

}

}while(New_Rcp < Temp1);

#if MODE >= 1        //; Tail or multi

if(Pgm_Direction != 3)

#endif

{

wait100ms();//                        ; Wait to see if start pulse was only a glitch

}

if(0 == Rcp_Timeout_Cntd)//                ; If it is not zero - proceed

{

goto init_no_signal;//                        ; If it is zero (pulses missing) - go back to detect input signal

}

//Start entry point

cli();

switch_power_off();

Requested_Pwm = 0;//Set requested pwm to zero

Governor_Req_Pwm = 0;// Set governor requested pwm to zero

Current_Pwm = 0;//Set current pwm to zero

Current_Pwm_Limited = 0;//Set limited current pwm to zero

Current_Pwm_Lim_Dith = 0;

Pwm_Dither_Excess_Power = 0;

sei();

//; Set idle pwm to programmed value

Pwm_Motor_Idle = (Pgm_Motor_Idle << 1);

Gov_Target_L = 0;//                ; Set target to zero

Gov_Target_H = 0;//

Gov_Integral_L = 0;//        ; Set integral to zero

Gov_Integral_H = 0;//

Gov_Integral_X = 0;//

Adc_Conversion_Cnt = 0;//

Flags0 = 0;//                                ; Clear flags0

Flags1 = 0;//                                ; Clear flags1

Demag_Detected_Metric = 0;//Clear demag metric

//Motor start beginning

Adc_Conversion_Cnt = TEMP_CHECK_RATE;                                        ; Make sure a temp reading is done

Set_Adc_Ip_Temp();

wait1ms();

Start_Adc();

//read_initial_temp

while(0 != (Get_Adc_Status() & (1 << ADSC))) {};

Temp1 = ADCL;

Temp2 = ADCH;

Stop_Adc();

if(0 != Temp2)//; Is reading below 256?

{

Temp1 = 0xFF;                                                ; No - set average temperature value to 255

}

Current_Average_Temp_Adc = Temp1;//                ; Set initial average temp ADC reading

check_temp_voltage_and_limit_power();

Adc_Conversion_Cnt = TEMP_CHECK_RATE;//                                        ; Make sure a temp reading is done next time

Set_Adc_Ip_Temp();

//; Set up start operating conditions

decode_parameters();//                ; (Decode_parameters uses Temp1 and Temp8)

//; Set max allowed power

cli();//                                                ; Disable interrupts to avoid that Requested_Pwm is overwritten

Pwm_Limit = 0xFF;//                                ; Set pwm limit to max

set_startup_pwm();

Pwm_Limit = Requested_Pwm;

Pwm_Limit_Spoolup = Requested_Pwm;

Pwm_Limit_By_Rpm = Requested_Pwm;

sei();

//Set low pwm again after calling set_startup_pwm

Requested_Pwm = 1;

Current_Pwm = 1;

Current_Pwm_Limited = 1;

Current_Pwm_Lim_Dith = 1;

Spoolup_Limit_Skip = 1;

Spoolup_Limit_Cnt = Auto_Bailout_Armed;

//Begin startup sequence

if(Pgm_Direction == 3)//                        ; Check if bidirectional operation

{

Flags3 &= ~(1<

if(0 != (Flags2 & (1 << RCP_DIR_REV)))//                        ; Check force direction

{

Flags3 |= (1<

}

}

init_start_bidir_done:

Flags1 |= (1<

Flags1 |= (1<

Startup_Cnt = Zero;//                        ; Reset counter

comm5comm6();//                                ; Initialize commutation

comm6comm1();//

initialize_timing();//                        ; Initialize timing

calc_next_comm_timing();//                ; Set virtual commutation point

initialize_timing();//                        ; Initialize timing

calc_next_comm_timing();//

initialize_timing();//                        ; Initialize timing

//; Run entry point

//; Run 1 = B(p-on) + C(n-pwm) - comparator A evaluated

//; Out_cA changes from low to high

run1:

wait_for_comp_out_high        ; Wait zero cross wait and wait for high

//;                 setup_comm_wait();//                ; Setup wait time from zero cross to commutation

//;                 evaluate_comparator_integrity();//        ; Check whether comparator reading has been normal

calc_governor_target();//        ; Calculate governor target

wait_for_comm();//                        ; Wait from zero cross to commutation

comm1comm2();//                        ; Commutate

calc_next_comm_timing();//        ; Calculate next timing and start advance timing wait

//;                 wait_advance_timing();//        ; Wait advance timing and start zero cross wait

//;                 calc_new_wait_times();//

//;                 set_comparator_phase();//        ; Set comparator phase

//;                 wait_before_zc_scan();//        ; Wait zero cross wait and start zero cross timeout

//; Run 2 = A(p-on) + C(n-pwm) - comparator B evaluated

//; Out_cB changes from high to low

run2:

wait_for_comp_out_low();

//;                 setup_comm_wait();

//;                 evaluate_comparator_integrity();

if(0 != (Flags0 & (1 << GOV_ACTIVE)))

{

calc_governor_prop_error();

}

if(0 == (Flags1 & (1 << HIGH_RPM)))//                ; Skip if high rpm

{

set_pwm_limit_low_rpm();

}

if(0 != (Flags1 & (1 << HIGH_RPM)))//                ; Do if high rpm

{

set_pwm_limit_high_rpm();

}

wait_for_comm();//                        ; Wait from zero cross to commutation

comm2comm3();//                        ; Commutate

calc_next_comm_timing();//        ; Calculate next timing and start advance timing wait

//;                 wait_advance_timing();//        ; Wait advance timing and start zero cross wait

//;                 calc_new_wait_times();//

//;                 set_comparator_phase();//        ; Set comparator phase

//;                 wait_before_zc_scan();//        ; Wait zero cross wait and start zero cross timeout

//; Run 3 = A(p-on) + B(n-pwm) - comparator C evaluated

//; Out_cC changes from low to high

run3:

wait_for_comp_out_high();

//;                 setup_comm_wait

//;                 evaluate_comparator_integrity

if(0 != (Flags0 & (1 << GOV_ACTIVE)))

{

calc_governor_prop_error();

}

wait_for_comm();//                        ; Wait from zero cross to commutation

comm3comm4();//                        ; Commutate

calc_next_comm_timing();//        ; Calculate next timing and start advance timing wait

//;                 wait_advance_timing();//        ; Wait advance timing and start zero cross wait

//;                 calc_new_wait_times();//

//;                 set_comparator_phase();//        ; Set comparator phase

//;                 wait_before_zc_scan();//        ; Wait zero cross wait and start zero cross timeout

//; Run 4 = C(p-on) + B(n-pwm) - comparator A evaluated

//; Out_cA changes from high to low

run4:

wait_for_comp_out_low();

//;                 setup_comm_wait();

//;                 evaluate_comparator_integrity();

if(0 != (Flags0 & (1 << GOV_ACTIVE)))

{

calc_governor_prop_error();

}

wait_for_comm();//                        ; Wait from zero cross to commutation

comm4comm5();//                        ; Commutate

calc_next_comm_timing();//        ; Calculate next timing and start advance timing wait

//;                 wait_advance_timing();//        ; Wait advance timing and start zero cross wait

//;                 calc_new_wait_times();//

//;                 set_comparator_phase();//        ; Set comparator phase

//;                 wait_before_zc_scan();//        ; Wait zero cross wait and start zero cross timeout

//; Run 5 = C(p-on) + A(n-pwm) - comparator B evaluated

//; Out_cB changes from low to high

run5:

wait_for_comp_out_high();

//;                 setup_comm_wait

//;                 evaluate_comparator_integrity

if(0 != (Flags0 & (1 << GOV_ACTIVE)))

{

calc_governor_prop_error();

}

wait_for_comm();//                        ; Wait from zero cross to commutation

comm5comm6();//                        ; Commutate

calc_next_comm_timing();//        ; Calculate next timing and start advance timing wait

//;                 wait_advance_timing();//        ; Wait advance timing and start zero cross wait

//;                 calc_new_wait_times();//

//;                 set_comparator_phase();//        ; Set comparator phase

//;                 wait_before_zc_scan();//        ; Wait zero cross wait and start zero cross timeout

//; Run 6 = B(p-on) + A(n-pwm) - comparator C evaluated

//; Out_cC changes from high to low

run6:

wait_for_comp_out_low();

//;                 setup_comm_wait();

//;                 evaluate_comparator_integrity();

Start_Adc();

wait_for_comm();//                        ; Wait from zero cross to commutation

comm6comm1();//                        ; Commutate

calc_next_comm_timing();//        ; Calculate next timing and start advance timing wait

//;                 wait_advance_timing();//        ; Wait advance timing and start zero cross wait

//;                 calc_new_wait_times();//

//;                 set_comparator_phase();//        ; Set comparator phase

//;                 wait_before_zc_scan();//        ; Wait zero cross wait and start zero cross timeout

check_temp_voltage_and_limit_power();

//; Check if it is startup

if(0 == (Flags1 & (1 << STARTUP_PHASE)))

{

goto normal_run_checks;

}

//Set spoolup power variables

Pwm_Limit = Pwm_Spoolup_Beg;//                                ; Set initial max power

Pwm_Limit_Spoolup = Pwm_Spoolup_Beg;//                ; Set initial slow spoolup power

Spoolup_Limit_Cnt = Auto_Bailout_Armed;

Spoolup_Limit_Skip = 1;

//; Check startup counter

Temp2 = 24;//                                        ; Set nominal startup parameters

Temp3 = 12;

if(Startup_Cnt < Temp2)//                                        ; Is counter above requirement?

{

if(New_Rcp < RCP_STOP)//                                ; Check if pulse is below stop value

{

goto run_to_wait_for_power_on;

}

else

{

goto run1;//                                                ; Continue to run

}

}

Flags1 &= ~(1<

Flags1 |= (1<

Initial_Run_Rot_Cntd = Temp3;//        ; Set initial run rotation count

#if MODE == 1        //; Tail

Pwm_Limit = 0xff;//                                ; Allow full power

#elif MODE == 2 //        ; Multi

Pwm_Limit = Pwm_Spoolup_Beg;

Pwm_Limit_By_Rpm = Pwm_Spoolup_Beg;

#endif

normal_run_checks:

//; Check if it is initial run phase

if(0 == (Flags1 & (1 << INITIAL_RUN_PHASE)))//        ; If not initial run phase - branch

{

goto initial_run_phase_done;

}

if(1 == (Flags0 & (1 << DIR_CHANGE_BRAKE)))//                ; If a direction change - branch

{

goto initial_run_phase_done;

}

//; Decrement startup rotation count

if(Initial_Run_Rot_Cntd - 1) == 0) //; Check number of nondamped rotations

{

Flags1 &= ~(1<

Flags1 |= (1<

goto run1

}                                                ; Continue with normal run

normal_run_check_startup_rot:

Initial_Run_Rot_Cntd = Initial_Run_Rot_Cntd - 1;//                ; Not zero - store counter

if(New_Rcp >= RCP_STOP)//                                ; Check if pulse is below stop value

{

goto run1();//                                                ; Continue to run

}

if(Pgm_Direction != 3)//                        ; Check if bidirectional operation

{

goto run_to_wait_for_power_on;

}

initial_run_phase_done:

//; Reset stall count

Stall_Cnt = 0;

#if MODE == 0        //; Main

//; Check if throttle is zeroed

if(Rcp_Stop_Cnt >=        1)//        ; Is number of stop RC pulses above limit?

{

Pwm_Limit_Spoolup = Pwm_Spoolup_Beg;//                        ; If yes - set initial max powers

Spoolup_Limit_Cnt = Auto_Bailout_Armed;//                ; And set spoolup parameters

Spoolup_Limit_Skip = 1;

}

#endif

//; Exit run loop after a given time

Temp1 = RCP_STOP_LIMIT;

if(0 != Pgm_Brake_On_Stop)

{

Temp1 = 3;//                                        ; About 100ms before stopping when brake is set

}

if(Rcp_Stop_Cnt > Temp1)//                                        ; Is number of stop RC pulses above limit?

{

goto run_to_wait_for_power_on;//                ; Yes, go back to wait for poweron

}

if(0 != (Flags2 & (1 << RCP_PPM)))

{

if(Rcp_Timeout_Cntd == 0)

{

goto run_to_wait_for_power_on;//                ; If it is zero - go back to wait for poweron

}

}

run6_check_dir:

#if MODE >= 1 //        ; Tail or multi

if((Pgm_Direction == 3) &&                                                 //Check if bidirectional operation

((0 == (Flags3 & (1 << PGM_DIR_REV))) !=         //Check if actual rotation direction

(0 == (Flags2 & (1 << RCP_DIR_REV)))) &&    //Matches force direction

(0 == (Flags0 & (1 << DIR_CHANGE_BRAKE))))

{

Flags0 |= (1<

Pwm_Limit = Pwm_Spoolup_Beg;//                ; Set max power while braking

goto run4;//                                                ; Go back to run 4, thereby changing force direction

}

#endif

Temp1 = 0xF0;//                                ; Default minimum speed

if((0 != (Flags0 & (1 <

{

Pwm_Limit = Pwm_Spoolup_Beg;//                        ; Set max power while braking

Temp1 = 0x20;//                                ; Bidirectional braking termination speed

}

run6_brake_done:

if(Comm_Period4x_H        < Temp1)//                 ; Is Comm_Period4x more than 32ms (~1220 eRPM)?

{

goto run1;//                                                ; No - go back to run 1

}

//; Yes - stop or turn direction

#if MODE >= 1        //; Tail or multi

if(0 == (Flags0 & (1 << DIR_CHANGE_BRAKE)))//                ; If it is not a direction change - stop

{

goto run_to_wait_for_power_on;

}

Flags0 &= ~(1<

Flags3 &= (1<

if(0 != (Flags2 & (1 << RCP_DIR_REV)))//                        ; Check force direction

{

Flags3 += (1<

}

Flags1 |= (1<

Initial_Run_Rot_Cntd = 18;

Pwm_Limit = Pwm_Spoolup_Beg;//                        ; Set initial max power

goto run1;//                                                ; Go back to run 1

.ENDIF

run_to_wait_for_power_on_fail:

Stall_Cnt++;//                                ; Increment stall count

if(0 != New_Rcp)//                                ; Check if RCP is zero, then it is a normal stop

{

goto run_to_wait_for_power_on_stall_done;

}

run_to_wait_for_power_on:

Stall_Cnt = Zero;

run_to_wait_for_power_on_stall_done:

cli();

switch_power_off();

Temp7 = Pgm_Pwm_Freq;//                        ; Store setting in Temp7

Pgm_Pwm_Freq = 2;

decode_parameters();//                        ; (Decode_parameters uses Temp1 and Temp8)

Pgm_Pwm_Freq = Temp7;//                        ; Restore settings

Requested_Pwm = 0;//                        ; Set requested pwm to zero

Governor_Req_Pwm = 0;//                ; Set governor requested pwm to zero

Current_Pwm = 0;//                        ; Set current pwm to zero

Current_Pwm_Limited = 0;//        ; Set limited current pwm to zero

Current_Pwm_Lim_Dith = 0;//

Pwm_Motor_Idle = 0;//                ; Set motor idle to zero

Flags0 = 0;//                                        ; Clear flags0

Flags1 = 0;//                                        ; Clear flags1

sei();

wait100ms();//                                ; Wait for pwm to be stopped

switch_power_off();

if(0 != Pgm_Brake_On_Stop)

{

Brake_FETs_On();

}

run_to_wait_for_power_on_brake_done:

Initialize_Adc();//                                ; Initialize ADC, to keep reference on for selected ESCs

#if MODE == 0 //        ; Main

if((0 != (Flags2 & (1 << RCP_PPM)))

&& (0 == Rcp_Timeout_Cntd))//                ; Load RC pulse timeout counter value

{

goto init_no_signal;//                                ; If it is zero (pulses missing) - go back to detect input signal

}

run_to_next_state_main:

if(Pgm_Main_Rearm_Start >= 1)// Is re-armed start enabled?

{

goto        validate_rcp_start;//                        ; Yes - go back to validate RC pulse

}

//No - do like tail and start immediately

#elif MODE >= 1        //; Tail or multi

if((0 != (Flags2 & (1 << RCP_PPM)))

&& (Stall_Cnt >= 4))//

{

goto init_no_signal;//                                ; If it is zero (pulses missing) - go back to detect input signal

}

#endif

}

}

}

c语言tmplink,为了便于阅读,偿试把BLHeli的汇编源程序改成C语言格式相关推荐

  1. c 系统语言改为中文,主编设置win7系统英文版改成中文语言的操作技巧

    根据朋友们的反映以及小编自己的观察,发现win7系统英文版改成中文语言的疑问是很多朋友的困扰之处,即便很容易处理,还是有朋友不知道win7系统英文版改成中文语言到底如何处理.即便很容易处理,还是有朋友 ...

  2. 单目车辆测距源码,python源码,可以自己改成c语言

    单目车辆测距源码,python源码,可以自己改成c语言 单目车辆测距源码,python源码,可以自己改成c语言 辅助驾驶之车辆测距程序 测距原理:参考百度陈光的基于单目摄像头的物体检测-2D图像上的3 ...

  3. java改成c语言专业名词解释,求助大神!!!JAVA转换成C语言

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 //此处不要看,c++应该内置了这个函数,不需要自定义 Array.prototype.remove = function(val) { var inde ...

  4. c语言改java语言,请教怎么把这个JAVA程序改成C语言能够运行啊

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 package test; import java.io.BufferedReader; import java.io.IOException; impo ...

  5. c语言ntc程序,NTC热敏电阻测温度 单片机C和汇编源程序

    /*---------------------------------------------------------------------*/ /* --- STC MCU Internation ...

  6. java 语言转 c 命令_求助大神!!!JAVA转换成C语言

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 //此处不要看,c++应该内置了这个函数,不需要自定义 Array.prototype.remove = function(val) { var inde ...

  7. 联想e470c怎么修改电脑语言,我联想e470c笔记本,重装系统把预装的win10改成win...-e470改win7,联想e470装win10bios...

    联想预装win10安装win7系统步骤如下: 1.把U盘插入电脑,打开小白一键安装,点击[U盘启动],然后点击[U盘模式],进入界面后,在[设备名]勾选需要制作启动的U盘,点击[一键制作启动U盘]. ...

  8. 将element-plus 默认的使用英语改成其他语言设置

    1.我们可以看到我们使用最新的elementPlus 时,全部都是英语 2.在App.vue 里面进行全局国际化的配置 <template><div id="app&quo ...

  9. dell笔记本c语言系统,戴尔Latitude 5280笔记本如何将自带win10改成win7

    [文章导读]戴尔Latitude 5280是一款12.5英寸笔记本,该机型采用 Intel 酷睿第七代处理器.默认预装了windows10系统,很多用户不喜欢win10系统,打算安装win7系统,但是 ...

最新文章

  1. Bootstrap下拉菜单组件
  2. 计算机教案计算机的组成,计算机的组成 教案
  3. 浏览器默认标签样式总结及css初始化程序(转)
  4. 关于VMFS6 Block 1M 512M 说明
  5. 甲骨文推出低成本高速公共与混合云方案,矛头直指AWS
  6. python安装cv-oracle时如何解决vc++的问题_python中cx_Oracle模块安装遇到的问题与解决方法...
  7. 腾讯 java_2019腾讯的面试题(腾讯qq音乐部门)
  8. 什么是BNF EBNF 巴科斯范式及其扩展 BNF Augmented BNF
  9. (DFS or BFS)Find The Multiple(poj1426)
  10. VC++ 多线程同步实例
  11. 暑期训练日志----2018.8.10
  12. Java实战-坦克大战
  13. Android Shape工具 Duck
  14. java 制作动态手机壁纸_android 动态切换壁纸实例 利用service机制实现 附完整源码 带动态截图...
  15. 创建带Tomcat服务的Centos Docker镜像
  16. Netty in action—单元测试
  17. WDA基础七:TABStrip
  18. win10+Ubuntu16.04 LTS双系统完美教程
  19. 10. InnoDB表空间加密
  20. Tolua for Unity3d 编译字节码

热门文章

  1. AI写程序,这事可没那么简单!
  2. 云栖大讲堂Java基础入门(三)- 阿里巴巴Java开发手册介绍
  3. IoT日志利器:嵌入式日志客户端(C Producer)发布
  4. 看懂别人的代码,只是成为高效程序员的第一步!
  5. BDTC 2019 | 七个开发者能干多大的事?​
  6. 虚拟化精华问答 | 什么是虚拟化?
  7. MyBatis 配置文件 用户密码加密存储
  8. flowable 数据库表结构 梳理
  9. Centos7 开机启动汇总
  10. 常用命令集合_Windows