📄 last5.c
字号:
/*
cycle_measure_timer=1500;
chongci_num_min=(uint)(60000/cycle_measure_timer); // 计算实测最小冲次数(已经乘10)
cycle_measure_timer=750;
chongci_num_max=(uint)(60000/cycle_measure_timer); // 计算实测最大冲次数(已经乘10)
chongci_num_set=5.5*10;
chongcheng_speed_ratio_set=0.7*10;
// 计算上冲程冲次数(已经乘10)
chongci_num_up=(float)(chongci_num_set*(chongcheng_speed_ratio_set+10))/20;
// 计算下冲程冲次数(已经乘10)
chongci_num_down=(float)(chongci_num_set*(chongcheng_speed_ratio_set+10))/
(2*chongcheng_speed_ratio_set);
// 计算与设定冲次数对应的PWM数值
pwm_chongci_num_set=(float)((chongci_num_set-chongci_num_min)*255)/
(chongci_num_max-chongci_num_min);
// 计算上冲程PWM数值
pwm_data_up=(float)((chongci_num_up-chongci_num_min)*255)/(chongci_num_max-chongci_num_min);
// 计算下冲程PWM数值
pwm_data_down=(float)((chongci_num_down-chongci_num_min)*255)/(chongci_num_max-chongci_num_min);
while(1);
*/
//goto iic_time;
//goto iic_rom;
//goto pwm;
//goto ad;
//goto da;
//goto uart;
//goto lcd;
goto mainprog;
//-----------------------------------------------
pwm:
//wqy=152;
//PCA0CPL0 = wqy;
//PCA0CPH0 = wqy;
//while(1);
while(1)
{for(wqy=0;wqy<255;wqy++)
{
PCA0CPH0 = wqy;
P4=1;
for(timer0_10ms=0;timer0_10ms<10;);
P4=0;
for(timer0_10ms=0;timer0_10ms<10;);
}
}
//-----------------------------------------------
iic_time:
while(1)
{read_time();
sp_out('2');
sp_out('0');
change2_hex_askii(year);
sp_out2();
sp_out(0x0d);
change2_hex_askii(month);
sp_out2();
sp_out(0x0d);
change2_hex_askii(date);
sp_out2();
sp_out(0x0d);
sp_out('-');
sp_out(0x0d);
change2_hex_askii(hour);
sp_out2();
sp_out(0x0d);
change2_hex_askii(minute);
sp_out2();
sp_out(0x0d);
change2_hex_askii(second);
sp_out2();
sp_out(0x0d);
sp_out(0x0a);
P4=0; // 延时1秒
for(timer0_10ms=0;timer0_10ms<50;);
P4=1;
for(timer0_10ms=0;timer0_10ms<50;);
}
//-----------------------------------------------
iic_rom:
for(i=0;i<500;i++)
{
SM_Send(CHIP_ROM,i,0xcd); // 发送0x89到CHIP_ROM的地址i
}
for(i=0;i<500;i++)
{ wqy=SM_Receive(CHIP_ROM,i);// 从CHIP_ROM的地址i读数
change2_hex_askii(wqy);
sp_out2();
sp_out(0x0d);
}
while(1);
//-----------------------------------------------
lcd:
out_lcd_light=0;// LCD背光供电
clear_lcd(0,0,0);
menu_setup();
menu_wait();
for(wqy=0;wqy<255;wqy++)
{
xianshi_spaces_hanzi(7,12,infor_hanzi35,2);//显示“异常”
for(timer0_10ms=0;timer0_10ms<50;);
xianshi_spaces_hanzi(7,12,infor_hanzi34,2);//显示“正常”
for(timer0_10ms=0;timer0_10ms<200;);
}
goto lcd;
//-----------------------------------------------
da:
for(wqy=0;wqy<256;wqy++)//DA0 output
{
DAC0H = wqy;
for(timer0_10ms=0;timer0_10ms<30;);
if(wqy>=256) wqy=0;
}
//-----------------------------------------------
ad:
iu_channel_select(1);//iu1
ad_channel_select(1);//ad1
while(1)
{
i=ad_sampling(); // 连续20毫秒采样,去坏点,求平均值
sp_out( hex_askii((uchar)((i>>12)&0x000f)) );
sp_out( hex_askii((uchar)((i>>8)&0x000f )) );
sp_out( hex_askii((uchar)((i>>4)&0x000f )) );
sp_out( hex_askii((uchar)( i&0x000f )) );
sp_out(0x0d);
sp_out(0x0d);
for(timer0_10ms=0;timer0_10ms<10;); // 采样间隔100毫秒
}
//-----------------------------------------------
uart:
while(1) // 连续发送“Very Good!”
{sp_out('V');
sp_out('e');
sp_out('r');
sp_out('y');
sp_out(0x0d);
sp_out('G');
sp_out('o');
sp_out('o');
sp_out('d');
sp_out('!');
sp_out(0x0d);
sp_out(0x0a);
for(timer0_10ms=0;timer0_10ms<100;);
}
//-----------------------------------------------
//“设置” 键值为1 “UP” 键值为2 “查看” 键值为3 “翻屏”键值为4
//“LEFT” 键值为5 “确认”键值为6 “RIGHT”键值为7 “测量”键值为8
//“Shift”键值为9 “DOWN”键值为10 “DEL” 键值为11 “密码”键值为12
mainprog:
clear_lcd(0,0,0);
menu_selftest(); // 显示文本“系统正在自检...”
//for(timer0_10ms=0;timer0_10ms<100;); // 延时1秒
init_program_parameter(); // 用24WC256中的数据初始化系统运行参数
volt_ab_present_measure=0;
volt_bc_present_measure=0;
volt_ca_present_measure=0;
menu_wait();// 显示“启动前循环监测静态界面”
PCA0CPH0=5; // 保证系统安全
while(1) // ---------------电机启动前循环检测--------------
{
if(bp_fault_flag==1)
{out_bgt=0;
xianshi_spaces_hanzi(7,12,infor_hanzi35,2); // 显示变频器状态:“异常”
}
else xianshi_spaces_hanzi(7,12,infor_hanzi34,2);// 显示变频器状态:“正常”
iu_channel_select(1);//iu1
ad_channel_select(1);//ad1
i=ad_sampling();
volt_ab_present_measure=(float)(i)*500/4095 + u_ab_compensate;
if((volt_ab_present_measure>volt_max_set)||(volt_ab_present_measure<volt_min_set))
{volt_ab_fault_counter+=1;} // 电压异常时电压故障计数器加1
else volt_ab_fault_counter=0;
iu_channel_select(2);//iu2
ad_channel_select(1);//ad1
i=ad_sampling();
volt_bc_present_measure=(float)(i)*500/4095 + u_bc_compensate;
if((volt_bc_present_measure>volt_max_set)||(volt_bc_present_measure<volt_min_set))
{volt_bc_fault_counter+=1;} // 电压异常时电压故障计数器加1
else volt_bc_fault_counter=0;
iu_channel_select(3);//iu3
ad_channel_select(1);//ad1
i=ad_sampling();
volt_ca_present_measure=(float)(i)*500/4095 + u_ca_compensate;
if((volt_ca_present_measure>volt_max_set)||(volt_ca_present_measure<volt_min_set))
{volt_ca_fault_counter+=1;} // 电压异常时电压故障计数器加1
else volt_ca_fault_counter=0;
xianshi_spaces_data(1,15,3,0,volt_ab_present_measure,1);//显示ab相电压瞬时值
xianshi_spaces_data(2,15,3,0,volt_bc_present_measure,1);//显示bc相电压瞬时值
xianshi_spaces_data(3,15,3,0,volt_ca_present_measure,1);//显示ca相电压瞬时值
if(volt_ab_fault_counter>2) // 如果电压故障连续10次以上(时间<3s),则置电压故障标志
{volt_ab_fault_flag=1;}
if(volt_bc_fault_counter>2)
{volt_bc_fault_flag=1;}
if(volt_ca_fault_counter>2)
{volt_ca_fault_flag=1;}
if(volt_ab_fault_flag||volt_bc_fault_flag||volt_ca_fault_flag)
{ out_jt=0;
xianshi_spaces_hanzi(4,12,infor_hanzi35,2);//显示“异常”
}
else xianshi_spaces_hanzi(4,12,infor_hanzi34,2);//显示“正常”
if(in_bp_start==0) // 变频启动
{for(timer0_10ms=0;timer0_10ms<50;); // 500毫秒消抖
if(in_bp_start==0)
{bp_start_flag=1;
break;
}
}
if(in_gp_start==0) // 工频启动
{for(timer0_10ms=0;timer0_10ms<50;); // 500毫秒消抖
if(in_gp_start==0)
{gp_start_flag=1;
break;
}
}
if(key_value_main==1) //“设置”键处理
{for(timer0_10ms=0;timer0_10ms<20;);
key_value_main=0;
menu_setup();
menu_wait();
}
/*
if(key_value_main==3) //“查看”键处理
{key_value_main=0;
key_look_dispose();
}
if(key_value_main==3) //“翻页”键处理
{key_value_main=0;
key_browse_page_dispose();
}
if(key_value_main==12) //“密码”键处理
{key_value_main=0;
key_password_dispose();
}
*/
} // 电机启动前循环检测结束
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
if(bp_start_flag==1) // ----------------变频启动处理---------------
{
clear_lcd(0,0,0);
menu_bp_before_run();// 显示文本“变频启动监测...”
if(bp_study_flag==0) // 根据标志确定是否学习
{
PCA0CPL0 = 5;
PCA0CPH0 = 5; // 给最小PWM输出,学习最小冲次数
for(timer0_10ms=0;timer0_10ms<(uint)((float)(bp_start_delay)*100);); // 延时“变频器加速时间”
xianshi_spaces_hanzi(6,10,infor_hanzi54,7);//显示“学习最小冲次数”
wz1_fault_timer=0;
wz1_fault_flag=0;
wz1_touch_flag=0;
while(1) // 等待周期测量开始
{if(wz1_touch_flag==1) // 第一次检测到位置传感器1可靠触发标志,清空周期测量计时器
{cycle_measure_timer=0;
xianshi_hanzi_dan(6,18,85);//显示“一”
for(timer0_10ms=0;timer0_10ms<100;);//delay 1s
break;
}
if(wz1_fault_flag==1) break; // 如果位置传感器1故障则退出
if(in_bp_start==1) break; // 如果变频启动信号撤消则退出循环
}
wz1_touch_flag=0;
if(wz1_fault_flag!=1) // 如果位置传感器正常则继续学习
{while(1)
{if(wz1_touch_flag==1) // 再次检测到位置传感器1可靠触发标志,周期测量结束
{chongci_num_min=(uint)(60000/cycle_measure_timer); // 计算实测最小冲次数(已经乘10)
xianshi_hanzi_dan(6,18,86);//显示“二”
for(timer0_10ms=0;timer0_10ms<100;);//delay 1s
break;
}
if(wz1_fault_flag==1) break; // 如果位置传感器1故障则退出
if(in_bp_start==1) break; // 如果变频启动信号撤消则退出循环
}
}
PCA0CPL0 = 255;
PCA0CPH0 = 255; // 给最大PWM输出,学习最大冲次数
for(timer0_10ms=0;timer0_10ms<(uint)((float)(bp_start_delay)*100);); // 延时“变频器加速时间”
xianshi_spaces_hanzi(6,10,infor_hanzi55,9);//显示“学习最大冲次数”
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -