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

📄 main.c

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


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



TB1TBPR  =  0x01;

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




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

TB2DSR0  =  rr_sta0;
TB2DSR1  =  rr_sta1;

TB2IDR0  =   0x41;      //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(rrwin_up_300_enable==1) {rr_up_count++;}

if(rrwin_dn_300_enable==1) {rr_dn_count++;}               


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

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

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

if(rr_sta1_rr_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 ;
rr_butt_sta1[0]=PTE&0x10;          
if(rr_butt_sta1[0]!=0)   time_delay(5);                 
rr_butt_sta2[0]=PTE&0x10;          
if(rr_butt_sta1[0]==rr_butt_sta2[0])
  {  rr_button_sta[0]=rr_butt_sta1[0];
       if(rr_button_sta[0]!=0)   rrwin_dn_300_enable=1;          
       else  rrwin_dn_300_enable=0;                               
   }  
       
if(rr_dn_count>=75) { rrwin_dn_300_reach=1; rrwin_dn_300_enable=0;}
else rrwin_dn_300_reach=0;
     
if(rrwin_dn_300_reach==1 && rr_button_sta[0]!=0)            
  {rr_sta1_rr_moto_sta=0x2;}                         
if(rrwin_dn_300_reach==0 && rr_dn_count>0 && rr_button_sta[0]==0)
  {rr_sta1_rr_moto_sta=0x6;rr_dn_count=0;}              
if((rr_sta1_rr_moto_sta==0x2 && rr_button_sta[0]==0)&&cent_sta3_rr_manual_dn==0x0)
  {rr_sta1_rr_moto_sta=0x0;rr_dn_count=0;}         
if(rr_sta1_rr_moto_sta==0x6 && rrwin_dn_300_reach==1 && rr_button_sta[0]!=0)
  {rr_sta1_rr_moto_sta=0x2;}                     

if(rr_sta1_rr_moto_sta==0x6 && rrwin_up_300_reach==0 && rr_up_count>0 && rr_button_sta[1]==0)
  {rr_sta1_rr_moto_sta=0x5;}                 
if(rr_sta1_rr_moto_sta==0x6&& rrwin_up_300_reach==1 && rr_button_sta[1]!=0)
  {rr_sta1_rr_moto_sta=0x1;}               


if(  cent_sta3_rr_auto_dn==0x1   && window_position>0 )
 { rr_sta1_rr_moto_sta=0x6; 
   if(PWM_flag1!=1)
  { window_down_start();        
     PWM_flag1=1;}
   
   rr_moto_sta[0]= PTE_PTE3 ;
   } 

if(  cent_sta3_rr_manual_dn==0x1   && window_position>0 )
 { rr_sta1_rr_moto_sta=0x2;
  if(PWM_flag1!=1)
  {window_down_start();       
    PWM_flag1=1;}
    
   rr_moto_sta[0]= PTE_PTE3 ;
   } 
 
if( cent_sta0_child_lock==0x0 &&(cent_sta3_rr_auto_dn==0x0&&cent_sta3_rr_manual_dn==0x0)&& (rr_sta1_rr_moto_sta==0x2||rr_sta1_rr_moto_sta==0x6) && window_position>0  )
   { 
   if(PWM_flag1!=1)
  { window_down_start();        
    PWM_flag1=1;}
   rr_moto_sta[0]= PTE_PTE3 ; 
   }
                           
      
if( rr_sta1_rr_moto_sta==0x0 && cent_sta3_rr_auto_up==0x0 && cent_sta3_rr_manual_up==0x0 && cent_sta3_rr_auto_dn==0x0 && cent_sta3_rr_manual_dn==0x0 && PWM_flag1==1 )      
    { 
     if(PWM_flag1!=2)
    { window_down_stop();       
     PWM_flag1=2;}
     rr_moto_sta[0]= PTE_PTE3 ;
    }
                       
           
if(  window_position<=0 )       
   {  if( rr_sta1_rr_moto_sta!=0x1 && rr_sta1_rr_moto_sta!=0x5) 
     { rr_sta1_rr_moto_sta=0x3;
     if(PWM_flag1!=2)
     { window_down_stop(); 
       PWM_flag1=2;}
      } 

   rr_moto_sta[0]= PTE_PTE3 ;
   }
      
      
PTC_PTC2=0x0 ;
PTC_PTC3=0x1 ;
PTC_PTC4=0x1 ;
rr_butt_sta1[1]=PTE&0x10;         
if(rr_butt_sta1[1]!=0)   time_delay(5);                  
rr_butt_sta2[1]=PTE&0x10;           
if(rr_butt_sta1[1]==rr_butt_sta2[1])
  {  rr_button_sta[1]=rr_butt_sta1[1];
       if(rr_button_sta[1]!=0)   rrwin_up_300_enable=1;          
       else  rrwin_up_300_enable=0;                           
   }  
       
if(rr_up_count>=75) { rrwin_up_300_reach=1; rrwin_up_300_enable=0;}
else rrwin_up_300_reach=0;
     
if(rrwin_up_300_reach==1 && rr_button_sta[1]!=0)            
  {rr_sta1_rr_moto_sta=0x1;}                         
if(rrwin_up_300_reach==0 && rr_up_count>0 && rr_button_sta[1]==0)
  {rr_sta1_rr_moto_sta=0x5;rr_up_count=0;}           
if((rr_sta1_rr_moto_sta==0x1 && rr_button_sta[1]==0)&& cent_sta3_rr_manual_up==0x0)
  {rr_sta1_rr_moto_sta=0x0;rr_up_count=0;}           
if(rr_sta1_rr_moto_sta==0x5 && rrwin_up_300_reach==1 && rr_button_sta[1]!=0)
  {rr_sta1_rr_moto_sta=0x1;}                  

if(rr_sta1_rr_moto_sta==0x5&& rrwin_dn_300_reach==0 && rr_dn_count>0 && rr_button_sta[0]==0)
  {rr_sta1_rr_moto_sta=0x6;}                  
if(rr_sta1_rr_moto_sta==0x5&& rrwin_dn_300_reach==1 && rr_button_sta[0]!=0)
  {rr_sta1_rr_moto_sta=0x2;}                 


if(  cent_sta3_rr_auto_up==0x1   && window_position<WT )
 {rr_sta1_rr_moto_sta=0x5;
 
 if(PWM_flag1!=4)
 { window_up_start();        
  PWM_flag1=4;}
   rr_moto_sta[0]= PTE_PTE3 ;
   } 

if(  cent_sta3_rr_manual_up==0x1  && window_position<WT )
 {rr_sta1_rr_moto_sta=0x1;
 if(PWM_flag1!=4)
  {window_up_start();       
   PWM_flag1=4;}
   rr_moto_sta[0]= PTE_PTE3 ;
   } 
 
if( cent_sta0_child_lock==0x0 && (cent_sta3_rr_auto_up==0x0&&cent_sta3_rr_manual_up==0x0)&& (rr_sta1_rr_moto_sta==0x1||rr_sta1_rr_moto_sta==0x5) && window_position<WT  )
   { 
  if(PWM_flag1!=4)
  { window_up_start();       
   PWM_flag1=4;}
   rr_moto_sta[0]= PTE_PTE3 ; 
   }
                           
      
if( rr_sta1_rr_moto_sta==0x0 && cent_sta3_rr_auto_up==0x0 && cent_sta3_rr_manual_up==0x0 && cent_sta3_rr_auto_dn==0x0 && cent_sta3_rr_manual_dn==0x0 && PWM_flag1==4 )      
    { 
     if(PWM_flag1!=8)
   {  window_up_stop();         
      PWM_flag1=8;}
     rr_moto_sta[0]= PTE_PTE3 ;
    }
                       
           
if(  window_position>=WT )       
   {           
    if( rr_sta1_rr_moto_sta!=2 &&  rr_sta1_rr_moto_sta!=6)
     { rr_sta1_rr_moto_sta=0x4;
     if(PWM_flag1!=8)
      {window_up_stop(); 
      PWM_flag1=8;}
       } 
     
   rr_moto_sta[0]= PTE_PTE3 ;
   }




rr_butt_sta1[2]=PTE&0x20;         
if(rr_butt_sta1[2]!=0)   time_delay(5);                 
rr_butt_sta2[2]=PTE&0x20;             
if(rr_butt_sta1[2]==rr_butt_sta2[2])
  {  rr_button_sta[2]= rr_butt_sta1[2];
       if(rr_button_sta[2]!=0)    rr_sta0_rr_sta=0x1;        
       else  rr_sta0_rr_sta=0x2;                             
   }




if(lock_moto_count<=0)         
       {       
          if(PWM_flag2==1)
         { open_lock_stop();                
           PWM_flag2=2;}
                             

         rr_moto_sta[1]= PTE_PTE0;
         rr_sta1_rr_lock_sta=0x1; 
         }
 
 
if(lock_moto_count>=LT)           
       {       
           if(PWM_flag2==4)   
          { close_lock_stop();                 
              PWM_flag2=8;}

         rr_moto_sta[1]= PTE_PTE0;
         rr_sta1_rr_lock_sta=0x2;  
        }

}           


}        




	  

























⌨️ 快捷键说明

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