📄 sw_led2.c
字号:
/*""FILE COMMENT""****************************************************
*System Name : CAN DEMO PROGRAM2
*File Name : sw_led2.c
*Version : 1.00
*Contens :
*Customer : RSO
*Model :
*Order :
*CPU :
*Compiler : NC30 Version 5.30 Release 02
*OS :
*Programmer :
*Note :
* :
**********************************************************************
* Copyright(C)2005, Renesas Technology Corp.
* Copyright(C)2005, Renesas Solutions Corp.
* All rights reserved.
*
**********************************************************************
*History 2005.07.1 Ver 1.00
*""FILE COMMENT END""************************************************/
#include "sfr29.h"
#include "define2.h"
#include "declare2.h"
/*""FUNC COMMENT""****************************************************
*ID :3.0
*Description :Initialize Switch and LED
*--------------------------------------------------------------------
*Include :"sfr29.h"
* :"define2.h"
* :"declare2.h"
*--------------------------------------------------------------------
*Declaration :void sw_led_initial(void)
*--------------------------------------------------------------------
*Function :Initialize Switch and LED
*--------------------------------------------------------------------
*Arguments :Nothing
*--------------------------------------------------------------------
*Returns :Nothing
*--------------------------------------------------------------------
*Input :Nothing
*Ountput :unsigned char led_data[] ;LED display data
* :unsigned char trm_led_data[] ;Transmit data
*--------------------------------------------------------------------
*Call functions :Nothing
*--------------------------------------------------------------------
*Note :
*--------------------------------------------------------------------
*History :
* :
*""FUNC COMMENT END""***********************************************/
void sw_led_initial(void)
{
/* LED initial */
p0 = 0x03;
p2 = 0xff;
pd0 = 0x03;
pd2 = 0xff;
led_data[0] = LED_TBL[0x00]; //initial LED dsp
led_data[1] = LED_TBL[0x00]; //
/* SW initial */
pd8_2 = 0; //SW2(INT0)
pd8_3 = 0; //SW3(INT1)
pd8_4 = 0; //SW4(INT2)
/* variable initial */
trm_led_data[0] = DATA_CLWS; //set transmit data
trm_led_data[1] = DATA_ANTCLWS; //
trm_led_data[2] = DATA_HALF_CLWS; //
}
/*""FUNC COMMENT""****************************************************
*ID :3.1
*Description :LED dynamic lightning
*--------------------------------------------------------------------
*Include :"sfr29.h"
* :"define2.h"
* :"declare2.h"
*--------------------------------------------------------------------
*Declaration :void led_fnc(void)
*--------------------------------------------------------------------
*Function :LED dynamic lightning
*--------------------------------------------------------------------
*Arguments :Nothing
*--------------------------------------------------------------------
*Returns :Nothing
*--------------------------------------------------------------------
*Input :unsigned char led_data[] ;LED display data
* :unsigned char led_count ;LED counter
*Ountput :unsigned char led_count ;LED counter
*--------------------------------------------------------------------
*Call functions :Nothing
*--------------------------------------------------------------------
*Note :
*--------------------------------------------------------------------
*History :
* :
*""FUNC COMMENT END""***********************************************/
void led_fnc(void)
{
p0 = 0x03; //LED OFF
led_count++;
if(led_count > 1){
led_count = 0;
}
//set led data
p2 = led_data[led_count];
p0 = 0x01 << led_count; //LED ON
}
/*""FUNC COMMENT""****************************************************
*ID :3.2
*Description :Switch function
*--------------------------------------------------------------------
*Include :"sfr29.h"
* :"define2.h"
* :"declare2.h"
*--------------------------------------------------------------------
*Declaration :void sw_fnc(void)
*--------------------------------------------------------------------
*Function :Switch function
*--------------------------------------------------------------------
*Arguments :Nothing
*--------------------------------------------------------------------
*Returns :Nothing
*--------------------------------------------------------------------
*Input :Nothing
*Ountput :Nothing
*--------------------------------------------------------------------
*Call functions :sw_down() ;Switch down function
* :fix_sw_fnc() ;Fix switch function
* :sw_decode() ;Switch decode function
*--------------------------------------------------------------------
*Note :
*--------------------------------------------------------------------
*History :
* :
*""FUNC COMMENT END""***********************************************/
void sw_fnc(void)
{
unsigned char in_data,i;
in_data = p8 & PT_SW_MASK;
if(fix_sw_fnc(in_data)){
i = sw_decode();
if(i){
sw_down(i-1);
}
}
}
/*""FUNC COMMENT""****************************************************
*ID :3.2.1
*Description :Switch decode function
*--------------------------------------------------------------------
*Include :"define2.h"
* :"declare2.h"
*--------------------------------------------------------------------
*Declaration :unsigned char sw_decode(void)
*--------------------------------------------------------------------
*Function :Switch decode function
*--------------------------------------------------------------------
*Arguments :Nothing
*--------------------------------------------------------------------
*Returns :unsigned char in_rtn ;Decode number
*--------------------------------------------------------------------
*Input :unsigned char fix_sw_data ;Fixed switch data
* :unsigned char last_fix_sw_data ;Last fixed switch data
*Ountput :unsigned char last_fix_sw_data ;Last fixed switch data
*--------------------------------------------------------------------
*Call functions :error_fnc() ;Error function
*--------------------------------------------------------------------
*Note :
*--------------------------------------------------------------------
*History :
* :
*""FUNC COMMENT END""***********************************************/
unsigned char sw_decode(void)
{
unsigned char in_rtn = 0;
if(last_fix_sw_data != PT_NO_SW){
in_rtn = 0;
}
else{
switch(fix_sw_data){
case PT_NO_SW: //no SW
in_rtn = 0;
break;
case PT_SW2: //SW2
in_rtn = 1;
break;
case PT_SW3: //SW3
in_rtn = 2;
break;
case PT_SW4: //SW4
in_rtn = 3;
break;
default:
in_rtn = 0;
break;
}
}
last_fix_sw_data = fix_sw_data;
return in_rtn;
}
/*""FUNC COMMENT""****************************************************
*ID :3.2.2
*Description :Fix switch function
*--------------------------------------------------------------------
*Include :"sfr29.h"
* :"define2.h"
* :"declare2.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++;
}
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 :3.2.3
*Description :Switch down function
*--------------------------------------------------------------------
*Include :"sfr29.h"
* :"define2.h"
* :"declare2.h"
*--------------------------------------------------------------------
*Declaration :void sw_down(unsigned char in_trm_num)
*--------------------------------------------------------------------
*Function :Switch2 down function
*--------------------------------------------------------------------
*Arguments :Nothing
*--------------------------------------------------------------------
*Returns :Nothing
*--------------------------------------------------------------------
*Input :unsigned char trm_id ;Transmit ID
* :unsigned char trm_led_data[] ;Transmit data
*Ountput :Nothing
*--------------------------------------------------------------------
*Call functions :error_fnc() ;Error function
*--------------------------------------------------------------------
*Note :
*--------------------------------------------------------------------
*History :
* :
*""FUNC COMMENT END""***********************************************/
void sw_down(unsigned char in_trm_num)
{
can_std_data_def in_trm_data;
/* ID */
in_trm_data.id = trm_id;
/* DLC */
in_trm_data.dlc = TRM_DLC;
/* data */
if(in_trm_num >= sizeof(trm_led_data)){
error_fnc(CAN_TRM_ERROR);
}
in_trm_data.data.data[0] = trm_led_data[in_trm_num];
/* transmission */
set_trm_std_dataframe_can0(TRM_SLOT,&in_trm_data);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -