📄 main.c
字号:
/*********************************************/
/**file name: right_rear node program **/
/**Author :Xiaoming Li **/
/**date/time: 1.11.2003 **/
/**company: Tongji university **/
/*********************************************/
#include <MC68HC908GZ16.H>
#include <hidef.h>
#include <signal_group.h>
#define WT 5000
#define LT 2000
unsigned int CAN_timer_count=0;
unsigned int count=0;
unsigned int SPI_count=0;
unsigned int rr_up_count=0;
unsigned int rr_dn_count=0;
unsigned long int window_position=0;
unsigned long int lock_moto_count=0;
unsigned char rr_button_sta[3]={0,0,0};
unsigned char rr_butt_sta1[3]={0,0,0};
unsigned char rr_butt_sta2[3]={0,0,0};
unsigned char rr_moto_sta[2]={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 int childlock=0;
unsigned int childlock1=0;
unsigned int childlock2=0;
unsigned int PWM_flag1=0;
unsigned int PWM_flag2=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;
}
/************************* CAN接收中断子程序****************************/
void interrupt CAN_Receive(void)
{
unsigned char doors_closed=0;
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 == 0x44) //接受右前门数据
{
rf_sta0=RBDSR0;
rf_sta1=RBDSR1;
}
else if(idr0test == 0x42) //接受左后门数据
{
lr_sta0=RBDSR0;
lr_sta1=RBDSR1;
}
CRFLG = 0x01;
inlock2=cent_sta1_cent_inlock;
outlock2=cent_sta1_cent_outlock;
rflock2=rf_sta1_rf_cent_outlock;
speedlock2=cent_sta0_speed;
childlock2=cent_sta0_child_lock;
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; }
if( childlock2==childlock1) {childlock=0; childlock1=childlock2; }
if( childlock2!=childlock1) {childlock=1; childlock1=childlock2; }
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 && rr_sta0_rr_sta==0x1 )
{
if( judge==1 )
{
if(PWM_flag2!=1)
{ open_lock_start();
PWM_flag2=1;}
rr_moto_sta[1]= PTE_PTE0;
}
}
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;}
rr_moto_sta[1]= PTE_PTE0;
}
}
if( cent_sta0_crash==2 &&lock_moto_count==LT && rr_sta0_rr_sta==0x1 )
{ if(PWM_flag2!=1)
{ open_lock_start();
PWM_flag2=1;}
rr_moto_sta[1]= PTE_PTE0;
}
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;}
rr_moto_sta[1]= PTE_PTE0;
}
}
if ( childlock==1 && cent_sta0_crash==1 && lock_moto_count==0 && doors_closed ==1 )
{ if(childlock2==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;}
}
rr_moto_sta[1]= PTE_PTE0;
}
}
if ( ( speedlock==1 || childlock==1 ) && lock_moto_count==LT && rr_sta0_rr_sta==0x1 )
{ if( (speedlock2==0 ||childlock2==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;}
rr_moto_sta[1]= PTE_PTE0;
}
}
if ( (cent_sta0_fire==1 && (cent_sta1_cent_outlock==2 || rf_sta1_rf_cent_outlock ==0x2) ) && 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;}
}
rr_moto_sta[1]= PTE_PTE0;
}
}
/*********************** CAN发送子程序第一帧***********************/
void CAN_TransmitF1(void){
unsigned char emptytest;
unsigned char emptytest0;
unsigned char emptytest1;
unsigned char emptytest2;
emptytest = CTFLG;
emptytest0 = emptytest&0x01; //判断接受区为空
emptytest1 = emptytest&0x02;
emptytest2 = emptytest&0x04;
if(emptytest0 !=0)
{
TB0DLR = 0x02;
TB0DSR0 = rr_sta0;
TB0DSR1 = rr_sta1;
TB0IDR0 = 0x41; //id 赋值
TB0IDR1 = 0x00;
TB0IDR2 = 0x00;
TB0IDR3 = 0x00;
TB0TBPR = 0x01;
CTFLG = 0x01; //启动发送
}
else if(emptytest1 !=0)
{
TB1DLR = 0x02;
TB1DSR0 = rr_sta0;
TB1DSR1 = rr_sta1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -