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

📄 tim.c

📁 AirConditioner project
💻 C
字号:
/*  Include  */
#include <hidef.h> /* for EnableInterrupts macro */
#include <MC68HC908GZ60.h> /* include peripheral declarations */
#include "COMMON.h"
#include "TIM.h"

/* Global Variables */
UINT8 duty_cycle;
UINT8 motor_channel;
extern UINT8 fanladder;

/*****************************************************************************
 * Function:        Turn_Right()
 *
 * Description:     none
 *
 * Returns:         none
 *
 * Notes:           This handler initializes the TIM2 channels 0.2 Duty Cycle.
 *
 *****************************************************************************/

 void Turn_Right(UINT8 channel , UINT8 duty)               //0x28  20%
{  																												 //0xA0  80%
  duty_cycle=duty;																				 //0x64  50%
  if(channel == 0x01)
   { 
     T2SC0_CH0IE = 1;                 //Channel 1 CPU interrupt requests enabled
   }
   else if(channel == 0x02)
    { 
     T2SC1_CH1IE = 1;                 //Channel 2 CPU interrupt requests enabled
    }
   else if(channel == 0x03)
    {
     T2SC2_CH2IE = 1;                 //Channel 3 CPU interrupt requests enabled
    }
   else if(channel == 0x04)
    {
     T2SC3_CH3IE = 1;                 //Channel 4 CPU interrupt requests enabled
    }
}
  
//////////////////////////////////////////////////////////////////  
 
void interrupt Motor1_Right(void)
{
      T2SC0_CH0IE = 0;                  //Channel 1 CPU interrupt requests disabled
     
      T2CH0H        =0x00; 
      T2CH0L        =duty_cycle;              //20% duty cycle selected
      
      T2SC0_CH0F  = 0;
      
}
//////////////////////////////////////////////////////////////////
void interrupt Motor2_Right(void)
{
      T2SC1_CH1IE = 0;                  //Channel 1 CPU interrupt requests disabled
 
      T2CH1H        =0x00; 
      T2CH1L        =duty_cycle;              //20% duty cycle selected
      
      T2SC1_CH1F  = 0;
 }     
/////////////////////////////////////////////////////////////////   
void interrupt Motor3_Right(void)
{
      T2SC2_CH2IE = 0;                  //Channel 1 CPU interrupt requests disabled
      
      T2CH2H        =0x00; 
      T2CH2L        =duty_cycle;              //20% duty cycle selected
      
      T2SC2_CH2F  = 0;
}   
/////////////////////////////////////////////////////////////////
void interrupt Motor4_Right(void)
{
      T2SC3_CH3IE = 0;                  //Channel 1 CPU interrupt requests disabled
      
      T2CH3H        =0x00; 
      T2CH3L        =duty_cycle;              //20% duty cycle selected
      
      T2SC3_CH3F  = 0;
}   

/*****************************************************************************
 * Function:        Turn_Left()
 *
 * Description:     none
 *
 * Returns:         none
 *
 * Notes:           This handler initializes the TIM2 channels 0.8 Duty Cycle.
 *
 *****************************************************************************/

 void Turn_Left(UINT8 channel , UINT8 duty)
 {  
  duty_cycle=duty;
  motor_channel = channel;
  T2SC_TOIE = 1;                   //TIM2 overflow interrupts enabled
 }
 
 
//////////////////////////////////////////////////////////////// 
void interrupt Motor_Left(void)
{
  T2SC_TOIE = 0;                         //TIM2 overflow interrupts disabled
  if(motor_channel == 0x01)
   {
     T2CH0H        =0x00; 
     T2CH0L        =duty_cycle;                //80% duty cycle selected
   }
   else if(motor_channel == 0x02)
     {
       T2CH1H        =0x00; 
       T2CH1L        =duty_cycle;              //80% duty cycle selected
     }
   else if(motor_channel == 0x03)
     {
       T2CH2H        =0x00; 
       T2CH2L        =duty_cycle;              //80% duty cycle selected
     }
   else if(motor_channel == 0x04)
     {
       T2CH3H        =0x00; 
       T2CH3L        =duty_cycle;              //80% duty cycle selected
     }
  
  T2SC_TOF  = 0;  
}

/*****************************************************************************
 * Function:        Fan_Up()
 *
 * Description:     fanladder from 1 to 7
 *
 * Returns:         none
 *
 * Notes:          
 *
 *****************************************************************************/
 
 void Fan_Up(void)
 {  
   T1SC_TOIE = 1;                   //TIM1 overflow interrupts enabled
 }
 
 
//////////////////////////////////////////////////////////////// 
void interrupt Speed_Up(void)
{
  T1SC_TOIE = 0;                         //TIM1 overflow interrupts disabled
  switch(fanladder)
         {                                       
           case    2 : {   
                           T1CH0H        =0x00; 
                           T1CH0L        =0x21;    //16.5% duty cycle selected
                       }break;
           case    3 : {
                           T1CH0H        =0x00; 
                           T1CH0L        =0x42;    //33% duty cycle selected
                       }break;
           case    4 : {
                           T1CH0H        =0x00; 
                           T1CH0L        =0x63;    //49.5% duty cycle selected
                       }break;
           case    5 : {
                           T1CH0H        =0x00; 
                           T1CH0L        =0x84;    //66% duty cycle selected
                       }break;
           case    6 : {
                           T1CH0H        =0x00; 
                           T1CH0L        =0xA5;    //82.5% duty cycle selected
                       }break;
           case    7 : {
                           T1SC0_CH0MAX  =1;       //100% duty cycle selected
                       }break;
           default : break;
         }
     
  T1SC_TOF  = 0;
} 
 
/*****************************************************************************
 * Function:        Fan_Down ()
 *
 * Description:     fanladder from 1 to 7
 *
 * Returns:         none
 *
 * Notes:           
 *
 *****************************************************************************/
 void Fan_Down(void)
  {  
    T1SC0_CH0IE = 1;                 //Channel 0 CPU interrupt requests enabled
  }
  
//////////////////////////////////////////////////////////////////  
 
void interrupt Speed_Down(void)
{
  T1SC0_CH0IE = 0;                  //Channel 0 CPU interrupt requests disabled
  switch(fanladder)
         { 
           case    1 : {
                           T1CH0H        =0x00; 
                           T1CH0L        =0x00;    //0% duty cycle selected
                       }break;
                                      
           case    2 : {
                           T1CH0H        =0x00; 
                           T1CH0L        =0x21;    //16.5% duty cycle selected
                       }break;
           case    3 : {
                           T1CH0H        =0x00; 
                           T1CH0L        =0x42;    //33% duty cycle selected
                       }break;
           case    4 : {
                           T1CH0H        =0x00; 
                           T1CH0L        =0x63;    //49.5% duty cycle selected
                       }break;
           case    5 : {
                           T1CH0H        =0x00; 
                           T1CH0L        =0x84;    //66% duty cycle selected
                       }break;
           case    6 : {
                           T1SC0_CH0MAX  =0;
                           T1CH0H        =0x00; 
                           T1CH0L        =0xA5;    //82.5% duty cycle selected
                       }break;
           default : break;
         }
 
  T1SC0_CH0F  = 0;
  
    
} 

⌨️ 快捷键说明

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