📄 m8.c
字号:
set_led_r;
//等待手动设置
while (sb_xc_fs)
{
//扫描按键
subpr_sbw_scan();
//扫描无线
if (subpr_rif()==0)
{
//有信号
subpr_rif_ok();
}
}
//设置终点
eep_xc_open=xc_currently;
//等待放手
clr_led_r;
while (sb_xc_ax)
{
//等待放手
subpr_yms_com(2);
}
set_led_r;
subpr_yms_com(4);
clr_led_r;
*/
}
else if (com_timer1>=3)
{
//执行自动设置
//bit_xc_man=0;
subpr_xc_config(); //调用行程设置
}
else
{
//时间未到,无执行
set_led_r;
subpr_yms_com(4);
clr_led_r;
}
}
//******************函数*******************
//无线处理SUBPR_RIF_OK
void subpr_rif_ok(void)
{
//接收正确处理
if (subpr_eep_check()==cst_window_have) //调用通道检察
{
//通道存在,测试操作码
switch (rif_val[3])
{
case (cst_rif_open):
{
//开指令
subpr_out_control(cst_out_open);
ip_timer=0;
}
break;
case (cst_rif_stop):
{
//停止指令
if (j1_out_true||j2_out_true)
{
set_led_r;
j1_close;
j2_close;
xc_work_old=cst_out_free;
subpr_yms_com(2);
}
ip_timer=0;
}
break;
case (cst_rif_close):
{
//关指令
subpr_out_control(cst_out_close);
ip_timer=0;
}
break;
case (cst_rif_sel_open):
{
//运行至IP1
subpr_out_control(cst_out_ip1);
ip_timer=0;
}
break;
case (cst_rif_sel_close):
{
//运行至IP2
subpr_out_control(cst_out_ip2);
ip_timer=0;
} ;break;
case (cst_rif_st_open):
{
//设定IP1
ip_timer++;
if (ip_timer>=20)
{
//设置当前位置为IP1
eep_xc_ip1=xc_currently;
eep_xc_ip1_sram=xc_currently;
subpr_out_control(cst_out_open); //IP1设置成功执行开
ip_timer=0;
}
}
break;
case (cst_rif_st_close):
{
//设定IP2
ip_timer++;
if (ip_timer>=20)
{
//设置当前位置为IP1
eep_xc_ip2=xc_currently;
eep_xc_ip2_sram=xc_currently;
subpr_out_control(cst_out_close); //IP2设置成功执行关
ip_timer=0;
}
}
break;
case (cst_rif_learn):
{
//重设行程
ip_timer++;
if (ip_timer>=30)
{
//自动时间到
set_led_r;
subpr_mot_wink();
//测试手动时间
subpr_rif_wait_test(cst_rif_learn);
//判断设置方式
if (ip_timer<60)
{
//自动方式
//bit_xc_man=0;
subpr_xc_config();
}
else
{
//手动方式
//bit_xc_man=1;
//subpr_xc_config();
//清除行程
subpr_clr_xc();
subpr_mot_wink();
}
clr_led_r;
ip_timer=0;
}
}
break;
case (cst_rif_sel_stop):
{
ip_timer++;
if (ip_timer>=50)
{
//清除行程
subpr_clr_xc();
ip_timer=0;
}
}
break;
default:
{
//未知或无效指令
ip_timer=0;
}
}
}
}
//*************************************
//**********主程序开始*****************
//*************************************
void main(void)
{
// Declare your local variables here
// 局部变量
//unsigned char rif_result;
// Reset Source checking
// 复位来源测试
if (MCUCSR & 1)
{
// Power-on Reset
// 电上复位
MCUCSR=0;
// Place your code here
}
else if (MCUCSR & 2)
{
// External Reset
// 外部复位
MCUCSR=0;
// Place your code here
}
else if (MCUCSR & 4)
{
// Brown-Out Reset
// 低电压复位
MCUCSR=0;
// Place your code here
}
else
{
// Watchdog Reset
// 看门狗复位
MCUCSR=0;
// Place your code here
};
// Input/Output Ports initialization
// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=Out Func1=Out Func0=In
// State7=P State6=P State5=P State4=P State3=P State2=0 State1=0 State0=T
PORTB=b1111_1111;
DDRB =b0000_0000;
// Port C initialization
// Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State6=P State5=P State4=P State3=P State2=P State1=P State0=P
PORTC=b1101_1111;
DDRC =b0010_0000;
// Port D initialization
// Func7=In Func6=In Func5=Out Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=P State6=P State5=0 State4=T State3=T State2=T State1=P State0=P
PORTD=b0000_0011;
DDRD =b0110_0000;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: 7.813 kHz
TCCR0=cst_tccr0;
TCNT0=cst_tcnt0;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 31.250 kHz
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: On
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=cst_tccr1b;
TCNT1H=cst_tcnt1h;
TCNT1L=cst_tcnt1l;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: 7.813 kHz
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=cst_tccr2;
TCNT2=cst_tcnt2;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: On
// INT0 Mode: Low level
// INT1: On
// INT1 Mode: Any change
//GICR|=0xC0;
//MCUCR=0x04;
//GIFR=0xC0;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x45;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// Watchdog Timer initialization
// Watchdog Timer Prescaler: OSC/2048k
#pragma optsize-
WDTCR=0x1F;
WDTCR=0x0F;
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif
// Global enable interrupts
bit_xc_change=0; //行程变化标志
#asm("sei")
//-------------------------------
//开机指示灯亮度3秒关3秒
//相当于廷时启动6秒
set_led_r;
subpr_ys_com(5);
clr_led_r;
subpr_ys_com(1);
//-------------------------------
//开机检测按键状态
if (sbw_open_ax)
{
bit_sbw_open=cst_sbw_ax;
}
else
{
bit_sbw_open=cst_sbw_fs;
}
if (sbw_close_ax)
{
bit_sbw_close=cst_sbw_ax;
}
else
{
bit_sbw_close=cst_sbw_fs;
}
//----------------------------------
//开机检测EEPROM
if (eep_first_work!=cst_first_work)
{
//第一次开机,初始化EEPROM
subpr_eep_clr();
}
//----------------------------------
//读取开关类型标志
if (eep_sbw_sort==cst_sbw_k)
{
bit_sbw_sort=cst_sbw_k;
}
else
{
bit_sbw_sort=cst_sbw_sb;
}
//----------------------------------
//读取当前行程
xc_currently=eep_xc_currently[eep_xc_ptr];
subpr_xc_copy();
//开外部中断
CLI();
NOP();
GICR|=0xC0;
MCUCR=0x04;
GIFR=0xC0;
NOP();
SEI();
//初始化完成
subpr_ys_com(1);
subpr_led_wink(1,1);
//*****************************************
//**************主程序循环*****************
//*****************************************
while (1)
{
// Place your code here
//clr_led_r;
WDR();
SEI();
//com_led_r;
//--------------------------------
//按键扫描
//--------------------------------
subpr_sbw_scan();
//---------------------------------
//通道设置按键
if (sb_w_learn_ax)
{
set_led_r;
subpr_yms_com(2);
if (sb_w_learn_ax)
{
//通道设置处理
clr_led_r;
subpr_sb_w_learn_ax();
}
clr_led_r;
}
//---------------------------------
//行程设置按键
if (sb_xc_ax)
{
set_led_r;
subpr_yms_com(2);
if (sb_xc_ax)
{
//行程设置处理
clr_led_r;
subpr_sb_xc_ax();
}
clr_led_r;
}
//无线扫描
if (subpr_rif()==0)
{
//接收正确处理
subpr_rif_ok();
clr_led_r;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -