📄 timer.h
字号:
unsigned char sleep_count=0;
//**************************定时器初始化函数OK***********************************
static void Init_TBM(void) //时基定时器
{
TBCR_TBIE =1; //2 基础定时器中断使能
TBCR_TACK =1; //3 TBM中断标志清除
TBCR_TBR0 =1;
TBCR_TBR1 =1;
TBCR_TBR2 =0; //分频系数16384,4.096ms
/* TBR2 TBR1 TBR0 Divider Tap
TMBCLKSEL
0 1
0 0 0 32,768 4,194,304
0 0 1 8192 1,048,576
0 1 0 2048 262144
0 1 1 128 16,384
1 0 0 64 8192
1 0 1 32 4096
1 1 0 16 2048
1 1 1 8 1024
*/
TBCR_TBIF =1; //7 中断标志
TBCR_TBON =1; //0 启动定时器
//2E 0010 1110
}
//**************************定时器中断函数***********************************
void interrupt 17 INT_TBM(void) //4.096ms
{
//系统指示灯
LED_count++;
if(LED_count==122) //0.5s
{
LED_count=0;
LED=!LED; //工作指示灯
fault_flag=1; //MC33984故障检测标志
fault_clk=1; //MC33984故障清除标志
}
//喂狗、开关量检测
dog_count++;
if(dog_count==27) //110ms
{
dog_count=0;
Dog_MC33389(); //MC33389喂狗
Dog_MC33984(); //MC33984喂狗
RD33993(0x00,0x00,0x00); //MC33993状态检测
MC33993_FLAG=1; //检测完成标志
if(can_yb_flag)
{
INC_WAKE=0; //检测与仪表通信
can_yb_flag=0;
}
else if(INC_WAKE) can_yb_flag=1;
if(can_qkz_flag)
{
VACC_WAKE=0; //检测与前控左通信
can_qkz_flag=0;
}
else if(VACC_WAKE) can_qkz_flag=1;
}
//门电磁阀 工作1s
if(door_flag)
{
door_count++;
if(door_count==244)
{
door_count=0;
door_flag=0;
MC33984_OUT[6].Byte=0x1a;
}
}
//休眠、唤醒
if(VACC_WAKE||INC_WAKE||DOOR_WAKE)
{
//CAN通信
can_comm_count++;
if(can_comm_count==11)
{
CAN_CMD(); //45ms发送CAN命令
DOOR_WAKE=0;
}
else if(can_comm_count==12)
{
can_comm_count=0;
CAN_STR(); //50ms发送CAN状态
}
//雨刮间歇
if(CAN_YB1.Bit.BIT0==1&&CAN_YB1.Bit.BIT1==0)
{
if(rain_int==0)
{
xidi_flag=0;
xidi_count=0;
rain_stop=1;
if(MC33984_fault2.Bit.BIT3) MC33984_OUT[5].Byte=0x1a;
else MC33984_OUT[5].Byte=0x1e;
rain_int=1;
rain_brush=1;
int_time=0;
}
if(rain_stop&&++stop_count==122) //0.5s
{
stop_count=0;
rain_stop=0;
}
if(rain_stop==0)
{
if(SGH_status.Bit.BIT4) MC33984_OUT[5].Byte=0x1a;
if(MC33984_OUT[5].Byte==0x1a&&++int_count==61)
{
int_count=0;
if(++int_time>=CAN_YB7.Byte) rain_int=0;
}
}
}
/* if(rain_int)
{
if(rain_stop&&++stop_count==122)
{
rain_stop=0;
stop_count=0;
}
if(rain_stop==0)
{
if(SGH_status.Bit.BIT4) MC33984_OUT[5].Byte=0x1a;
if(++int_count==244)
{
int_count=0;
if(--int_time==0)
{
rain_int=0;
}
}
}
rain_stop=1;
if(rain_stop) //延时0.5s检测到位信号
{
if(stop_count==122) //0.5s
{
stop_count=0;
rain_stop=0;
}
else stop_count++;
}
else
{
if(SGH_status.Bit.BIT4) //到位后停止雨刮
{
if(MC33984_OUT[5].Byte!=0x1a)
{
int_clk=0;
MC33984_OUT[5].Byte=0x1a;
}
if(int_clk) //雨刮间歇
{
int_clk=0;
if(++int_count==int_time) rain_int=0; //间歇时间为0.5s倍数
}
}
}
}
*/ //MC33984故障检测
if(fault_flag&&fault_ok==0) FAULT_MC33984(); //0.5s
}
else if(MC33984_OUT[5].Byte!=0x1a) //雨刮在工作
{
if(SGH_status.Bit.BIT4) MC33984_OUT[5].Byte=0x1a; //到位后停止雨刮
}
else if(door_flag==0&&can_yb_flag==0&&can_qkz_flag==0) //门停止工作,且无CAN接收
{
Sleep_33984(); //MC33984睡眠
Sleep_33993(); //MC33993睡眠
Sleep_33389(); //MC33389睡眠
}
//MC33984端口刷新
out_count++;
if(out_count==11) //45ms
{
out_count=0;
Out_MC33984();
}
TBCR_TACK =1; //清除中断标志
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -