⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 使用KD30编译后就可以下载到实验箱中运行了。
💻 C
字号:
/*""FILE COMMENT""*************************************************************
*  System Name : This program is only for education.
*  File Name   : main.c
*  Contents    : Practice 4-A time management by timer ---sample---
*  Model       : OAKS16-LCD Board
*  CPU         : M16C/60 Serials
*  Compiler    : M16C/60 NC30 COMPILER V.4.00 Release 2 - Entry
*  OS          : NON
*  Programer   : RENESAS Semiconductor Training Center
*  Note        : For OAKS16-M30620FCAFP(M16C/62group,16MHz)
*******************************************************************************
* COPYRIGHT(C) 2004 RENESAS TECHNOLOGY CORPORATION ALL RIGHTS RESERVED 
*               AND RENESAS SOLUTIONS CORPORATION ALL RIGHTS RESERVED
*******************************************************************************
* History      : ---
*""FILE COMMENT END""*********************************************************/
#include "sfr62p.h"
unsigned char BitCode[4]={
    0x10, 0x08, 0x04, 0x02
};
unsigned char SegCode[]={
    0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x00
};
unsigned char GetKeyCode( void );

unsigned char DispCode[4];
int TimeFor1s;
/*===== prototype declaration =====*/
void main(void);                        
static void init_ta0(void);             /* initialization of timer A0       */
static char count_up_0to9(char Count);  /* count up (0乣9)      */
void DisplayLED( void );
/*===== variable declaration =====*/


/*""FUNC COMMENT""*************************************************************
* ID             : ---
* Function name  : void main(void)
* Feature        : repeatly count up from 0(initial value) to 9 every 1s
*                : and display the count value in SingleLED as BCD code 
*                : every time.
*                : timer is started cyclically (polling). 
* Argument       : NON
* Return value   : NON
* Called function: init_ta0()           ; initialization of timer A0
*                : count_up_0to9()      ; count up from 0 to 9 
* Causion        : NON
* History        : ---
*""FUNC COMMENT END""*********************************************************/
#define SET     1               /* set the symbol SET to 1                 */
#define CLEAR   0               /* set the symbol CLEAR to 0               */
#define TRUE    1               /* when condition is satisfied             */
#define FALSE   0               /* when condition is not satisfied          */
#define CYCLICTIME  0          /* to count the set time(100ms)   */
                                /* 100ms亊10times = 1000ms = 1s                */
void main(void)
{
   
    char Count = 0;                 /* the data conted up every 1s  */
    char DispLED = 0x00;            /* output data to SingleLED        */
 TimeFor1s = CYCLICTIME;    /* 1s counter (100ms亊10=1000ms)    */
    /* Port initialization */
    p2   = 0xff;                    /* set SingleLED to off          */
    pd2  = 0xff;                    /* set Port P7 to output           */
	 pd3 = 0x00;  
    /* initialization of timer A0 */
    init_ta0();
    
    while(1){
        /* judgment for passing 100ms */
	DispCode[0]=0;
	DispCode[1]=0;
	DispCode[2]=0;
	DispCode[3]=0;
	while(p3_0==0){
        if( ir_ta0ic == SET ){      /* as soon as passed 100ms, timer A0 interrupt   */
                                    /* request bit (bit3) is set. */
            ir_ta0ic = CLEAR;       /* clearing timer A0 interrupt request bit  */
            
            /* judgment for passing 1s */
            TimeFor1s++;
			
            if( TimeFor1s == 1000 ){           /* passed 1s?             */
                TimeFor1s = CYCLICTIME;     /* initialize 1s counter    */
                
                /* updata the count data (0乣9) */
                Count = count_up_0to9( Count );
                /* updata display data */
                DispLED = Count;
				
            }
			DispCode[0]=TimeFor1s%10;
			DispCode[1]=TimeFor1s/100;
			DispCode[2]=DispLED%10;
			DispCode[3]=DispLED/10;
			DisplayLED();
            /* output to SingleLED */
                /*p2 = DispLED ^ 0xff;*/
        }
		}
	while(p3_0==1){
			DisplayLED();
			Count=0;
			TimeFor1s=CYCLICTIME;
			DispLED=0;
		}
    }
}


/*""FUNC COMMENT""*************************************************************
* ID               : ---
* Function name    : static void init_ta0(void)
* Feature          : initialization of timer A0 
* Argument         : NON
* Return value     : NON
* Called function  : NON
* Causion          : NON
* History          : ---
*""FUNC COMMENT END""*********************************************************/
static void init_ta0(void)
{
    ta0mr = 0x80;                   /* setting timer A0 mode register         */
                                    /* 10000000                             */
                                    /* ||||||++---- timer  mode            */
                                    /* |||||+------ pulse is not output        */
                                    /* |||++------- gate function not availble  */
                                    /* ||+--------- timer mode       */
                                    /* ++----------  count source is f32       */
                                    /*              (f(XIN)=24MHz:(4/3)兪s))    */
    ta0=749;/*ta0 = 49999;  */                   /* setting timer A0 register (100ms)         */
                                    /* 749 = (1ms / (4/3)兪s) -1              */
    ir_ta0ic = CLEAR;               /* clearign timer A0 interrupt request  bit     */
    ta0s = SET;                     /* setting timer A0 count to start           */
}


/*""FUNC COMMENT""*************************************************************
* ID                : ---
* Function name     : static char count_up_0to9(char Count)
* Feature           : repeatly count up during 0乣9
* Argument          : char Count;  count up data
* Return value      : char;       count up data after 1 s
* Called function   : NON
* Causion           : return to 0 if the count data is graeter than 9
* History           : ---
*""FUNC COMMENT END""*********************************************************/
static char count_up_0to9(char Count)
{
    if(60 < ++Count){
        Count = 0;
    }
    return Count;
}


void DisplayLED( void )
{
    unsigned char itemp,delayt;
    for(itemp=0; itemp<4; itemp++) {
        p2 = 0x00;
        p5 = BitCode[itemp];
        p2 = SegCode[DispCode[itemp]];
        for(delayt=0; delayt<0xFF; delayt++);
    }
}

/******************************************************************************
    end of file
******************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -