📄 jac-ets.c
字号:
else
{
if(back_store_sw)//后备箱开
{
store_state_sw_flag=1;
}
else if(store_state_sw_flag)
{
store_state_sw_flag=0;
tx_open_store_flag=0;
}
}
//==========报警处理
if(warn_state)
{
if(flash_cycle>0)
{
if(flash_time==0)
{
if(!flash_on)
{
flash_on=1;
flash_time=FLASH_ON_TIME;
}
else
{
flash_on=0;
flash_time=FLASH_OFF_TIME;
flash_cycle--;
}
}
}
if(entrance_sw&&(!entrance_flag)&&(!warn_cycle))//入口
{
entrance_flag=1;
warn_entrance_flag=1;
flash_cycle=27;
flash_on=1;
flash_time=FLASH_ON_TIME;
warn_on=1;
warn_cycle=3;
warn_time=WARN_ON_TIME3;
}
else if(!entrance_sw)
{
entrance_flag=0;
}
if(warn_entrance_flag)
{
if(warn_cycle>0)
{
if(warn_time==0)
{
if(!warn_on)
{
warn_on=1;
warn_time=WARN_ON_TIME3;//27s
flash_cycle=27;;
}
else
{
flash_on=0;
warn_on=0;
flash_time=WARN_OFF_TIME3;//10s
warn_time=WARN_OFF_TIME3;//10s
warn_cycle--;
}
}
}
}
}
else
{
if(!flash_time)
flash_on=0;
}
//=============当钥匙ON时30S后取消报警状态
if(warn_state&&warn_on)
{
if(on_sw&&(!on_sw_flag3))
{
on_sw_flag3=1;
flash_on=0;
flash_cycle=0;
warn_cycle=0;
warn_time=DELAY_30S;//30s
}
else if(on_sw_flag3&&(warn_time==0))
{
on_sw_flag3=0;
warn_state=0;
warn_on=0;
start_inhibit_relay=0;
}
}
// if(!(driver_door_sw|engineer_sw|back_store_sw))
/* if(!engineer_sw)
{
if(!warn_on)
{
if(lock_state&&(!warn_state))
{
warn_state=1;
flash_time=FLASH_TIME;
flash_on=1;
flash_cycle=2;
}
else if(lock_state&&warn_state)
{
if(flash_cycle>0)
{
if(flash_time==0)
{
flash_time=FLASH_TIME;
flash_on=!flash_on;
if(!flash_on)
flash_cycle--;
}
}
}
if((flash_cycle==0)&&(flash_time==0))
flash_on=0;
}
}
if(lock_time==0)
{
lock_ctrl=0;
ulock_ctrl=0;
if(!(tx_lock_signal|tx_ulock_signal))
tx_lock_flag=0;
}
if(store_time==0)
{
store_ctrl=0;
if(!(tx_store_signal))
tx_store_flag=0;
if(store_uwarn_flag)
{
if((!store_state_sw)&&(!store_state_sw_flag))
{
store_state_sw_flag=1;
store_warn_delay_time=STORE_WARN_DELAY_TIME;//2s
}
else if ((!store_state_sw)&&(store_warn_delay_time==0))
{
warn_on=1;
store_uwarn_flag=0;
}
}
}
//====报警功能
entrance_sw=!PORTB_6;
if(entrance_sw&&(!entrance_sw_flag))
{
entrance_sw_flag=1;
warn_cycle=3;
}
if(warn_state)
{
if(entrance_sw_flag)
{
if((warn_cycle>0)&&(!warn_door))
{
if(warn_time==0)
{
if(!warn_on)
{
warn_on=1;
warn_time=WARN_ON_TIME;
}
else
{
warn_on=0;
warn_time=WARN_OFF_TIME;
warn_cycle--;
flash_on=0;
}
}
}
else if(!warn_door)//warn_cycle=0
{
warn_on=0;
flash_on=0;
entrance_sw_flag=0;
}
else//warn_door=1
{
warn_on=1;
if(onkey&&(!onkey_warn_flag))
{
onkey_warn_flag=1;
warn_time=600;
}
else if(onkey_warn_flag)
{
if(warn_time==0)
{
warn_on=0;
entrance_sw_flag=0;
onkey_warn_flag=0;
}
}
}
}
}
else
{
entrance_sw_flag=0;
warn_cycle=0;
}
if(warn_on)
{
if(flash_time==0)
{
flash_time=FLASH_TIME;
flash_on=!flash_on;
}
}
*/
//=========
}
}
void time0_init(void)
{
T0CS=0;
OPTION=0x07;
GIE=1;
PEIE=1;
T0IE=1;
T0IF=0;
TMR0=0X3C;
}
void time1_init(void)
{
T1CON=0X00;
TMR1H=TMR1_H;
TMR1L=TMR1_L;
TMR1IE=0;
PEIE=0;
TMR1IF=0;
TMR1ON=0;
}
/*****************/
void interrupt Time0_int(void)
{
//if(TMR1IF)
{
// TMR1IF=0;
// TMR1H=TMR1_H;
// TMR1L=TMR1_L;
}
if(T0IF)
{
T0IF=0;
TMR0=0X3C;
if(testtime>0) testtime--;
if(light_key_timer>0) light_key_timer--;
if(remove_fro_timer>0) remove_fro_timer--;
if(sound_timer>0) sound_timer--;
if(water_sw_time>0) water_sw_time--;
if(RstPointRain>0) RstPointRain--;
if(rain_timer>0) rain_timer--;
if(safe_belt_led_t>0) safe_belt_led_t--;
if(safe_belt_sound_t>0) safe_belt_sound_t--;
if(power_windows_t>0) power_windows_t--;
if(chime_bell_t>0) chime_bell_t--;
if(tail_light_out_t>0) tail_light_out_t--;
// if(delay_time_30s>0) delay_time_30s--;
if(lock_out_t>0) lock_out_t--;
if(store_out_t>0) store_out_t--;
if(unlock_out_t>0) unlock_out_t--;
if(flash_time>0) flash_time--;
if(warn_time>0) warn_time--;
if(store_warn_delay_time>0) store_warn_delay_time--;
if(CCPR1L>0) CCPR1L--;
if(speed_cleartime>0)
{
// speedresult_last=0;
speed_cleartime--;
}
else
{
timer1h=0;
timer1l=0;
speedresult=0;
}
if(rain_water_sw_begin)
{
if(rain_water_sw_t<200 )
rain_water_sw_t++;
}
if(speed_over_40km_flag)
{
if(speed_over_40km_t<200 )
speed_over_40km_t++;
}
if(warningflash_time>0)
{
warningflash_time--;
}
if(warningstop_time>0)
{
warningstop_time--;
}
/*
if(!all_door_lock_flag)
{
if(all_door_unlock_t<200 )
all_door_unlock_t++;
}
*/
}
else if(INTF)
{
INTF=0;
if(extcount==0)
{
TMR1H=0;
TMR1L=0;
TMR1ON=1;
}
if(extcount==1)
{
timer1h=TMR1H;
timer1l=TMR1L;
timer1h=timer1h<<8;
speedtimer1=timer1h+timer1l;
speedresult=(unsigned char)(1000000/speedtimer1);
if(speedresult>230)
{
speedresult=230;
}
speedresult=speedresult*141/100;
speed_cleartime=20;
TMR1ON=0;
}
extcount=extcount+1;
if(extcount==2)
{
extcount=0;
}
}
}
void safe_belt_init_ctrl(void)
{
safe_belt_led=1;
safe_belt_led_t=6;//0.3s
safe_belt_led_c=9;//周期
safe_belt_sound=1;
safe_belt_sound_t=9;//0.45s
safe_belt_sound_c=6;//周期
}
void safe_belt_led_ctrl(void)
{
if(safe_belt_led_t==0)
{
safe_belt_led_t=6;//0.3s
if(safe_belt_led)
safe_belt_led=0;
else
if(safe_belt_led_c>0)//10 cycle is 6s
{
safe_belt_led=1;
safe_belt_led_c--;
}
}
}
void safe_belt_sound_ctrl(void)
{
if(safe_belt_sound_t==0)
{
safe_belt_sound_t=9;//0.45s
if(safe_belt_sound)
safe_belt_sound=0;
else
if(safe_belt_sound_c>0)//7 cycle is 6.3s
{
safe_belt_sound=1;
safe_belt_sound_c--;
}
}
}
void CCP1INIT(void)
{
CCPR1L=0X00;
CCP1CON=0X0C; //设置CCP1模块为PWM工作方式,且其工作,循环的低2位为00,高8位为01100000=60
INTCON=0X00; //禁止总中断和外围中断
PR2=0X92; //设置PWM的工作周期
TRISC&=0XFB; //设置CCP1引脚为输出方式
}
/*
void IOINIT(void)
{
TRISA=0XFF;
TRISB=0xF0;
RBPU=0;
TRISC=0X01;
}
*/
void write_74hc595(unsigned char d)
{
unsigned char i,j;
for(i=0;i<8;i++)
{
SRCLK_595=0;
b=0;
if(d&0x80)
b=1;
SER_595=b;
d<<=1;
SRCLK_595=1;
}
}
unsigned char Sort_Port_Bit(uchar d0,uchar d1,uchar d2,uchar d3,
uchar d4,uchar d5,uchar d6,uchar d7)
{
unsigned char PortBuffer;
PortBuffer=(PortBuffer&0x7f)|(d7<<7);
PortBuffer=(PortBuffer&0xbf)|(d6<<6);
PortBuffer=(PortBuffer&0xdf)|(d5<<5);
PortBuffer=(PortBuffer&0xef)|(d4<<4);
PortBuffer=(PortBuffer&0xf7)|(d3<<3);
PortBuffer=(PortBuffer&0xfb)|(d2<<2);
PortBuffer=(PortBuffer&0xfd)|(d1<<1);
PortBuffer=(PortBuffer&0xfe)|d0;
return(PortBuffer);
}
void exint0_init(void)
{
INTEDG=0;
INTE=1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -