📄 main.c
字号:
/******************************************/
/**file name: right_front node program **/
/**Author :Xiaoming Li **/
/**date/time: 13.3.2004 **/
/**company: Tongji university **/
/******************************************/
#include <MC68HC908GZ16.H>
#include <hidef.h>
#include <signal_group.h>
#define WT 5000
#define LT 2000
#define MT 4000
unsigned int CAN_timer_count=0;
unsigned int count=0;
unsigned int SPI_count=0;
unsigned int rf_up_count=0;
unsigned int rf_dn_count=0;
unsigned int window_position=0;
unsigned int mirror_x_position=2000;
unsigned int mirror_y_position=2000;
unsigned int lock_moto_count=0;
unsigned char rf_button_sta[4]={0,0,0,0};
unsigned char rf_butt_sta1[4]={0,0,0,0};
unsigned char rf_butt_sta2[4]={0,0,0,0};
unsigned int inlock1=0;
unsigned int inlock2=0;
unsigned int inlock=0;
unsigned int outlock1=0;
unsigned int outlock2=0;
unsigned int outlock=0;
unsigned int rflock1=0;
unsigned int rflock2=0;
unsigned int rflock=0;
unsigned int judge=0;
unsigned int speedlock=0;
unsigned int speedlock1=0;
unsigned int speedlock2=0;
unsigned char PWM_flag1=0;
unsigned char PWM_flag2=0;
unsigned char PWM_flag3=0;
unsigned char PWM_flag4=0;
unsigned char T2_CH0_flag=0;
unsigned char T2_CH1_flag=0;
void TIM2_CH0_start(void)
{
T2SC_TSTOP =1;
T2SC_TRST =1;
T2SC0_MS0A =1;
T2SC0_MS0B =0;
T2SC0_ELS0A =0;
T2SC0_ELS0B =1;
T2SC1_MS1A =1;
T2SC1_ELS1A =0;
T2SC1_ELS1B =1;
T2SC0_MS0B =1;
T2SC1_TOV1 =0;
T2SC0_TOV0 =1;
T2SC0_CH0MAX=0;
T2SC_TSTOP =0;
}
void TIM2_CH0_stop(void)
{
T2SC_TSTOP =1;
T2SC_TRST =1;
T2SC0_MS0A =1;
T2SC0_ELS0A =0;
T2SC0_ELS0B =1;
T2SC1_MS1A =1;
T2SC1_ELS1A =0;
T2SC1_ELS1B =1;
T2SC1_TOV1 =0;
T2SC0_TOV0 =0;
T2SC_TSTOP =0;
}
void TIM2_CH1_start(void)
{
T2SC_TSTOP =1;
T2SC_TRST =1;
T2SC0_MS0A =1;
T2SC0_MS0B =1;
T2SC0_ELS0A =0;
T2SC0_ELS0B =1;
T2SC1_MS1A =1;
T2SC1_ELS1A =0;
T2SC1_ELS1B =1;
T2SC0_MS0B =0;
T2SC0_TOV0 =1;
T2SC0_CH0MAX=1;
T2SC1_TOV1 =1;
T2SC1_CH1MAX=0;
T2SC_TSTOP =0;
}
void TIM2_CH1_stop(void)
{
T2SC_TSTOP =1;
T2SC_TRST =1;
T2SC0_MS0A =1;
T2SC0_ELS0A =0;
T2SC0_ELS0B =1;
T2SC1_MS1A =1;
T2SC1_ELS1A =0;
T2SC1_ELS1B =1;
T2SC0_MS0B =0;
T2SC0_TOV0 =0;
T2SC0_CH0MAX=1;
T2SC1_TOV1 =1;
T2SC1_CH1MAX=1;
T2SC_TSTOP =0;
}
void open_lock_start(void)
{ PTA_PTA6=0;
PTA_PTA7=1;
T1SC_TSTOP =1;
T1SC_TRST =1;
T1SC0_MS0A =1;
T1SC0_MS0B =0;
T1SC0_ELS0A =0;
T1SC0_ELS0B =1;
T1SC1_MS1A =1;
T1SC1_ELS1A =0;
T1SC1_ELS1B =1;
T1SC0_MS0B =1;
T1SC1_TOV1 =0;
T1SC0_TOV0 =1;
T1SC0_CH0MAX=0;
T1SC_TSTOP =0;
}
void open_lock_stop(void)
{
PTA_PTA6=1 ;
PTA_PTA7=0 ;
T1SC_TSTOP =1;
T1SC_TRST =1;
T1SC0_MS0A =1;
T1SC0_ELS0A =0;
T1SC0_ELS0B =1;
T1SC1_MS1A =1;
T1SC1_ELS1A =0;
T1SC1_ELS1B =1;
T1SC1_TOV1 =0;
T1SC0_TOV0 =0;
T1SC_TSTOP =0;
}
void close_lock_start(void)
{ PTA_PTA6=0;
PTA_PTA7=1;
T1SC_TSTOP =1;
T1SC_TRST =1;
T1SC0_MS0A =1;
T1SC0_MS0B =1;
T1SC0_ELS0A =0;
T1SC0_ELS0B =1;
T1SC1_MS1A =1;
T1SC1_ELS1A =0;
T1SC1_ELS1B =1;
T1SC0_MS0B =0;
T1SC0_TOV0 =1;
T1SC0_CH0MAX=1;
T1SC1_TOV1 =1;
T1SC1_CH1MAX=0;
T1SC_TSTOP =0;
}
void close_lock_stop(void)
{
PTA_PTA6=1;
PTA_PTA7=0;
T1SC_TSTOP =1;
T1SC_TRST =1;
T1SC0_MS0A =1;
T1SC0_ELS0A =0;
T1SC0_ELS0B =1;
T1SC1_MS1A =1;
T1SC1_ELS1A =0;
T1SC1_ELS1B =1;
T1SC0_MS0B =0;
T1SC0_TOV0 =0;
T1SC0_CH0MAX=1;
T1SC1_TOV1 =1;
T1SC1_CH1MAX=1;
T1SC_TSTOP =0;
}
void window_up_start(void)
{ PTA_PTA2=0;
PTA_PTA3=1;
T2SC_TSTOP =1;
T2SC_TRST =1;
T2SC0_MS0A =1;
T2SC0_MS0B =0;
T2SC0_ELS0A =0;
T2SC0_ELS0B =1;
T2SC1_MS1A =1;
T2SC1_ELS1A =0;
T2SC1_ELS1B =1;
T2SC0_MS0B =1;
T2SC1_TOV1 =0;
T2SC0_TOV0 =1;
T2SC0_CH0MAX=0;
T2SC_TSTOP =0;
}
void window_up_stop(void)
{
PTA_PTA2=1;
PTA_PTA3=0;
T2SC_TSTOP =1;
T2SC_TRST =1;
T2SC0_MS0A =1;
T2SC0_ELS0A =0;
T2SC0_ELS0B =1;
T2SC1_MS1A =1;
T2SC1_ELS1A =0;
T2SC1_ELS1B =1;
T2SC1_TOV1 =0;
T2SC0_TOV0 =0;
T2SC_TSTOP =0;
}
void window_down_start(void)
{
PTA_PTA2=0;
PTA_PTA3=1;
T2SC_TSTOP =1;
T2SC_TRST =1;
T2SC0_MS0A =1;
T2SC0_MS0B =1;
T2SC0_ELS0A =0;
T2SC0_ELS0B =1;
T2SC1_MS1A =1;
T2SC1_ELS1A =0;
T2SC1_ELS1B =1;
T2SC0_MS0B =0;
T2SC0_TOV0 =1;
T2SC0_CH0MAX=1;
T2SC1_TOV1 =1;
T2SC1_CH1MAX=0;
T2SC_TSTOP =0;
}
void window_down_stop(void)
{ PTA_PTA2=1;
PTA_PTA3=0;
T2SC_TSTOP =1;
T2SC_TRST =1;
T2SC0_MS0A =1;
T2SC0_ELS0A =0;
T2SC0_ELS0B =1;
T2SC1_MS1A =1;
T2SC1_ELS1A =0;
T2SC1_ELS1B =1;
T2SC0_MS0B =0;
T2SC0_TOV0 =0;
T2SC0_CH0MAX=1;
T2SC1_TOV1 =1;
T2SC1_CH1MAX=1;
T2SC_TSTOP =0;
}
void mirror_x_forward_start(void)
{ PTB_PTB6=0;
PTB_PTB7=1;
if( T2_CH0_flag!=1)
{ TIM2_CH0_start();
T2_CH0_flag=1;}
}
void mirror_x_forward_stop(void)
{
PTB_PTB6=1;
PTB_PTB7=0;
if( T2_CH0_flag!=2)
{TIM2_CH0_stop();
T2_CH0_flag=2;}
}
void mirror_x_reverse_start(void)
{ PTB_PTB6=0;
PTB_PTB7=1;
if( T2_CH1_flag!=1)
{ TIM2_CH1_start();
T2_CH1_flag=1;}
}
void mirror_x_reverse_stop(void)
{ PTB_PTB6=1;
PTB_PTB7=0;
if( T2_CH1_flag!=2)
{TIM2_CH1_stop();
T2_CH1_flag=2;}
}
void mirror_y_forward_start(void)
{ PTC_PTC4=0;
PTC_PTC5=1;
if( T2_CH0_flag!=1)
{ TIM2_CH0_start();
T2_CH0_flag=1;}
}
void mirror_y_forward_stop(void)
{
PTC_PTC4=1;
PTC_PTC5=0;
if( T2_CH0_flag!=2)
{TIM2_CH0_stop();
T2_CH0_flag=2;}
}
void mirror_y_reverse_start(void)
{ PTC_PTC4=0;
PTC_PTC5=1;
if( T2_CH1_flag!=1)
{ TIM2_CH1_start();
T2_CH1_flag=1;}
}
void mirror_y_reverse_stop(void)
{ PTC_PTC4=1;
PTC_PTC5=0;
if( T2_CH1_flag!=2)
{TIM2_CH1_stop();
T2_CH1_flag=2;}
}
/************************* CAN接收中断子程序************************/
void interrupt CAN_Receive(void)
{
int doors_closed=0;
volatile unsigned char idr0test;
idr0test = RBIDR0;
if(idr0test==0x50) //接受中央控制器数据
{
cent_sta0=RBDSR0;
cent_sta1=RBDSR1;
cent_sta2=RBDSR2;
cent_sta3=RBDSR3;
}
else if(idr0test == 0x48) //接受左前门数据
{
lf_sta0=RBDSR0;
lf_sta1=RBDSR1;
lf_sta2=RBDSR2;
}
else if(idr0test == 0x42) //接受左后门数据
{
lr_sta0=RBDSR0;
lr_sta1=RBDSR1;
}
else if(idr0test == 0x41) //接受右后门数据
{
rr_sta0=RBDSR0;
rr_sta1=RBDSR1;
}
CRFLG = 0x01; //receive buffer full
inlock2=cent_sta1_cent_inlock;
outlock2=cent_sta1_cent_outlock;
rflock2=rf_sta1_rf_cent_outlock;
speedlock2=cent_sta0_speed;
if(inlock2==inlock1) { inlock=0; inlock1=inlock2; }
if(inlock2!=inlock1) { inlock=1; judge=inlock2; inlock1=inlock2; }
if(outlock2==outlock1) { outlock=0; outlock1=outlock2; }
if(outlock2!=outlock1) { outlock=1; judge=outlock2; outlock1=outlock2; }
if(rflock2==rflock1) { rflock=0; rflock1=rflock2; }
if(rflock2!=rflock1) { rflock=1; judge=rflock2; rflock1=rflock2; }
if( speedlock2==speedlock1) {speedlock=0; speedlock1=speedlock2; }
if( speedlock2!=speedlock1) {speedlock=1; speedlock1=speedlock2; }
doors_closed= (lf_sta0_lf_sta==0x1 && rf_sta0_rf_sta==0x1&& lr_sta0_lr_sta==0x1&& rr_sta0_rr_sta==0x1) ;
if( ( inlock==1||outlock==1||rflock==1) &&lock_moto_count==LT && rf_sta0_rf_sta==0x1 )
{ if( judge==1 )
{
if(PWM_flag2!=1)
{ open_lock_start();
PWM_flag2=1;}
}
}
if( ( inlock==1||outlock==1||rflock==1) && lock_moto_count==0 && cent_sta0_crash==1 && doors_closed==1 )
{ if( judge ==2)
{
if(PWM_flag2!=4)
{ close_lock_start();
PWM_flag2=4;}
}
}
if( cent_sta0_crash==2 &&lock_moto_count==LT && rf_sta0_rf_sta==0x1 )
{ if(PWM_flag2!=1)
{ open_lock_start();
PWM_flag2=1;}
}
if ( speedlock==1 && cent_sta0_crash==1 && lock_moto_count==0 && doors_closed==1 )
{ if(speedlock2==1 )
{
if(PWM_flag2!=4)
{ close_lock_start();
PWM_flag2=4;}
}
}
if ( speedlock==1 && lock_moto_count==LT && rf_sta0_rf_sta==0x1 )
{ if(speedlock2==0 && cent_sta1_cent_inlock ==0x1 && cent_sta1_cent_outlock ==0x1 && rf_sta1_rf_cent_outlock ==0x1)
{ if(PWM_flag2!=1)
{ open_lock_start();
PWM_flag2=1;}
}
}
if ( (cent_sta0_fire==1 && (cent_sta1_cent_outlock==2 || rf_sta1_rf_cent_outlock==2) ) && cent_sta0_crash==1 && lock_moto_count==0 && doors_closed==1 )
{
if(PWM_flag2!=4)
{ close_lock_start();
PWM_flag2=4;}
if(window_position<WT)
{
if(PWM_flag1!=4)
{ window_up_start();
PWM_flag1=4;}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -