📄 m8.c
字号:
xc_work_old=cst_out_free;
}
//测试是否为中间定位
if (xc_work_old==cst_out_ip1)
{
if (xc_currently==eep_xc_ip1_sram)
{
j1_close;
j2_close;
bit_xc_tsend=1;
xc_work_old=cst_out_free;
}
}
else if (xc_work_old==cst_out_ip2)
{
if (xc_currently==eep_xc_ip2_sram)
{
j1_close;
j2_close;
bit_xc_tsend=1;
xc_work_old=cst_out_free;
}
}
}
else if (mot_dec)
{
//清除行程控制定时器
com_timer2=0;
xc_currently--;
if (eep_xc_close_sram>=xc_currently)
{
j1_close;
j2_close;
bit_xc_tsend=1;
xc_work_old=cst_out_free;
}
//测试是否为中间定位
if (xc_work_old==cst_out_ip1)
{
if (xc_currently==eep_xc_ip1_sram)
{
j1_close;
j2_close;
bit_xc_tsend=1;
xc_work_old=cst_out_free;
}
}
else if (xc_work_old==cst_out_ip2)
{
if (xc_currently==eep_xc_ip2_sram)
{
j1_close;
j2_close;
bit_xc_tsend=1;
xc_work_old=cst_out_free;
}
}
}
WDR();
}
//===================中断====================
// Timer 0 overflow interrupt service routine
// 通用短定时中断,25.088(错开)毫秒
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
// Reinitialize Timer 0 value
TCNT0=cst_tcnt0;
// Place your code here
//WDR();
com_timer0++;
}
//===================中断====================
// Timer 1 overflow interrupt service routine
// 通用长定时中断,1秒
interrupt [TIM1_OVF] void timer1_ovf_isr(void)
{
// Reinitialize Timer 1 value
TCNT1H=cst_tcnt1h;
TCNT1L=cst_tcnt1l;
// Place your code here
//WDR();
com_timer1++;
//com_led_r;
//测试外控按键是否按下
if ((sbw_open_ax||sbw_close_ax)&&(bit_sbw_sort==cst_sbw_sb))
{
//有按键,按下时间记录寄存器+1
if (sbw_ax_timer1<8)
{
sbw_ax_timer1++;
}
else
{
set_led_r;
//WDR();
}
}
}
//===================中断====================
// Timer 2 overflow interrupt service routine
// 运行控制定时器中断,25毫秒(32.768ms)
interrupt [TIM2_OVF] void timer2_ovf_isr(void)
{
// Reinitialize Timer 2 value
//TCNT2=cst_tcnt2;
// Place your code here
//WDR();
com_timer2++;
//测试定时是否到
if (j1_out_true||j2_out_true)
{
if (com_timer2>=20)
{
j1_close;
j2_close;
xc_work_old=cst_out_free;
bit_xc_tsend=1;
com_timer2=0;
}
}
}
//把EEPROM中的行程数据读取到SRAM中
void subpr_xc_copy(void)
{
eep_xc_sum_sram=eep_xc_sum;
eep_xc_open_sram=eep_xc_open;
eep_xc_close_sram=eep_xc_close;
eep_xc_ip1_sram=eep_xc_ip1;
eep_xc_ip2_sram=eep_xc_ip2;
}
//******************函数*******************
//廷时ms
void subpr_yms_com(unsigned char com_timer0_cp)
{
com_timer0=0;
//置T0保证廷时准确
TCCR0=cst_tccr0;
while (com_timer0<com_timer0_cp)
{
//等待廷时25ms*com_timer
WDR();
}
}
//******************函数*******************
//廷时s
void subpr_ys_com(unsigned char com_timer1_cp)
{
com_timer1=0;
TCNT1H=cst_tcnt1h;
TCNT1L=cst_tcnt1l;
while (com_timer1<com_timer1_cp)
{
//等待廷时1s*com_timer
WDR();
}
}
//******************函数*******************
//廷时ms
void subpr_yms2_com(unsigned char com_timer3_cp)
{
com_timer2=0;
TCNT2=200;
while (com_timer2<com_timer3_cp)
{
//等待廷时25ms*com_timer
WDR();
}
}
//******************函数*******************
//LED闪烁
void subpr_led_wink(unsigned char led_wink,unsigned char mot_wink)
{
//闪烁次数为LED_WINK
while (led_wink!=0)
{
com_led_r;
delay_ms(200);
com_led_r;
delay_ms(200);
led_wink--;
while (mot_wink!=0)
{
if (get_1(SREG,7))
{
subpr_mot_wink();
}
mot_wink--;
}
}
clr_led_r;
}
//******************函数******************
//电机抖动
void subpr_mot_wink(void)
{
j1_close;
j2_close;
delay_ms(50);
j1_out;
delay_ms(50);
j1_close;
delay_ms(50);
j2_out;
delay_ms(50);
j2_close;
delay_ms(50);
}
//******************函数*******************
//EEPROM初始化操作
void subpr_eep_clr(void)
{
//测试是否已经运行过
//如果运行过则为通道清除操作
//清除通道(窗号)
unsigned char i;
unsigned char j;
set_led_r;
eep_window_ptr=0;
for (i=0;i<16;i++)
{
for (j=0;j<3;j++)
{
eep_window[i][j]=0;
} //清除窗号数组
eep_empty[i]=0;
}
if (eep_first_work!=cst_first_work)
{
//第一次运行,初始化EEPROM
eep_sbw_sort=cst_sbw_sb; //开关类型
eep_out_j12=cst_out_j12_false; //输出换向
eep_xc_sum=cst_xc_sum; //行程相关
eep_xc_open=cst_xc_open;
eep_xc_close=cst_xc_close;
eep_xc_ip1=cst_xc_open;
eep_xc_ip2=cst_xc_close;
eep_xc_ptr=0;
for (i=0;i<200;i++)
{
//清除当前行程记录数组
eep_xc_currently[i]=cst_xc_currently;
}
//标志已经工作过标志
eep_first_work=cst_first_work;
}
subpr_led_wink(5,5);
}
//******************函数*******************
//通道核对,如果有返回0,没有返回1
unsigned char subpr_eep_check(void)
{
unsigned char i;
unsigned char j;
unsigned char check_result;
for (i=0;i<16;i++)
{
for (j=0,check_result=0;j<3;j++)
{
if (eep_window[i][j]==rif_val[j])
{
//相等+1
check_result++;
}
}
//测试是否全相等
if (check_result==3)
{
//相等置退数
i=16;
}
}
//测试完成,测试返回值
if (check_result==3)
{
check_result=cst_window_have; //通道存在
}
else
{
check_result=cst_window_null; //通道不存在
}
return (check_result); //返回结果
}
//******************函数*******************
//输出开
void subpr_rif_wait_test(unsigned char rif_wait_test)
{
//等待遥控器按键放开
com_timer1=0;
TCNT1H=cst_tcnt1h;
TCNT1L=cst_tcnt1l;
while (com_timer1<3)
{
if (subpr_rif()==0)
{
if (rif_val[3]==rif_wait_test)
{
if (subpr_eep_check()==cst_window_have)
{
com_timer1=0;
TCNT1H=cst_tcnt1h;
TCNT1L=cst_tcnt1l;
if (ip_timer>=30)
{
if (ip_timer==60)
{
//手动时间到
subpr_mot_wink();
subpr_mot_wink();
ip_timer++;
}
else if (ip_timer>=60)
{
clr_led_r;
subpr_yms_com(2);
}
else
{
ip_timer++;
}
}
}
}
}
else
{
set_led_r;
}
WDR();
}
}
//******************函数*******************
//输出开
void subpr_out_open(void)
{
//清除定时监控
com_timer2=0;
bit_xc_change=1; //运行标志
if (eep_out_j12==cst_out_j12_true)
{
j2_out;
}
else
{
j1_out;
}
}
//******************函数*******************
//输出关
void subpr_out_close(void)
{
//清除定时监控
com_timer2=0;
bit_xc_change=1; //运行标志
if (eep_out_j12==cst_out_j12_true)
{
j1_out;
}
else
{
j2_out;
}
}
//******************函数*******************
//输出处理
void subpr_out_control(unsigned char out_task)
{
//测试任务是否相同,相同则退出&&行程是否设置
if (xc_work_old!=out_task) //&&(eep_xc_sum!=0)
{
subpr_xc_copy();
//任务不同,执行新任务
xc_work_old=out_task; //保存即将要执行的任务
//bit_xc_change=1; //运行标志
set_led_r; //指示灯发光指示
//测试是否有输出,有则关闭
if (j1_out_true||j2_out_true)
{
//关闭输出
j1_close;
j2_close;
subpr_ys_com(2);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -