📄 e11d.c
字号:
/*""FILE COMMENT""*************************************************************
* System Name : for eduction (NO TRANSFERRING)
* File Name : e11d.c
* Contents : exercise 11D: write Motolora S format file in flash memory
* :
* 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 "lcdutl.h" /* header file control LCD */
#include "txutl.h" /* header file control TimerX */
#include "ad1utl.h" /* header file control A-D conversion */
#include "intr_i0.h" /* interrupt service program definition file */
/* define T_CLOCK type structure */
typedef struct t_clock{
unsigned char minute ; /* minute( 0乣59) */
unsigned char second ; /* second(00乣59) */
int state; /* state */
}T_CLOCK ;
/*===== define macro =====*/
#define STOP 0 /* watch on STOP state */
#define START 1 /* watch on START state */
/*===== define function prototype =====*/
void main(void);
static void interruptTX_initialize(void);
/* initialize timer X interrupt */
static void AdToLcdDisp(void); /* get A-D conversion result, display bar in LCD */
static void process_clock(T_CLOCK *clock);
/* count up the watch (minute : second), */
/* display on LCD */
static void print_clock(const T_CLOCK *clock);
/* display watch on LCD (minute : second) */
static void change_clock_state(T_CLOCK *clock);
/* exchange watch state */
static void process_clock_reset(T_CLOCK *clock);
/* reset watch display, move to STOP state */
static void read_sw5_edge(void);/* input SW5, detect the edge */
/* detect long pushed */
static unsigned char read_sw5(void);
/* input SW5(with chattering cancelling) */
void INTtx(void); /* timer X interrupt function */
/* not add static because it is called */
/* from interrupt program intr_i0.a30 */
/*===== define variable =====*/
static volatile FLAG time_flag; /* flag for detecting time passed */
#define F_RefreshAdDisp time_flag.bit.b0/* A-D update(100ms passed) flag */
/* 0:FALSE:not updated */
/* 1:TRUE :updated */
#define F_Clock time_flag.bit.b1/* watch update flag */
/* 0:FALSE:not updated */
/* 1:TRUE :updated */
#define F_Key time_flag.bit.b2/* key update flag */
/* 0:FALSE:not updated */
/* 1:TRUE :updated */
#define F_LongSW time_flag.bit.b3/* flag for measuring time of SW5 long pushed */
/* 0:FALSE:not measure */
/* 1:TRUE :measure */
static volatile FLAG sw_sence; /* flag for detecting SW */
#define F_edge_sw5 sw_sence.bit.b0 /* flag for detecting SW5 pushed */
/* 0:FALSE:not pushed */
/* 1:TRUE :pushed */
#define F_long_sw5 sw_sence.bit.b1
/* flag for detecting SW5 long pushed */
/* 0:FALSE:no long pushed */
/* 1:TRUE :long pushed */
/*""FUNC COMMENT""*************************************************************
* ID : ---
* function name : void main(void)
* function : display A-D conversion result and 60 minute watch with START/STOP and RESET function
* parameter : none
* return : none
* function used : SW__initialize2, LCD__initialize, AD1__initialize,
* : TX__initialize, interruptTX_initialize, LCD__puts, ei
* : process_clock, AdToLcdDisp, read_sw5_edge, process_clock_reset
* notice : none
* History : ---
*""FUNC COMMENT END""*********************************************************/
void main(void)
{
static T_CLOCK clock = { 0 , 0, STOP }; /* watch information */
/* minute : 00 second : 00 state : STOP */
SW__initialize2(); /* initialize SW5 */
LCD__initialize(); /* initialize port */
AD1__initialize(); /* initialize A-D conversion */
TX__initialize(); /* initialize timer X(5ms period) */
interruptTX_initialize(); /* set timer X interrupt */
LCD__puts(" 0:00"); /* display initial watch */
ei(); /* permit interrupt */
/* infinite loop */
while(1){
if(F_Clock){ /* time to update watch passed */
F_Clock = FALSE; /* re-initialize watch update flag */
process_clock(&clock); /* count up watch (minute : second) */
/* display on LCD */
}
if(F_RefreshAdDisp){ /* time to update A-D conversion result passed */
F_RefreshAdDisp = FALSE; /* re-initialize A-D conversion update flag */
AdToLcdDisp(); /* get A-D conversion result, display bar in LCD */
}
if(F_Key){ /* time to update key passed */
F_Key = FALSE; /* re-initialize key update flag */
read_sw5_edge(); /* detect SW5 input edge*/
if(F_edge_sw5){ /* SW5 is pushed */
F_edge_sw5 = FALSE; /* re-initialize flag for detecting SW5 pushed */
change_clock_state(&clock); /* exchange watch state */
}
}
if(F_long_sw5){ /* SW5 is long pushed */
F_long_sw5 = FALSE; /* re-initialize flag for detecting SW5 long pushed */
process_clock_reset(&clock); /* reset watch display */
/* move to STOP state */
}
}
}
/*""FUNC COMMENT""*************************************************************
* ID : ---
* function name : static void interruptTX_initialize(void)
* function : initialize timer X interrupt
* parameter : none
* return : none
* function used : none
* notice : none
* History : ---
*""FUNC COMMENT END""*********************************************************/
static void interruptTX_initialize(void)
/* define function to initialize timer X interrupt */
{
txic = 0x01 ; /* set timer X interrupt control register */
/* xxxx0001 */
/* |+++---- interrupt priority level */
/* +------- interrupt request bit */
}
/*""FUNC COMMENT""*************************************************************
* ID : ---
* function name : void AdToLcdDisp(void)
* function : get A-D conversion result, display bar in LCD
* : 0x000 to 0x07f : □□□□□□□ 0x200 to 0x27f : ■■■■□□□
* : 0x080 to 0x0ff : ■□□□□□□ 0x280 to 0x2ff : ■■■■■□□
* : 0x100 to 0x17f : ■■□□□□□ 0x300 to 0x37f : ■■■■■■□
* : 0x180 to 0x1ff : ■■■□□□□ 0x380 to 0x3ff : ■■■■■■■
* parameter : none
* return : none
* function used : none
* notice : none
* History : ---
*""FUNC COMMENT END""*********************************************************/
#define WT ' ' /* space character */
#define BK 0xff /* ■ character */
static void AdToLcdDisp(void)
/* define function to get A-D conversion result, display bar in LCD */
{
/* LCD bar display pattern response to A-D conversion result */
/* define two-dimensional array with 8 lines and 8 columns */
static const unsigned char LevelMeter_ptn[][8] = {
WT, WT, WT, WT, WT, WT, WT, '\0' , /* A-D conversion result:0x000 to 0x07f*/
BK, WT, WT, WT, WT, WT, WT, '\0', /* A-D conversion result:0x080 to 0x0ff*/
BK, BK, WT, WT, WT, WT, WT, '\0', /* A-D conversion result:0x100 to 0x17f*/
BK, BK, BK, WT, WT, WT, WT, '\0', /* A-D conversion result:0x180 to 0x1ff*/
BK, BK, BK, BK, WT, WT, WT, '\0', /* A-D conversion result:0x200 to 0x27f*/
BK, BK, BK, BK, BK, WT, WT, '\0', /* A-D conversion result:0x280 to 0x2ff*/
BK, BK, BK, BK, BK, BK, WT, '\0', /* A-D conversion result:0x300 to 0x37f*/
BK, BK, BK, BK, BK, BK, BK, '\0' /* A-D conversion result:0x380 to 0x3ff*/
};
unsigned int result_ad1; /* A-D conversion result(0x000 to 0x3ff) */
int i;
result_ad1 = AD1__getad1(); /* get A-D conversion result */
result_ad1 >>= 7; /* shift right for 7 bits */
LCD__setcursol( 0 , 1 ); /* set LCD display position at the 2nd line and the 1st column*/
LCD__puts(&LevelMeter_ptn[result_ad1][0]);
/* display string showing bar */
/* in suitable line in LCD */
}
/*""FUNC COMMENT""*************************************************************
* ID : ---
* function name : static void process_clock(T_CLOCK *clock)
* function : count up watch (minute : second) and display on LCD
* 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(T_CLOCK *clock)
/* defination of function to count up watch (minute : second) and display on LCD */
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -