📄 e11d.c
字号:
if(START == clock->state){ /* if watch is on START state */
if(++clock->second >= 60){ /* count up second, if larger than 60 */
clock->second = 0 ; /* re-initialize second */
if(++clock->minute >= 60){ /* count up minute, if larger than 60 */
clock->minute = 0 ; /* re-initialize minute */
}
}
print_clock(clock); /* display watch on LCD */
}
}
/*""FUNC COMMENT""*************************************************************
* ID : ---
* function name : static void print_clock(const T_CLOCK *clock)
* function : display watch on LCD
* parameter : clock:pointer of watch information (minute : 00 second : 00 state : STOP/START)
* return : none
* function used : none
* notice : none
* History : ---
*""FUNC COMMENT END""*********************************************************/
static void print_clock(const T_CLOCK *clock)
/* defination of function to display watch on LCD */
{
/*----- display minute -----*/
LCD__setcursol(0, 0); /* move cursor to the 1st line and 1st column of LCD */
if(clock->minute < 10 ){ /* if less than 10 minute */
LCD__putchar(' ') ; /* display a space */
}
LCD__putdec(clock->minute); /* display minute */
/*----- display second -----*/
LCD__setcursol(3, 0); /* move cursor to the 1st line and 3rd column of LCD */
if(clock->second < 10 ){ /* if less than 10 second */
LCD__putchar('0') ; /* display 0 */
LCD__putdec(clock->second); /* display second */
}
else{
LCD__putdec(clock->second); /* display second */
}
}
/*""FUNC COMMENT""*************************************************************
* ID : ---
* function name : static void change_clock_state(void)
* function : exchange watch state START to STOP or STOP to START
* parameter : clock:pointer of watch information (minute : 00 second : 00 state : STOP/START)
* return : none
* function used : none
* notice : none
* History : ---
*""FUNC COMMENT END""*********************************************************/
static void change_clock_state(T_CLOCK *clock)
/* defination of function to exchange watch state */
{
clock->state ^= 1; /* exchange watch state */
/* STOP :0 */
/* START:1 */
}
/*""FUNC COMMENT""*************************************************************
* ID : ---
* function name : static void process_clock_reset(T_CLOCK *clock)
* function : reset watch, move to STOP state
* parameter : clock:pointer of watch information (minute : 00 second : 00 state : STOP/START)
* return : none
* function used : print_clock
* notice : none
* History : ---
*""FUNC COMMENT END""*********************************************************/
static void process_clock_reset(T_CLOCK *clock)
/* defination of function to reset watch and move to STOP state */
{
clock->minute = 0; /* re-initialize minute */
clock->second = 0; /* re-initialize second */
print_clock(clock); /* display watch on LCD */
clock->state = STOP; /* move to STOP state */
}
/*""FUNC COMMENT""*************************************************************
* ID : ---
* function name : static void read_sw5_edge(void)
* function : input SW5 and detect edge and long pushed
* parameter : none
* return : none
* function used : read_sw5
* notice : remember in detection flag(F_edge_SW5) when SW5 is pushed
* History : ---
*""FUNC COMMENT END""*********************************************************/
#define SW5_ON 0x20 /* SW5 is ON (bit 5) */
#define SW5_OFF 0x00 /* SW5 is OFF */
static void read_sw5_edge(void) /* input SW5, detect edge丄 */
/* define function to input SW5, detect long pushed */
{
unsigned char Input; /* fixed key input data this time */
static unsigned char OldInput = SW5_ON;
/* fixed key input data last time */
Input = read_sw5(); /* input SW5, get input status with more than or equal twice */
if((SW5_ON == Input) && (SW5_OFF == OldInput)){
F_edge_sw5 = TRUE; /* set flag for SW5 pushed */
}
else if((SW5_ON == Input) && (SW5_ON == OldInput)){
F_LongSW = TRUE; /* start measuring long pushed time */
/* when F_LongSW is true, measure long */
/* pushed time with timer interrupt */
}
else{
F_LongSW = FALSE; /* re-initialize SW5 long pushed flag */
F_long_sw5 = FALSE; /* re-initialize flag for detecting SW5 long pushed */
}
OldInput = Input; /* remember fixed input data this time */
}
/*""FUNC COMMENT""*************************************************************
* ID : ---
* function name : static unsigned char read_sw5(void )
* function : input SW5(cancel chattering)
* parameter : none
* return : unsigned char ; fixed input data from SW5
* function used : none
* notice : measure port input status, "L" is ON, "H" is OFF,
* : mask all other than SW5 input port with "1", reverse active
* : not update data when no more than or equal twice
* History : ---
*""FUNC COMMENT END""*********************************************************/
static unsigned char read_sw5(void)
/* define function to input SW5(cancel chattering) */
{
static unsigned char FixdInput = 0; /* fixed key input data(initial is OFF) */
unsigned char NewInput; /* key input data this time */
static unsigned char OldInput = SW5_ON;
/* key input data last time */
static unsigned char CountAgree; /* same numbe of key input data */
/* input SW5(mask processing, change active) */
NewInput = p0; /* input port P0 */
NewInput |= 0xdf; /* mask all other than SW5 input port with "1" */
NewInput ^= 0xff; /* reverse active(measure as "1" when SW is ON)*/
/* compare input data between this time and last time */
if( NewInput != OldInput ){
/*--- inut data this time is not same as last time ---*/
CountAgree = 0; /* initialize same counter */
/* remember input data differ from last time */
OldInput = NewInput;
}
else{
/*--- inut data this time is the same as last time ---*/
++CountAgree; /* count same counter */
/* the same input data is more than or equal twice */
if( 2 <= CountAgree ){
CountAgree = 0; /* fix if same to the third time */
FixdInput = NewInput; /* fix key input data */
}
}
return FixdInput; /* return fixed key input data */
}
/*""FUNC COMMENT""*************************************************************
* ID : ---
* function name : void INTtx(void)
* function : count when timer X interrupt occurs
* : (called by timer X interrupt program when time passed)
* parameter : none
* return : none
* function used : none
* notice : interrupt function called by interrupt program
* : use global variable userflag
* History : ---
*""FUNC COMMENT END""*********************************************************/
#define CYCLICTIME_100ms 20 /* value for how many times count base time(5ms) */
/* 5ms*20=100ms */
#define CYCLICTIME_1s 200 /* value for how many times count base time(5ms) */
/* 5ms*200=1s */
#define CYCLICTIME_LongSW 100 /* value for how many times count base time(5ms) */
/* 5ms*100=500ms */
void INTtx(void) /* define function for timer X interrupt */
{
static unsigned char TimeFor100ms = CYCLICTIME_100ms;
static int TimeFor1s = CYCLICTIME_1s;
static int TimeForLongSW = CYCLICTIME_LongSW;
F_Key = TRUE; /* set key update flag */
if(0 == --TimeFor100ms){ /* if 100ms passed */
TimeFor100ms = CYCLICTIME_100ms; /* re-initialize 100ms counter */
F_RefreshAdDisp = TRUE; /* set A-D conversion update flag */
}
if(0 == --TimeFor1s){ /* if 1s passed */
TimeFor1s = CYCLICTIME_1s; /* re-initialize 1s counter */
F_Clock = TRUE; /* set watch update flag */
}
if(TRUE == F_LongSW){ /* if measuring long pushed time */
if(0 == --TimeForLongSW){ /* if passed the long pushed time */
TimeForLongSW = CYCLICTIME_LongSW;
/* re-initialize long pushed time measuring counter */
F_long_sw5 = TRUE; /* set flag for detecting SW5 long pushed */
}
}
else{
TimeForLongSW = CYCLICTIME_LongSW;
/* re-initialize long pushed time measuring counter */
}
}
/******************************************************************************
end of file
******************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -