📄 sw_led1.c
字号:
/*""FILE COMMENT""****************************************************
*System Name : CAN DEMO PROGRAM1
*File Name : sw_led1.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 "define1.h"
#include "declare1.h"
/*""FUNC COMMENT""****************************************************
*ID :4.0
*Description :Initialize Switch and LED
*--------------------------------------------------------------------
*Include :"sfr29.h"
* :"define1.h"
* :"declare1.h"
*--------------------------------------------------------------------
*Declaration :void sw_led_initial(void)
*--------------------------------------------------------------------
*Function :Initialize Switch and LED
*--------------------------------------------------------------------
*Arguments :Nothing
*--------------------------------------------------------------------
*Returns :Nothing
*--------------------------------------------------------------------
*Input :Nothing
*Ountput :unsigned char F_RCV_DATA ;Receive data display enable flag
* :unsigned char trm_count_sw ;Transmit switch counter
* :unsigned char led_mode ;LED mode
* :unsigned char last_led_mode ;Last LED mode
* :unsigned char led_data[] ;LED display data
* :unsigned char sw_count ;Switch counter
* :unsigned char last_sw_data ;Last switch data
*--------------------------------------------------------------------
*Call functions :Nothing
*--------------------------------------------------------------------
*Note :
*--------------------------------------------------------------------
*History :
* :
*""FUNC COMMENT END""***********************************************/
void sw_led_initial(void)
{
unsigned char i;
/* LED port initial */
p0 = 0x03;
p2 = 0xff;
pd0 = 0x03;
p0 = 0x03;
pd2 = 0xff;
p2 = 0xff;
/* SW port initial */
pd8_2 = 0; //SW2(INT0)
pd8_3 = 0; //SW3(INT1)
pd8_4 = 0; //SW4(INT2)
/* variable initial */
F_RCV_DATA = 1; //receive data disp enable
trm_count_sw = 0;
led_mode = MODE_CLWS; //set LED mode
last_led_mode = MODE_CLWS; //
led_data[0] = LED_PT1_TBL[0]; //set initial LED dsp
led_data[1] = LED_PT2_TBL[0]; //set initial LED dsp
sw_count = 0;
last_sw_data = 0;
}
/*""FUNC COMMENT""****************************************************
*ID :4.1
*Description :LED dynamic lightning
*--------------------------------------------------------------------
*Include :"sfr29.h"
* :"define1.h"
* :"declare1.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)
{
/* LED */
p0 = 0x03; //LED OFF
led_count++;
if(led_count > 1){
led_count = 0;
}
p2 = led_data[led_count]; //set led data
p0 = 0x01 << led_count; //LED ON
}
/*""FUNC COMMENT""****************************************************
*ID :4.2
*Description :Change LED display pattern
*--------------------------------------------------------------------
*Include :"sfr29.h"
* :"define1.h"
* :"declare1.h"
*--------------------------------------------------------------------
*Declaration :void led_pt_fnc(void)
*--------------------------------------------------------------------
*Function :Change LED display pattern
*--------------------------------------------------------------------
*Arguments :Nothing
*--------------------------------------------------------------------
*Returns :Nothing
*--------------------------------------------------------------------
*Input :unsigned char led_mode ;LED mode
* :unsigned char led_pt_count ;LED display pattern counter
*Ountput :unsigned char led_data[] ;LED display data
* :unsigned char led_pt_count ;LED display pattern counter
*--------------------------------------------------------------------
*Call functions :error_fnc() ;Error function
*--------------------------------------------------------------------
*Note :
*--------------------------------------------------------------------
*History :
* :
*""FUNC COMMENT END""***********************************************/
void led_pt_fnc(void)
{
switch (led_mode){
case MODE_CLWS:
led_pt_count++;
if(led_pt_count >= sizeof(LED_PT1_TBL)){
led_pt_count = 0;
}
led_data[0] = LED_PT1_TBL[led_pt_count];
led_data[1] = LED_PT2_TBL[led_pt_count];
break;
case MODE_ANTCLWS:
led_pt_count--;
if(led_pt_count >= sizeof(LED_PT1_TBL)){
led_pt_count = sizeof(LED_PT1_TBL)-1;
}
led_data[0] = LED_PT1_TBL[led_pt_count];
led_data[1] = LED_PT2_TBL[led_pt_count];
break;
case MODE_HALF_CLWS:
led_pt_count++;
if(led_pt_count >= sizeof(LED_PT5_TBL)){
led_pt_count = 0;
}
led_data[0] = LED_PT5_TBL[led_pt_count];
led_data[1] = LED_PT6_TBL[led_pt_count];
break;
case MODE_RCV_ID:
break;
case MODE_TRM_ID:
break;
default:
error_fnc(LED_ERROR);
break;
}
}
/*""FUNC COMMENT""****************************************************
*ID :4.3
*Description :Change LED mode
*--------------------------------------------------------------------
*Include :"sfr29.h"
* :"define1.h"
* :"declare1.h"
*--------------------------------------------------------------------
*Declaration :void led_mode_change(void)
*--------------------------------------------------------------------
*Function :Change LED mode
*--------------------------------------------------------------------
*Arguments :Nothing
*--------------------------------------------------------------------
*Returns :Nothing
*--------------------------------------------------------------------
*Input :unsigned char F_RCV_DATA ;Receive data display enable flag
* :unsigned char led_mode ;LED mode
* :unsigned char last_rcv_data ;Last CAN receive data
*Ountput :unsigned char led_data[] ;LED display data
* :unsigned char led_mode ;LED mode
* :unsigned char last_led_mode ;Last LED mode
*--------------------------------------------------------------------
*Call functions :error_fnc() ;Error function
*--------------------------------------------------------------------
*Note :
*--------------------------------------------------------------------
*History :
* :
*""FUNC COMMENT END""***********************************************/
void led_mode_change(void)
{
unsigned char in_last_rcv_data;
if(F_RCV_DATA == 0){ //receive data disable?
return;
}
in_last_rcv_data = last_rcv_data;
switch (in_last_rcv_data){
case DATA_CLWS:
if(led_mode != MODE_CLWS){ //mode change clockwise
led_mode = MODE_CLWS;
last_led_mode = led_mode;
ta0 = DATA_CLWS_TM;
}
break;
case DATA_ANTCLWS:
if(led_mode != MODE_ANTCLWS){ //mode change anticlockwise
led_mode = MODE_ANTCLWS;
last_led_mode = led_mode;
ta0 = DATA_ANTCLWS_TM;
}
break;
case DATA_HALF_CLWS:
if(led_mode != MODE_HALF_CLWS){ //mode change half clockwise
led_mode = MODE_HALF_CLWS;
last_led_mode = led_mode;
ta0 = DATA_HALF_CLWS_TM;
}
break;
default:
break;
}
}
/*""FUNC COMMENT""****************************************************
*ID :4.4
*Description :Switch function
*--------------------------------------------------------------------
*Include :"sfr29.h"
* :"define1.h"
* :"declare1.h"
*--------------------------------------------------------------------
*Declaration :void sw_fnc(void)
*--------------------------------------------------------------------
*Function :Switch function
*--------------------------------------------------------------------
*Arguments :Nothing
*--------------------------------------------------------------------
*Returns :Nothing
*--------------------------------------------------------------------
*Input :Nothing
*Ountput :Nothing
*--------------------------------------------------------------------
*Call functions :error_fnc() ;Error function
* :sw_2() ;Switch2 function
* :sw_3() ;Switch3 function
* :sw_4() ;Switch4 function
* :sw_3_4() ;Switch3_4 function
* :sw_4_3() ;Switch4_3 function
* :sw_other() ;Other switch function
* :fix_sw_fnc() ;Fix swithc function
* :sw_decode() ;Swithc 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_TBL_SIZE){ //table check
(*SW_TBL[i])(); //call sw fnc
}
else{
error_fnc(TABLE_ERROR);
}
}
}
/*""FUNC COMMENT""****************************************************
*ID :4.4.1
*Description :Switch decode function
*--------------------------------------------------------------------
*Include :"define1.h"
* :"declare1.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;
switch(fix_sw_data){
case PT_NO_SW: //no SW
in_rtn = 0;
break;
case PT_SW2: //SW2
if(last_fix_sw_data == PT_NO_SW){
in_rtn = 1;
}
else{
in_rtn = 6;
}
break;
case PT_SW3: //SW3
in_rtn = 2;
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -