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

📄 timer.c

📁 4510 study
💻 C
📖 第 1 页 / 共 3 页
字号:
/*             Print: Total test time is 3:30:20.8                       */
/*                                                                       */
/* VARIABLES USED                                                        */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*         NAME            DATE                    REMARKS               */
/*                                                                       */
/*        in4maker      06-07-1999      Created initial version 1.0      */
/*                                                                       */
/*************************************************************************/
/*
void PrtSysTime(int TIMER_DEV,char *s)
{
    char buff[MAX_LINE_BUF];
    int i;
    int sec,ms;
    
    if(TIMER_DEV) {
        sec = tm1.tm_sec+(int)(clk_tick1/TICKS_PER_SECOND);
        ms =  (clk_tick1%TICKS_PER_SECOND);
        sprintf(buff,"%s is %d:%d:%d.%d",s,tm1.tm_hour,tm1.tm_min,sec,ms);
        put_string(buff);
        for(i=0;i < MAX_LINE_BUF;i++)  put_byte('\b'); 
               
    }
    else {
            sec = tm0.tm_sec+(int)(clk_tick0/TICKS_PER_SECOND);
            ms  = (clk_tick0%TICKS_PER_SECOND);
            sprintf(buff,"%s is %d:%d:%d.%d",s,tm0.tm_hour,tm0.tm_min,sec,ms);
            put_string(buff);
            for(i=0;i < MAX_LINE_BUF;i++)  put_byte('\b'); 
    }
}

*/
/*************************************************************************/
/*                                                                       */
/* NAME : GetSysTime(timer device)                                       */
/*                                                                       */
/* FUNCTIONS : return system time display string                         */
/*                                                                       */
/* EXAMPLES :                                                            */
/*             put_string(GetSysTime(TIMER_DEV0));                       */
/*             Printed : time =  6:30:27.30                              */
/*                                                                       */
/* VARIABLES USED                                                        */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*         NAME            DATE                    REMARKS               */
/*                                                                       */
/*        in4maker      06-07-1999      Created initial version 1.0      */
/*                                                                       */
/*************************************************************************/
/*
char *GetSysTime(int TIMER_DEV)
{
    char buff[MAX_LINE_BUF];
    int sec,ms;

    
    if(TIMER_DEV) 
    {
        sec = tm1.tm_sec+(int)(clk_tick1/TICKS_PER_SECOND);
        ms =  (clk_tick1%TICKS_PER_SECOND);
        sprintf(buff,"time = %d:%d:%d.%d",tm1.tm_hour,tm1.tm_min,sec,ms);
        return(buff);
    }
    else {
           sec = tm0.tm_sec+(int)(clk_tick0/TICKS_PER_SECOND);
           ms  = (clk_tick0%TICKS_PER_SECOND);
           sprintf(buff,"time = %d:%d:%d.%d",tm0.tm_hour,tm0.tm_min,sec,ms);
           return(buff);
    }
}
*/

/*************************************************************************/
/*                                                                       */
/* NAME : tm0isr()                                                       */
/*                                                                       */
/* FUNCTIONS : Timer0 interrupt service routine.                         */
/*                                                                       */
/* EXAMPLES :                                                            */
/*                                                                       */
/*       SysSetInterrupt(nTIMER0_INT, tm0isr);                           */
/*                                                                       */
/* VARIABLES USED                                                        */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*         NAME            DATE                    REMARKS               */
/*                                                                       */
/*        in4maker      06-07-1999      Created initial version 1.0      */
/*                                                                       */
/*************************************************************************/
void tm0isr(void)
{
    clk_tick0++;  

     if(clk_tick0 == TICKS_PER_SECOND) 
     {
         clk_tick0 = 0;
         if(tm0.tm_sec++ > 59) 
         { 
              tm0.tm_sec = 0;
              if(tm0.tm_min++ > 59) 
              {  
                  tm0.tm_min = 0;
                  if(tm0.tm_hour++ > 23) 
                  {
                      tm0.tm_hour = 0;
                      if(tm0.tm_mday++ > 30) 
                      {
                          tm0.tm_mday = 0;
                          if(tm0.tm_mon++ > 11) 
                          { 
                              tm0.tm_mon = 0; 
                              tm0.tm_year++;
                           }
                       }
                  }
              }
          }
          /* 4 means digit number for LED display */
          IOPDATA = ~(1<<tm0.tm_sec%4); 
    }  
}



/*************************************************************************/
/*                                                                       */
/* NAME : tm1isr()                                                       */
/*                                                                       */
/* FUNCTIONS : Timer1 interrupt service routine.                         */
/*                                                                       */
/* EXAMPLES :                                                            */
/*                                                                       */
/*       SysSetInterrupt(nTIMER1_INT, tm1isr);                           */
/*                                                                       */
/* VARIABLES USED                                                        */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*         NAME            DATE                    REMARKS               */
/*                                                                       */
/*        in4maker      06-07-1999      Created initial version 1.0      */
/*                                                                       */
/*************************************************************************/
void tm1isr(void)
{
    clk_tick1++;  

     if(clk_tick1 == TICKS_PER_SECOND) 
     {
         clk_tick1 = 0;
         if(tm1.tm_sec++ > 59) 
         { 
              tm1.tm_sec = 0;
              if(tm1.tm_min++ > 59) 
              {  
                  tm1.tm_min = 0;
                  if(tm1.tm_hour++ > 23) 
                  {
                      tm1.tm_hour = 0;
                      if(tm1.tm_mday++ > 30) 
                      {
                          tm1.tm_mday = 0;
                          if(tm1.tm_mon++ > 11) 
                          { 
                              tm1.tm_mon = 0; 
                              tm1.tm_year++;
                           }
                       }
                  }
              }
          }
          /* 4 means digit number for LED display */
          IOPDATA = ~(16<<tm1.tm_sec%4); 
    }  
}


/*************************************************************************/
/*                                                                       */
/* NAME : WaitTime_ms(timer device, timer value[ms])                     */
/*                                                                       */
/* FUNCTIONS : Time delay function. time will be delayed by the given    */
/*             value.                                                    */
/*                                                                       */
/* EXAMPLES :                                                            */
/*                                                                       */
/*       WaitTime_ms(TIMER_DEV0, ONE_SECOND);                            */
/*                                                                       */
/* VARIABLES USED                                                        */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*         NAME            DATE                    REMARKS               */
/*                                                                       */
/*        in4maker      06-07-1999      Created initial version 1.0      */
/*                                                                       */
/*************************************************************************/
void WaitTime_ms(int TIMER_DEV, int t)
{
    int rDATA;

    rDATA = t_data_ms(t); 

    if(TIMER_DEV) {
         TDATA1 = 0;    /* Clear Timer data register */
         TCNT1  = 0;    /* Clear timer counter register */

         Timer1Start();
         //Print("\r\rWait for %d ms time delay.\r",t);
         while(TCNT1 < rDATA);
         Timer1Stop();
    }
    else {
           TDATA0 = 0;    /* Clear Timer data register */
           TCNT0  = 0;    /* Clear timer counter register */
           Timer0Start();
           //Print("\r\rWait for %d ms time delay.\r",t);
           while(TCNT0 < rDATA);
           Timer0Stop();
    }
}


/*************************************************************************/
/*                                                                       */
/* FILE NAME                                      VERSION                */
/*                                                                       */
/*      timer.c                    		 KS32C50100   : version 1.0 */
/*                                                                       */
/* COMPONENT                                                             */
/*                                                                       */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*                                                                       */
/* AUTHOR                                                                */
/*                                                                       */
/*      Young Sun KIM, Samsung Electronics, Inc.                         */
/*                                                                       */
/* DATA STRUCTURES                                                       */
/*                                                                       */
/*                                                                       */
/* FUNCTIONS                                                             */

⌨️ 快捷键说明

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