[$group] 元件库.2类闪烁led灯类 [$last_ver_update_time] 2021-04-03 [$min_need_ver] 1.23 [$p_list] [$short_show_UIname] [$code_area_type] codes,exe_per_1ms,init_code [$blocks_type] line [$name] 闪烁的led灯的初始化积木 [$thread_do] thread_shan_led_t_$rnd_varname_pre$();//虚拟线程,不能含阻塞执行的部分,每1ms执行一次 [$cs] [$function_ref_define_in_headfile] @@file=shan_led2.h void ctrl_shan_led_t_$rnd_varname_pre$(u16 timess1,u16 delay_times,u16 delay2); void thread_shan_led_t_$rnd_varname_pre$(); extern u16 shanled_flag_$rnd_varname_pre$;//预留 extern u16 shanled_delay_time_$rnd_varname_pre$; //控制led灯每次闪后延时多少毫秒 extern u16 shanled_cur_need_count$rnd_varname_pre$; //控制led灯需要闪的次数变量 extern u32 shanled_delay_$rnd_varname_pre$_ccc; //每次闪完后停顿的时间的计时变量 extern u8 cur_shanled_is_on_or_off_$rnd_varname_pre$; //标志led灯目前是在闪还是不在闪 extern u16 shanled_cur_need2_count$rnd_varname_pre$; //控制led灯需要闪的次数变量 extern u8 cur_step_$rnd_varname_pre$; extern u16 end_ed_counter_$rnd_varname_pre$; extern u16 need_end_ed_counter_$rnd_varname_pre$; [$init_code_for_define_area] @@file=shan_led2.c u16 shanled_flag_$rnd_varname_pre$;//预留 u16 shanled_delay_time_$rnd_varname_pre$; //控制led灯每次闪后延时多少毫秒 u16 shanled_cur_need_count$rnd_varname_pre$; //控制led灯需要闪的次数变量 u32 shanled_delay_$rnd_varname_pre$_ccc; //每次闪完后停顿的时间的计时变量 u8 cur_shanled_is_on_or_off_$rnd_varname_pre$; //标志led灯目前是在闪还是不在闪 u16 shanled_cur_need2_count$rnd_varname_pre$; //控制led灯需要闪的次数变量 u8 cur_step_$rnd_varname_pre$=0; u16 end_ed_counter_$rnd_varname_pre$=0; u16 need_end_ed_counter_$rnd_varname_pre$=0; void ctrl_shan_led_t_$rnd_varname_pre$(u16 timess1,u16 delay_times,u16 delay2){ //控制led灯闪几次的赋值函数 shanled_cur_need2_count$rnd_varname_pre$=timess1; if(shanled_cur_need_count$rnd_varname_pre$==0){ shanled_cur_need_count$rnd_varname_pre$=timess1; } shanled_delay_time_$rnd_varname_pre$=delay_times; //控制led灯每次闪后延时多少毫秒 need_end_ed_counter_$rnd_varname_pre$=delay2; if(timess1==0){ shanled_cur_need_count$rnd_varname_pre$=0; cur_step_$rnd_varname_pre$=0; IO_Write([($_xgm$value3),type=pin] ,0) ; } } void thread_shan_led_t_$rnd_varname_pre$(){ if(shanled_cur_need_count$rnd_varname_pre$>0&& cur_step_$rnd_varname_pre$==0){//如果目标需要闪的次数大于0 if(shanled_delay_$rnd_varname_pre$_ccc>= shanled_delay_time_$rnd_varname_pre$ ){//如果延时计时达到 shanled_delay_$rnd_varname_pre$_ccc=0;//延时计时归零 if(cur_shanled_is_on_or_off_$rnd_varname_pre$==0){//判断当前状态 cur_shanled_is_on_or_off_$rnd_varname_pre$=1;//如果是关闭状态则开启 IO_Write([($_xgm$value3),type=pin] ,1) ; }else{ cur_shanled_is_on_or_off_$rnd_varname_pre$=0;//如果是开启状态则关闭 IO_Write([($_xgm$value3),type=pin] ,0) ; shanled_cur_need_count$rnd_varname_pre$--;//闪一次完事后减去目标的闪次数 if(shanled_cur_need_count$rnd_varname_pre$==0){ cur_step_$rnd_varname_pre$=1; end_ed_counter_$rnd_varname_pre$=0; } } } } if( cur_step_$rnd_varname_pre$==1){ end_ed_counter_$rnd_varname_pre$++; if( end_ed_counter_$rnd_varname_pre$ >= need_end_ed_counter_$rnd_varname_pre$){ end_ed_counter_$rnd_varname_pre$=0; shanled_cur_need_count$rnd_varname_pre$=shanled_cur_need2_count$rnd_varname_pre$; cur_step_$rnd_varname_pre$=0; } } } [$init_code_for_init_val] shanled_flag_$rnd_varname_pre$=0; shanled_cur_need_count$rnd_varname_pre$=0; shanled_delay_$rnd_varname_pre$_ccc=0; cur_shanled_is_on_or_off_$rnd_varname_pre$=0; shanled_delay_time_$rnd_varname_pre$=1000; #get_P口_to_PxM1_PxM0_set_code(group_xml,rand1,block_name,ref_complier,extinfo,"[($_xgm$value3),type=pin]","1","beep ")% IO_Write([($_xgm$value3),type=pin] ,0) ; cur_step_$rnd_varname_pre$=0; end_ed_counter_$rnd_varname_pre$=0; shanled_cur_need_count$rnd_varname_pre$=0; [$timer0_1ms_code] shanled_delay_$rnd_varname_pre$_ccc++;//计时加一 [$toolbox_block_code] [$replace_map] $_xgm$value3 = $field$guanjiao ,mytype|pin, ptype|TIMES