📄 e09a.c
字号:
/*""FILE COMMENT""*************************************************************
* System Name : for eduction (NO TRANSFERRING)
* File Name : e09a.c
* Contents : embedded C language entrance course
* : exercise 9A: confirm chattering phenomenon
* Model : for OAKS8-LCD Board
* CPU : R8C/Tiny series
* Compiler : NC30WA V.5.30 Release 1
* OS : not be used
* Programmer : RENESAS Semiconductor Training Center
* Note : for OAKS8-R5F21114FP(R8C/11 group,20MHz)
****************************************************************************
* COPYRIGHT(C) 2004 RENESAS TECHNOLOGY CORPORATION
* AND RENESAS SOLUTIONS CORPORATION ALL RIGHTS RESERVED
****************************************************************************
* History :
*""FILE COMMENT END""*******************************************************/
/*===== include file =====*/
#include "defs.h" /* define common symbol */
#include "target.h" /* SFR definition file */
#include "swutl.h" /* header file control key matrix, SW */
#include "ledutl.h" /* header file control LED */
/*===== define macro =====*/
/* decide LED digit */
#define LED0 0 /* LED0 digit */
#define LED1 1 /* LED1 digit */
#define LED2 2 /* LED2 digit */
#define LED3 3 /* LED3 digit */
/*===== define function prototype =====*/
void main(void);
static void read_sw5_edge(void);/* input SW5, detect edge sense */
static unsigned char read_sw5(void); /* input SW5 */
static int count_up(int count); /* count up from 0 to 9 */
/*===== define variable =====*/
static FLAG edge_sence; /* flag for detecting edge sense */
#define F_edge_sw5 edge_sence.bit.b0 /* flag for detecting SW5 pushed */
/* 0:FALSE:SW5 not be pushed */
/* 1:TRUE :SW5 be pushed */
/*""FUNC COMMENT""*************************************************************
* ID : ---
* function name : void main(void)
* function : LCD display changes whenever SW5 is pushed
* parameter : none
* return : none
* function used : SW__initialize2, LED__initialize, LED__puthex, read_sw5_edge
* : count_up,
* notice : none
* History : ---
*""FUNC COMMENT END""*********************************************************/
void main(void)
{
int counter = 0 ;
SW__initialize2(); /* initialize push switch SW5 */
LED__initialize(); /* initialize LCD */
LED__puthex(LED0, 0); /* initial display */
/* infinite loop */
while(1){
/* input SW5(detect when pushed, not cancel chattering) */
read_sw5_edge(); /* input SW5, detect edge sense */
/* SW5 is pushed */
if(F_edge_sw5){ /* SW5 is pushed */
F_edge_sw5 = FALSE; /* re-initialize flag for detecting SW5 pushed */
counter = count_up(counter); /* count number of push */
LED__puthex(LED0, counter); /* display number of push at LED0 */
}
}
}
/*""FUNC COMMENT""*************************************************************
* ID : ---
* function name : static void read_sw5_edge(void)
* function : input SW5, detect edge sense
* 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)
/* define function to input SW5, detect edge sense */
{
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 */
}
OldInput = Input; /* remember fixed input data this time */
}
/*""FUNC COMMENT""*************************************************************
* ID : ---
* function name : static unsigned char read_sw5(void )
* function : input SW5
* 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
* History : ---
*""FUNC COMMENT END""*********************************************************/
static unsigned char read_sw5(void) /* define function to input SW5 */
{
char NewInput; /* key input data this time */
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) */
return NewInput; /* return PushSW input status */
}
/*""FUNC COMMENT""*************************************************************
* ID : ---
* function name : static int count_up(int count)
* function : count up from 0 to 9
* parameter : count丗data for counting up
* return : int丗data after plus 1
* function used : none
* notice : when more than 9, return to 0
* History : ---
*""FUNC COMMENT END""*********************************************************/
static int count_up(int count)
/* define function to count up from 0 to 9 */
{
if(9 > count){
count++;
}
else{
count = 0;
}
return count;
}
/******************************************************************************
end of file
******************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -