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

📄 rili.lst

📁 频率计 闸门时间0.1s 1s 10s 频率范围0~99khz 可以切换 里面有四个源程序
💻 LST
📖 第 1 页 / 共 3 页
字号:
 202          {
 203              ClkTickCtr = 0;
 204              Clk_set_time(11,32,0);
 205          #if CLK_DATE_EN
 206              Clk_set_date(5,28,2002);
 207          #endif    
 208          }
 209          /*
 210          *********************************************************************************************************
 211          *                                    FORMAT CURRENT DATE INTO STRING
 212          *
 213          * Description : Formats the current date into an ASCII string.
 214          * Arguments   : mode   is the format type:
 215          *                      1   will format the time as "MM-DD-YY"           (needs at least  9 characters)
 216          *                      2   will format the time as "Day Month DD, YYYY" (needs at least 30 characters)
 217          *                      3   will format the time as "YYYY-MM-DD"         (needs at least 11 characters)
 218          *               s      is a pointer to the destination string.  The destination string must be large
 219          *                      enough to hold the formatted date.
 220          *                      contain
 221          * Returns     : None.
 222          * Notes       : - A 'switch' statement has been used to allow you to add your own date formats.  For
 223          *                 example, you could display the date in French, Spanish, German etc. by assigning
 224          *                 numbers for those types of conversions.
 225          *               - This function assumes that strcpy(), strcat() and itoa() are reentrant.
 226          *********************************************************************************************************
 227          */
 228          #if  CLK_DATE_EN
 229          void  Clk_format_date (UCHAR mode, char *s)
 230          {
 231              UINT  year;
 232              char    str[5];
 233              
 234              switch (mode) 
C51 COMPILER V7.50   RILI                                                                  10/24/2008 17:36:12 PAGE 5   

 235                 {
 236                  case  1:
 237                        strcpy(s, "MM-DD-YY");             /* Create the template for the selected format        */
 238                        s[0] = ClkMonth / 10 + '0';        /* Convert DATE to ASCII                              */
 239                        s[1] = ClkMonth % 10 + '0';
 240                        s[3] = ClkDay   / 10 + '0';
 241                        s[4] = ClkDay   % 10 + '0';
 242                        year = ClkYear % 100;
 243                        s[6] = year / 10 + '0';
 244                        s[7] = year % 10 + '0';
 245                        break;
 246          
 247                  case  2:
 248                        strcpy(s, ClkDOWTbl[ClkDOW]);                  /* Get the day of the week                */
 249                        strcat(s, ClkMonthTbl[ClkMonth].MonthName);    /* Get name of month                      */
 250                        if (ClkDay < 10)
 251                         {
 252                           str[0] = ClkDay + '0';
 253                           str[1] = 0;
 254                         } 
 255                        else
 256                         {
 257                           str[0] = ClkDay / 10 + '0';
 258                           str[1] = ClkDay % 10 + '0';
 259                           str[2] = 0;
 260                         }
 261                        strcat(s, str);
 262                        strcat(s, ", ");
 263                        sprintf(str,"%d",ClkYear); 
 264                        strcat(s, str);
 265                        break;
 266          
 267                  case  3:
 268                        strcpy(s, "YYYY-MM-DD");            /* Create the template for the selected format        */
 269                        s[0] = year / 1000 + '0';
 270                        year = year % 1000;
 271                        s[1] = year /  100 + '0';
 272                        year = year %  100;
 273                        s[2] = year /   10 + '0';
 274                        s[3] = year %   10 + '0';
 275                        s[5] = ClkMonth / 10 + '0';        /* Convert DATE to ASCII                              */
 276                        s[6] = ClkMonth % 10 + '0';
 277                        s[8] = ClkDay   / 10 + '0';
 278                        s[9] = ClkDay   % 10 + '0';
 279                        break;
 280          
 281                  default:
 282                        strcpy(s, "?");
 283                        break;
 284              }
 285          }
 286          #endif
 287          /*
 288          *********************************************************************************************************
 289          *                                    FORMAT CURRENT TIME INTO STRING
 290          *
 291          * Description : Formats the current time into an ASCII string.
 292          * Arguments   : mode   is the format type:
 293          *                      1   will format the time as "HH:MM:SS"     (24 Hour format)
 294          *                                                                 (needs at least  9 characters)
 295          *                      2   will format the time as "HH:MM:SS AM"  (With AM/PM indication)
 296          *                                                                 (needs at least 13 characters)
C51 COMPILER V7.50   RILI                                                                  10/24/2008 17:36:12 PAGE 6   

 297          *               s      is a pointer to the destination string.  The destination string must be large
 298          *                      enough to hold the formatted time.
 299          *                      contain
 300          * Returns     : None.
 301          * Notes       : - A 'switch' statement has been used to allow you to add your own time formats.
 302          *               - This function assumes that strcpy() is reentrant.
 303          *********************************************************************************************************
 304          */
 305          void  Clk_format_time (UCHAR mode, char *s)
 306          {
 307              UCHAR hr;
 308              switch (mode)
 309               {
 310                  case  1:
 311                        strcpy(s, "HH:MM:SS");                  /* Create the template for the selected format   */
 312                        s[0] = ClkHr  / 10 + '0';               /* Convert TIME to ASCII                         */
 313                        s[1] = ClkHr  % 10 + '0';
 314                        s[3] = ClkMin / 10 + '0';
 315                        s[4] = ClkMin % 10 + '0';
 316                        s[6] = ClkSec / 10 + '0';
 317                        s[7] = ClkSec % 10 + '0';
 318                        break;
 319          
 320                  case  2:
 321                        strcpy(s, "HH:MM:SS AM");               /* Create the template for the selected format   */
 322                        s[9] = (ClkHr >= 12) ? 'P' : 'A';       /* Set AM or PM indicator                        */
 323                        if (ClkHr > 12) 
 324                          {                                     /* Adjust time to be displayed                   */
 325                            hr   = ClkHr - 12;
 326                          } 
 327                        else
 328                          {
 329                            hr = ClkHr;
 330                          }
 331                        s[0] = hr     / 10 + '0';               /* Convert TIME to ASCII                         */
 332                        s[1] = hr     % 10 + '0';
 333                        s[3] = ClkMin / 10 + '0';
 334                        s[4] = ClkMin % 10 + '0';
 335                        s[6] = ClkSec / 10 + '0';
 336                        s[7] = ClkSec % 10 + '0';
 337                        break;
 338          
 339                  default:
 340                        strcpy(s, "?");
 341                        break;
 342              }
 343          }
 344          /*
 345          *********************************************************************************************************
 346          *                                            UPDATE THE TIME
 347          *
 348          * Description : This function is called to update the time (i.e. hours, minutes and seconds)
 349          * Arguments   : None.
 350          * Returns     : TRUE     if we have completed one day.
 351          *               FALSE    otherwise
 352          * Notes       : This function updates ClkSec, ClkMin and ClkHr.
 353          *********************************************************************************************************
 354          */
 355          static  BOOL  ClkUpdateTime (void)
 356          {
 357              BOOL newday;
 358              
C51 COMPILER V7.50   RILI                                                                  10/24/2008 17:36:12 PAGE 7   

 359              newday = FALSE;                           /* Assume that we haven't completed one whole day yet      *
             -/
 360              if (ClkSec >= 59)
 361               {                                        /* See if we have completed one minute yet                 *
             -/
 362                    ClkSec = 0;                         /* Yes, clear seconds                                      *
             -/
 363                    if (ClkMin >= 59)
 364                      {                                 /*    See if we have completed one hour yet                *
             -/
 365                        ClkMin = 0;                     /*    Yes, clear minutes                                   *
             -/
 366                        if (ClkHr >= 23) 
 367                         {                              /*        See if we have completed one day yet             *
             -/
 368                           ClkHr = 0;                   /*        Yes, clear hours ...                             *
             -/
 369                           newday    = TRUE;            /*        ... change flag to indicate we have a new day    *
             -/
 370                         } 
 371                        else
 372                         {
 373                          ClkHr++;                      /*        No,  increment hours                             *
             -/
 374                         }
 375                      }
 376                    else
 377                     {
 378                      ClkMin++;                         /*    No,  increment minutes                               *
             -/
 379                     }
 380               } 
 381              else
 382               {
 383                  ClkSec++;                             /* No,  increment seconds                                  *
             -/
 384               }
 385              return (newday);
 386          }
 387          /*
 388          *********************************************************************************************************
 389          *                                          SET TIME ONLY
 390          *
 391          * Description : Set the time-of-day clock
 392          * Arguments   : hr        is the desired hour    (0..23)
 393          *               min       is the desired minutes (0..59)
 394          *               sec       is the desired seconds (0..59)
 395          * Returns     : None.
 396          * Notes       : It is assumed that you are specifying a correct time (i.e. there is no range checking
 397          *               done by this function).
 398          *********************************************************************************************************
 399          */
 400          void  Clk_set_time (UCHAR hr, UCHAR min, UCHAR sec)
 401          {
 402              ENTER_CRITICAL();                         /* Gain exclusive access to time-of-day clock         */
 403              ClkHr  = hr;
 404              ClkMin = min;
 405              ClkSec = sec;
 406              EXIT_CRITICAL();                          /* Release access to time-of-day clock                */
 407          }

⌨️ 快捷键说明

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