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

📄 sw_led1.c

📁 M16C290FC can
💻 C
📖 第 1 页 / 共 2 页
字号:
        case PT_SW4:        //SW4
            in_rtn = 3;
            break;
        case PT_SW34:       //SW3 & SW4
            if(last_fix_sw_data == PT_SW3){
                in_rtn = 4; //SW3 --> SW4
            }
            else if(last_fix_sw_data == PT_SW4){
                in_rtn = 5; //SW4 --> SW3
            }
            else{
                in_rtn = 6; //
            }
            break;
        default:
            in_rtn = 6;
            break;
    }
    
    last_fix_sw_data = fix_sw_data;
    return in_rtn;
}


 /*""FUNC COMMENT""****************************************************
  *ID               :4.4.2
  *Description      :Fix switch function
  *--------------------------------------------------------------------
  *Include          :"define1.h"
  *                 :"declare1.h"
  *--------------------------------------------------------------------
  *Declaration      :unsigned char fix_sw_fnc(unsigned char)
  *--------------------------------------------------------------------
  *Function         :Fix switch function
  *--------------------------------------------------------------------
  *Arguments        :unsigned char in_data          ;Switch data
  *--------------------------------------------------------------------
  *Returns          :uneigned char in_rtn           ;Fixed switch data
  *--------------------------------------------------------------------
  *Input            :unsigned char fix_sw_data      ;Fixed switch data
  *                 :unsigned char last_sw_data     ;Last switch data
  *                 :unsigned char sw_count         ;Switch counter
  *Ountput          :unsigned char trm_count_sw     ;Transmit counter
  *--------------------------------------------------------------------
  *Call functions   :error_fnc()                    ;Error function
  *--------------------------------------------------------------------
  *Note             :
  *--------------------------------------------------------------------
  *History          :
  *                 :
  *""FUNC COMMENT END""***********************************************/
unsigned char fix_sw_fnc(unsigned char in_data)
{
    unsigned char in_rtn = 0;
    
    if((fix_sw_data != in_data) && (last_sw_data == in_data)){
        sw_count++;
    }
    else{
        sw_count = 0;
    }
    
    if(sw_count > CHAT_COUNT){
        fix_sw_data = in_data;
        sw_count = 0;
        in_rtn = 1;
    }
    
    last_sw_data = in_data;
    
    return in_rtn;
}


 /*""FUNC COMMENT""****************************************************
  *ID               :4.4.3
  *Description      :Switch2 function
  *--------------------------------------------------------------------
  *Include          :"sfr29.h"
  *                 :"define1.h"
  *                 :"declare1.h"
  *--------------------------------------------------------------------
  *Declaration      :void sw_2(void)
  *--------------------------------------------------------------------
  *Function         :Switch2 function
  *--------------------------------------------------------------------
  *Arguments        :Nothing
  *--------------------------------------------------------------------
  *Returns          :Nothing
  *--------------------------------------------------------------------
  *Input            :unsigned char trm_id           ;Transmit ID
  *                 :unsigned char trm_data_sw[]    ;Transmit data
  *                 :unsigned char trm_count_sw     ;Transmit counter
  *Ountput          :unsigned char trm_count_sw     ;Transmit counter
  *--------------------------------------------------------------------
  *Call functions   :error_fnc()                    ;Error function
  *--------------------------------------------------------------------
  *Note             :
  *--------------------------------------------------------------------
  *History          :
  *                 :
  *""FUNC COMMENT END""***********************************************/
void sw_2(void)
{
    can_std_data_def in_send_data;
    
    /* ID */
    in_send_data.id = trm_id;
    /* DLC */
    in_send_data.dlc = 1;
    /* data */
    in_send_data.data.data[0] = trm_data_sw[trm_count_sw];
    /* transmission */
    set_trm_std_dataframe_can0(TRM_SLOT,&in_send_data);     //Transmit CAN
    
    trm_count_sw++;
    if(trm_count_sw >= sizeof(trm_data_sw)){
        trm_count_sw = 0;
    }
}


 /*""FUNC COMMENT""****************************************************
  *ID               :4.4.4
  *Description      :Switch3 function
  *--------------------------------------------------------------------
  *Include          :"define1.h"
  *                 :"declare1.h"
  *--------------------------------------------------------------------
  *Declaration      :void sw_3(void)
  *--------------------------------------------------------------------
  *Function         :Switch3 function
  *--------------------------------------------------------------------
  *Arguments        :Nothing
  *--------------------------------------------------------------------
  *Returns          :Nothing
  *--------------------------------------------------------------------
  *Input            :unsigned char rcv_id           ;Receive ID
  *Ountput          :unsigned char F_RCV_DATA       ;Receive data display enable flag
  *                 :unsigned char led_data[]       ;LED display data
  *                 :unsigned char led_mode         ;LED mode
  *--------------------------------------------------------------------
  *Call functions   :
  *--------------------------------------------------------------------
  *Note             :
  *--------------------------------------------------------------------
  *History          :
  *                 :
  *""FUNC COMMENT END""***********************************************/
void sw_3(void)
{
    F_RCV_DATA = 0;                         //receive data disable
    
    led_mode = MODE_RCV_ID;                 //Display rceive ID
    led_data[0] = LED_TBL[0x0f & rcv_id];
    led_data[1] = LED_TBL[rcv_id >> 4];
}


 /*""FUNC COMMENT""****************************************************
  *ID               :4.4.5
  *Description      :Switch4_3 function
  *--------------------------------------------------------------------
  *Include          :"define1.h"
  *                 :"declare1.h"
  *--------------------------------------------------------------------
  *Declaration      :void sw_4_3(void)
  *--------------------------------------------------------------------
  *Function         :Switch4_3 function
  *--------------------------------------------------------------------
  *Arguments        :Nothing
  *--------------------------------------------------------------------
  *Returns          :Nothing
  *--------------------------------------------------------------------
  *Input            :unsigned char trm_id           ;Transmit ID
  *Ountput          :unsigned char F_RCV_DATA       ;Receive data display enable flag
  *                 :unsigned char trm_id           ;Transmit ID
  *                 :unsigned char led_data[]       ;LED display data
  *                 :unsigned char led_mode         ;LED mode
  *--------------------------------------------------------------------
  *Call functions   :
  *--------------------------------------------------------------------
  *Note             :
  *--------------------------------------------------------------------
  *History          :
  *                 :
  *""FUNC COMMENT END""***********************************************/
void sw_4_3(void)
{
    F_RCV_DATA = 0;                         //receive data disable
    trm_id++;                               //Add transmit ID
/*  if(trm_id > 0x03ff){                    //"trm_id" = 8bit
        trm_id = 0;
    }
*/
    led_data[0] = LED_TBL[0x0f & trm_id];   //Display transmit ID
    led_data[1] = LED_TBL[trm_id >> 4];
}


 /*""FUNC COMMENT""****************************************************
  *ID               :4.4.6
  *Description      :Switch4 function
  *--------------------------------------------------------------------
  *Include          :"define1.h"
  *                 :"declare1.h"
  *--------------------------------------------------------------------
  *Declaration      :void sw_4(void)
  *--------------------------------------------------------------------
  *Function         :Switch4 function
  *--------------------------------------------------------------------
  *Arguments        :Nothing
  *--------------------------------------------------------------------
  *Returns          :Nothing
  *--------------------------------------------------------------------
  *Input            :unsigned char trm_id           ;Transmit ID
  *Ountput          :unsigned char F_RCV_DATA       ;Receive data display enable flag
  *                 :unsigned char led_data[]       ;LED display data
  *                 :unsigned char led_mode         ;LED mode
  *--------------------------------------------------------------------
  *Call functions   :
  *--------------------------------------------------------------------
  *Note             :
  *--------------------------------------------------------------------
  *History          :
  *                 :
  *""FUNC COMMENT END""***********************************************/
void sw_4(void)
{
    F_RCV_DATA = 0;                          //receive data disable
    led_mode = MODE_TRM_ID;
    led_data[0] = LED_TBL[0x0f & trm_id];    //Display transmit ID
    led_data[1] = LED_TBL[trm_id >> 4];
}


 /*""FUNC COMMENT""****************************************************
  *ID               :4.4.7
  *Description      :Switch3_4 function
  *--------------------------------------------------------------------
  *Include          :"sfr29.h"
  *                 :"define1.h"
  *                 :"declare1.h"
  *--------------------------------------------------------------------
  *Declaration      :void sw_3_4(void)
  *--------------------------------------------------------------------
  *Function         :Switch3_4 function
  *--------------------------------------------------------------------
  *Arguments        :Nothing
  *--------------------------------------------------------------------
  *Returns          :Nothing
  *--------------------------------------------------------------------
  *Input            :unsigned char rcv_id           ;Receive ID
  *Ountput          :unsigned char F_RCV_DATA       ;Receive data display enable flag
  *                 :unsigned char rcv_id           ;Receive ID
  *                 :unsigned char led_data[]       ;LED display data
  *                 :unsigned char led_mode         ;LED mode
  *--------------------------------------------------------------------
  *Call functions   :abort_trm_can0()               ;Abort CAN transmit
  *--------------------------------------------------------------------
  *Note             :
  *--------------------------------------------------------------------
  *History          :
  *                 :
  *""FUNC COMMENT END""***********************************************/
void sw_3_4(void)
{
    unsigned short in_id;
    
    F_RCV_DATA = 0;                              //receive data disable
        /* When transmitting the message, stop transmitting */
        abort_trm_can0(TRM_SLOT);
        
        if((c0mctl14.receive.invaldata == 0)
         && (c0mctl15.receive.invaldata == 0)){  //Check receiving
            
            /* Stop receiveing the message */
            c0mctl14.byte = 0x00;
            c0mctl15.byte = 0x00;
            
            rcv_id++;                            //Add receive ID
/*          if(rcv_id > 0x03ff){                 //"trm_id" = 8bit
                rcv_id = 0;
            }
*/
            in_id = rcv_id;
            
            /* Set new ID and start rereceiving */
            set_rec_std_dataframe_can0(14,in_id);
            set_rec_std_dataframe_can0(15,in_id);
            
            /* Display receive ID */
            led_data[0] = LED_TBL[0x0f & rcv_id];
            led_data[1] = LED_TBL[rcv_id >> 4];
        }
}

 /*""FUNC COMMENT""****************************************************
  *ID               :4.4.8
  *Description      :Other switch function
  *--------------------------------------------------------------------
  *Include          :"declare1.h"
  *--------------------------------------------------------------------
  *Declaration      :void sw_other(void)
  *--------------------------------------------------------------------
  *Function         :Other switch function
  *--------------------------------------------------------------------
  *Arguments        :Nothing
  *--------------------------------------------------------------------
  *Returns          :Nothing
  *--------------------------------------------------------------------
  *Input            :Nothing
  *Ountput          :Nothing
  *--------------------------------------------------------------------
  *Call functions   :
  *--------------------------------------------------------------------
  *Note             :
  *--------------------------------------------------------------------
  *History          :
  *                 :
  *""FUNC COMMENT END""***********************************************/
void sw_other(void)
{
    
}

 /*""FUNC COMMENT""****************************************************
  *ID               :4.4.9
  *Description      :Return display
  *--------------------------------------------------------------------
  *Include          :"define1.h"
  *                 :"declare1.h"
  *--------------------------------------------------------------------
  *Declaration      :void dsp_return(void)
  *--------------------------------------------------------------------
  *Function         :Return display
  *--------------------------------------------------------------------
  *Arguments        :Nothing
  *--------------------------------------------------------------------
  *Returns          :Nothing
  *--------------------------------------------------------------------
  *Input            :unsigned char last_led_mode    ;Last LED mode
  *Ountput          :unsigned char led_mode         ;LED mode
  *                 :unsigned char F_RCV_DATA       ;Receive data display enable flag
  *--------------------------------------------------------------------
  *Call functions   :
  *--------------------------------------------------------------------
  *Note             :
  *--------------------------------------------------------------------
  *History          :
  *                 :
  *""FUNC COMMENT END""***********************************************/
void dsp_return(void)
{
    F_RCV_DATA = 1;             //receive data enable
    led_mode = last_led_mode;   //Return LED mode
}




⌨️ 快捷键说明

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