⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 基于摩托罗拉(现在飞思卡尔)MC68HC908AZ60A系列单片机
💻 C
📖 第 1 页 / 共 2 页
字号:

else if(emptytest1 !=0)
{
TB1DLR   =  0x02;

TB1DSR0  =  lr_sta0;
TB1DSR1  =  lr_sta1;


TB1IDR0  =   0x42;      //id 赋值
TB1IDR1  =   0x00;
TB1IDR2  =   0x00;  
TB1IDR3  =   0x00;



TB1TBPR  =  0x01;

CTFLG  =  0x02;        //启动发送
}




else if(emptytest2 !=0)
{
TB2DLR   =  0x02;

TB2DSR0  =  lr_sta0;
TB2DSR1  =  lr_sta1;



TB2IDR0  =   0x42;      //id 赋值
TB2IDR1  =   0x00;
TB2IDR2  =   0x00;  
TB2IDR3  =   0x00;


TB2TBPR  =  0x01;

CTFLG     =  0x04;      //启动发送
}


}



void time_delay(int n)
 {
  count=0;
  while(count<n) {;}    
   
  }


void transmit_SPI(unsigned char SPI_data)
{
  PTB_PTB3=0x0;
  PTB_PTB3=0x0;

  
   while(SPSCR_SPTE==0) {; }  
       SPDR=SPI_data;
  
  PTB_PTB3=0x0;PTB_PTB3=0x0;PTB_PTB3=0x0;PTB_PTB3=0x0;;
  
  PTB_PTB3=0x1; 
}




void interrupt TimerInterrupt(void)
{
__RESET_WATCHDOG();                  

count++;
CAN_timer_count++;
SPI_count++;

if(CAN_timer_count==5)
{
CAN_TransmitF1();               
CAN_timer_count=0;          
}


if(SPI_count==25)           
{
 transmit_SPI(0xB3);
 SPI_count=0;
}


if(lrwin_up_300_enable==1) {lr_up_count++;}

if(lrwin_dn_300_enable==1) {lr_dn_count++;}              


if(lr_sta1_lr_moto_sta ==0x1 && window_position<WT) { window_position++;}     

if(lr_sta1_lr_moto_sta ==0x5 && window_position<WT) { window_position++;}    

if(lr_sta1_lr_moto_sta ==0x2 && window_position>0) { window_position--;}   

if(lr_sta1_lr_moto_sta ==0x6 && window_position>0) { window_position--;}    


if(PWM_flag2==0x4 && lock_moto_count<LT) {lock_moto_count++;}     

if(PWM_flag2==0x1 && lock_moto_count>0) {lock_moto_count--;}        


TBCR_TACK =1;

}




/*********************MSCAN初始化子程序 **********************/
static void Init_MSCAN08(void){

CMCR0  = 0x01;   //CAN模块为软复位状态
CMCR1  = 0x00;

CBTR0  = 0x43;   
CBTR1  = 0xA3;   //波特率为62.5K


CIDAC   = 0x00;   //接收滤波为32位滤波

CIDAR0  = 0x00;   //滤波使它接收一帧
CIDAR1  = 0x00;   //standard identifiers



CIDMR0  = 0xFF;
CIDMR1  = 0xFF;   //standard identifiers


                             
CMCR0  = 0x00;   //把CAN模块设置为数据输入输出状态

CRIER  = 0x01;   //CAN接收中断使能 
}





static void Init_GZ16(void)
{
  CONFIG2 =0x0D;       
  CONFIG1 =0x4a;      
  
  TBCR_TBIE =1;
  TBCR_TACK =1;
  TBCR_TBR0 =1;
  TBCR_TBR1 =1;
  TBCR_TBR2 =0;       
  TBCR_TBIF =0;                

  TBCR_TBON =1;           

Init_MSCAN08();  

EnableInterrupts;
}
 
 

void main(void)
{
Init_GZ16();  


DDRC_DDRC2=1;
DDRC_DDRC3=1;
DDRC_DDRC4=1;         

DDRE_DDRE4=0; 
DDRE_DDRE5=0;         

PTC_PTC2=0x0;
PTC_PTC3=0x0;
PTC_PTC4=0x0;

PTE_PTE4=0x0;
PTE_PTE5=0x0;        




DDRB_DDRB3=1;           

DDRE_DDRE0=0;        

DDRA_DDRA6=1;             
DDRA_DDRA7=1; 



PTB_PTB3=0x0;

PTE_PTE0=0x0;

 PTA_PTA6=0;

 PTA_PTA7=1;
              

DDRE_DDRE3=0;             

DDRA_DDRA2=1;             
DDRA_DDRA3=1; 
                      


PTE_PTE3=0x0;

PTA_PTA2=0x0;
PTA_PTA3=0x1;         


        
        T1MODH  = 0x03;
        T1MODL  = 0xe8;    

        T1CH0H  =  0x03 ;
        T1CH0L  =  0x20 ;   

        T1CH1H  =  0x03 ;
        T1CH1L  =  0x20 ;    
        

       
        T2MODH  = 0x03;
        T2MODL  = 0xe8;    


        T2CH0H  =  0x03 ;
        T2CH0L  =  0x20 ;  

        T2CH1H  =  0x03 ;
        T2CH1L  =  0x20 ;    
                          

       
 cent_sta0=0x14;
 cent_sta1=0x05;
 cent_sta2=0x00;
 cent_sta3=0x00;
 


 lf_sta0=0x08;
 lf_sta1=0x40;
 lf_sta2=0x00;
    
 rf_sta0=0x08;
 rf_sta1=0x42;  
             
 lr_sta0=0x08;
 lr_sta1=0x40; 
              
 rr_sta0=0x08;
 rr_sta1=0x40;                           
	  

 win_moto_sta0=0x00;
 win_moto_sta1=0x00;
	  
  

	  

SPCR_SPE =1;  

SPSCR_SPR0=0;  
SPSCR_SPR1=0;  


PTB_PTB3=0x1;

transmit_SPI(0xB3);     
transmit_SPI(0x11);      
transmit_SPI(0x53);      
transmit_SPI(0x31);     
transmit_SPI(0x90);       
   
inlock1=cent_sta1_cent_inlock;
outlock1=cent_sta1_cent_outlock;
rflock1=rf_sta1_rf_cent_outlock;

speedlock1=cent_sta0_speed;
childlock1=cent_sta0_child_lock;



while(1)  
{ 

PTC_PTC2=0x1 ;
PTC_PTC3=0x0 ;
PTC_PTC4=0x1 ;
lr_butt_sta1[0]=PTE&0x10;       
if(lr_butt_sta1[0]!=0)   time_delay(5);                  
lr_butt_sta2[0]=PTE&0x10;        
if(lr_butt_sta1[0]==lr_butt_sta2[0])
  {  lr_button_sta[0]=lr_butt_sta1[0];
       if(lr_button_sta[0]!=0)   lrwin_dn_300_enable=1;         
       else  lrwin_dn_300_enable=0;                            
   }  
       
if(lr_dn_count>=75) { lrwin_dn_300_reach=1; lrwin_dn_300_enable=0;}
else lrwin_dn_300_reach=0;

     
if(lrwin_dn_300_reach==1 && lr_button_sta[0]!=0)            
  {lr_sta1_lr_moto_sta=0x2;}                           
if(lrwin_dn_300_reach==0 && lr_dn_count>0 && lr_button_sta[0]==0)
  {lr_sta1_lr_moto_sta=0x6;lr_dn_count=0;}          
if((lr_sta1_lr_moto_sta==0x2 && lr_button_sta[0]==0)&&cent_sta3_lr_manual_dn==0x0)
  {lr_sta1_lr_moto_sta=0x0;lr_dn_count=0;}          
if(lr_sta1_lr_moto_sta==0x6 && lrwin_dn_300_reach==1 && lr_button_sta[0]!=0)
  {lr_sta1_lr_moto_sta=0x2;}                  

if(lr_sta1_lr_moto_sta==0x6 && lrwin_up_300_reach==0 && lr_up_count>0 && lr_button_sta[1]==0)
  {lr_sta1_lr_moto_sta=0x5;}                
if(lr_sta1_lr_moto_sta==0x6&& lrwin_up_300_reach==1 && lr_button_sta[1]!=0)
  {lr_sta1_lr_moto_sta=0x1;}              



if(  cent_sta3_lr_auto_dn==0x1   && window_position>0 )
 { lr_sta1_lr_moto_sta=0x6; 
   if(PWM_flag1!=1)
  { window_down_start();        
     PWM_flag1=1;}
   
   lr_moto_sta[0]= PTE_PTE3 ;
   } 

if(  cent_sta3_lr_manual_dn==0x1   && window_position>0 )
 { lr_sta1_lr_moto_sta=0x2;
  if(PWM_flag1!=1)
  {window_down_start();    
    PWM_flag1=1;}
    
   lr_moto_sta[0]= PTE_PTE3 ;
   } 
 
if( cent_sta0_child_lock==0x0 &&(cent_sta3_lr_auto_dn==0x0&&cent_sta3_lr_manual_dn==0x0)&& (lr_sta1_lr_moto_sta==0x2||lr_sta1_lr_moto_sta==0x6) && window_position>0  )
   { 
   if(PWM_flag1!=1)
  { window_down_start();      
    PWM_flag1=1;}
   lr_moto_sta[0]= PTE_PTE3 ; 
   }
                           
      
if( lr_sta1_lr_moto_sta==0x0 && cent_sta3_lr_auto_up==0x0 && cent_sta3_lr_manual_up==0x0 && cent_sta3_lr_auto_dn==0x0 && cent_sta3_lr_manual_dn==0x0 && PWM_flag1==1 )      
    { 
     if(PWM_flag1!=2)
    { window_down_stop();        
     PWM_flag1=2;}
     lr_moto_sta[0]= PTE_PTE3 ;
    }
                       
           
if(  window_position<=0 )       
   {  if( lr_sta1_lr_moto_sta!=0x1 && lr_sta1_lr_moto_sta!=0x5) 
     { lr_sta1_lr_moto_sta=0x3;
     if(PWM_flag1!=2)
     { window_down_stop(); 
       PWM_flag1=2;}
      }  

   lr_moto_sta[0]= PTE_PTE3 ;
   }



PTC_PTC2=0x0 ;
PTC_PTC3=0x1 ;
PTC_PTC4=0x1 ;
lr_butt_sta1[1]=PTE&0x10;         
if(lr_butt_sta1[1]!=0)   time_delay(5);                  
lr_butt_sta2[1]=PTE&0x10;       
if(lr_butt_sta1[1]==lr_butt_sta2[1])
  {  lr_button_sta[1]=lr_butt_sta1[1];
       if(lr_button_sta[1]!=0)   lrwin_up_300_enable=1;            
       else  lrwin_up_300_enable=0;                               
   }  
       
if(lr_up_count>=75) { lrwin_up_300_reach=1; lrwin_up_300_enable=0;}
else lrwin_up_300_reach=0;
     
if(lrwin_up_300_reach==1 && lr_button_sta[1]!=0)            
  {lr_sta1_lr_moto_sta=0x1;}                         
if(lrwin_up_300_reach==0 && lr_up_count>0 && lr_button_sta[1]==0)
  {lr_sta1_lr_moto_sta=0x5;lr_up_count=0;}             
if((lr_sta1_lr_moto_sta==0x1 && lr_button_sta[1]==0)&& cent_sta3_lr_manual_up==0x0)
  {lr_sta1_lr_moto_sta=0x0;lr_up_count=0;}           
if(lr_sta1_lr_moto_sta==0x5 && lrwin_up_300_reach==1 && lr_button_sta[1]!=0)
  {lr_sta1_lr_moto_sta=0x1;}                    

if(lr_sta1_lr_moto_sta==0x5&& lrwin_dn_300_reach==0 && lr_dn_count>0 && lr_button_sta[0]==0)
  {lr_sta1_lr_moto_sta=0x6;}                
if(lr_sta1_lr_moto_sta==0x5&& lrwin_dn_300_reach==1 && lr_button_sta[0]!=0)
  {lr_sta1_lr_moto_sta=0x2;}                 



if(  cent_sta3_lr_auto_up==0x1   && window_position<WT )
 {lr_sta1_lr_moto_sta=0x5;
 
 if(PWM_flag1!=4)
 { window_up_start();        
  PWM_flag1=4;}
   lr_moto_sta[0]= PTE_PTE3 ;
   } 

if(  cent_sta3_lr_manual_up==0x1  && window_position<WT )
 {lr_sta1_lr_moto_sta=0x1;
 if(PWM_flag1!=4)
  {window_up_start();        
   PWM_flag1=4;}
   lr_moto_sta[0]= PTE_PTE3 ;
   } 
 
if( cent_sta0_child_lock==0x0 && (cent_sta3_lr_auto_up==0x0&&cent_sta3_lr_manual_up==0x0)&& (lr_sta1_lr_moto_sta==0x1||lr_sta1_lr_moto_sta==0x5) && window_position<WT  )
   { 
  if(PWM_flag1!=4)
  { window_up_start();        
   PWM_flag1=4;}
   lr_moto_sta[0]= PTE_PTE3 ; 
   }
                           
      
if( lr_sta1_lr_moto_sta==0x0 && cent_sta3_lr_auto_up==0x0 && cent_sta3_lr_manual_up==0x0 && cent_sta3_lr_auto_dn==0x0 && cent_sta3_lr_manual_dn==0x0 && PWM_flag1==4 )      
    { 
     if(PWM_flag1!=8)
   {  window_up_stop();         
      PWM_flag1=8;}
     lr_moto_sta[0]= PTE_PTE3 ;
    }
                       
           
if(  window_position>=WT )       
   {           
    if( lr_sta1_lr_moto_sta!=2 &&  lr_sta1_lr_moto_sta!=6)
     { lr_sta1_lr_moto_sta=0x4;
     if(PWM_flag1!=8)
      {window_up_stop(); 
      PWM_flag1=8;}
       }  
     
   lr_moto_sta[0]= PTE_PTE3 ;
   }



lr_butt_sta1[2]=PTE&0x20;           
if(lr_butt_sta1[2]!=0)   time_delay(5);                 
lr_butt_sta2[2]=PTE&0x20;           
if(lr_butt_sta1[2]==lr_butt_sta2[2])
  {  lr_button_sta[2]= lr_butt_sta1[2];
       if(lr_button_sta[2]!=0)    lr_sta0_lr_sta=0x1;         
       else  lr_sta0_lr_sta=0x2;                            
   }




if(lock_moto_count<=0)        
       {       
          if(PWM_flag2==1)
         { open_lock_stop();                 
           PWM_flag2=2;}
          
         lr_sta1_lr_lock_sta=0x01;
             
         lr_moto_sta[1]= PTE_PTE0;
          
         }
 
 
if(lock_moto_count>=LT)            
       {   if(PWM_flag2==4)   
          { close_lock_stop();                
              PWM_flag2=8;}
              
          lr_sta1_lr_lock_sta=0x2;
              
         lr_moto_sta[1]= PTE_PTE0;
           
        }

  

}            



}           




	  

























⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -