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

📄 traffic.lst

📁 Keil中文版
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.00  TRAFFIC                                                                01/04/2003 15:10:31 PAGE 1   


C51 COMPILER V7.00, COMPILATION OF MODULE TRAFFIC
OBJECT MODULE PLACED IN Traffic.OBJ
COMPILER INVOKED BY: C:\KEIL\C51\BIN\C51.EXE Traffic.c BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          /******************************************************************************/
   2          /*                                                                            */
   3          /*   TRAFFIC.C:  Traffic Light Controller using the C-51 COMPILER             */
   4          /*                                                                            */
   5          /******************************************************************************/
   6          
   7          char code menu[] = 
   8             "\n"
   9             "+***** TRAFFIC LIGHT CONTROLLER using C51 and RTX-51 tiny *****+\n"
  10             "| This program is a simple Traffic Light Controller.  Between  |\n"
  11             "| start time and end time the system controls a traffic light  |\n"
  12             "| with pedestrian self-service.  Outside of this time range    |\n"
  13             "| the yellow caution lamp is blinking.                         |\n"
  14             "+ command -+ syntax -----+ function ---------------------------+\n"
  15             "| Display  | D           | display times                       |\n"
  16             "| Time     | T hh:mm:ss  | set clock time                      |\n"
  17             "| Start    | S hh:mm:ss  | set start time                      |\n"
  18             "| End      | E hh:mm:ss  | set end time                        |\n"
  19             "+----------+-------------+-------------------------------------+\n";
  20          
  21          
  22          #include <reg52.h>                    /* special function registers 8052      */
  23          #include <rtx51tny.h>                 /* RTX-51 tiny functions & defines      */
  24          #include <stdio.h>                    /* standard I/O .h-file                 */
  25          #include <ctype.h>                    /* character functions                  */
  26          #include <string.h>                   /* string and memory functions          */
  27          
  28          
  29          extern getline (char idata *, char);  /* external function:  input line       */
  30          extern serial_init ();                /* external function:  init serial UART */
  31          
  32          #define INIT      0                   /* task number of task:  init           */
  33          #define COMMAND   1                   /* task number of task:  command        */
  34          #define CLOCK     2                   /* task number of task:  clock          */
  35          #define BLINKING  3                   /* task number of task:  blinking       */
  36          #define LIGHTS    4                   /* task number of task:  signal         */
  37          #define KEYREAD   5                   /* task number of task:  keyread        */
  38          #define GET_ESC   6                   /* task number of task:  get_escape     */
  39          
  40          struct time  {                        /* structure of the time record         */
  41            unsigned char hour;                 /* hour                                 */
  42            unsigned char min;                  /* minute                               */
  43            unsigned char sec;                  /* second                               */
  44          };
  45          
  46          struct time ctime = { 12,  0,  0 };   /* storage for clock time values        */
  47          struct time start = {  7, 30,  0 };   /* storage for start time values        */
  48          struct time end   = { 18, 30,  0 };   /* storage for end   time values        */
  49          
  50          sbit  red    = P1^2;                  /* I/O Pin:  red    lamp output         */
  51          sbit  yellow = P1^1;                  /* I/O Pin:  yellow lamp output         */
  52          sbit  green  = P1^0;                  /* I/O Pin:  green  lamp output         */
  53          sbit  stop   = P1^3;                  /* I/O Pin:  stop   lamp output         */
  54          sbit  walk   = P1^4;                  /* I/O Pin:  walk   lamp output         */
  55          sbit  key    = P1^5;                  /* I/O Pin:  self-service key input     */
C51 COMPILER V7.00  TRAFFIC                                                                01/04/2003 15:10:31 PAGE 2   

  56          
  57          char idata inline[16];                /* storage for command input line       */
  58          
  59          
  60          /******************************************************************************/
  61          /*        Task 0 'init': Initialize                                           */
  62          /******************************************************************************/
  63          void init (void) _task_ INIT  {       /* program execution starts here        */
  64   1        serial_init ();                     /* initialize the serial interface      */
  65   1        os_create_task (CLOCK);             /* start clock task                     */
  66   1        os_create_task (COMMAND);           /* start command task                   */
  67   1        os_create_task (LIGHTS);            /* start lights task                    */
  68   1        os_create_task (KEYREAD);           /* start keyread task                   */
  69   1        os_delete_task (INIT);              /* stop init task (no longer needed)    */
  70   1      }
  71          
  72          
  73          bit display_time = 0;                 /* flag:  signal cmd state display_time */
  74          
  75          /******************************************************************************/
  76          /*        Task 2 'clock'                                                      */
  77          /******************************************************************************/
  78          void clock (void)  _task_ CLOCK  {
  79   1        while (1)  {                        /* clock is an endless loop             */
  80   2          if (++ctime.sec == 60)  {         /* calculate the second                 */
  81   3            ctime.sec = 0;
  82   3            if (++ctime.min == 60)  {       /* calculate the minute                 */
  83   4              ctime.min = 0;
  84   4              if (++ctime.hour == 24)  {    /* calculate the hour                   */
  85   5                ctime.hour = 0;
  86   5              }
  87   4            }
  88   3          }
  89   2          if (display_time)  {              /* if command_status == display_time    */
  90   3            os_send_signal (COMMAND);       /* signal to task command: time changed */
  91   3          }
  92   2          os_wait (K_IVL, 100, 0);          /* wait interval:  1 second             */
  93   2        }
  94   1      }
  95          
  96          
  97          struct time rtime;                    /* temporary storage for entry time     */
  98          
  99          /******************************************************************************/
 100          /*        readtime: convert line input to time values & store in rtime        */
 101          /******************************************************************************/
 102          bit readtime (char idata *buffer)  {
 103   1        unsigned char args;                          /* number of arguments         */
 104   1      
 105   1        rtime.sec = 0;                               /* preset second               */
 106   1        args = sscanf (buffer, "%bd:%bd:%bd",        /* scan input line for         */
 107   1                       &rtime.hour,                  /* hour, minute and second     */
 108   1                       &rtime.min,
 109   1                       &rtime.sec);
 110   1        
 111   1        if (rtime.hour > 23  ||  rtime.min > 59  ||  /* check for valid inputs      */
 112   1            rtime.sec > 59   ||  args < 2        ||  args == EOF)  {
 113   2          printf ("\n*** ERROR: INVALID TIME FORMAT\n");
 114   2          return (0);
 115   2        }
 116   1        return (1);
 117   1      }
C51 COMPILER V7.00  TRAFFIC                                                                01/04/2003 15:10:31 PAGE 3   

 118          
 119          
 120          
 121          #define ESC  0x1B                     /* ESCAPE character code                */
 122          
 123          bit   escape;                         /* flag: mark ESCAPE character entered  */
 124          
 125          /******************************************************************************/
 126          /*        Task 6 'get_escape': check if ESC (escape character) was entered    */
 127          /******************************************************************************/
 128          void get_escape (void) _task_ GET_ESC  {
 129   1        while (1)  {                                 /* endless loop                */
 130   2          if (_getkey () == ESC)  escape = 1;        /* set flag if ESC entered     */
 131   2          if (escape)  {                             /* if escape flag send signal  */
 132   3            os_send_signal (COMMAND);                /* to task 'command'           */
 133   3          }
 134   2        }
 135   1      }
 136          
 137          
 138          /******************************************************************************/
 139          /*        Task 1 'command': command processor */
 140          /******************************************************************************/
 141          void command (void) _task_ COMMAND  {
 142   1        unsigned char i;
 143   1      
 144   1        printf (menu);                               /* display command menu        */
 145   1        while (1)  {                                 /* endless loop                */
 146   2          printf ("\nCommand: ");                    /* display prompt              */
 147   2          getline (&inline, sizeof (inline));        /* get command line input      */
 148   2      
 149   2          for (i = 0; inline[i] != 0; i++)  {        /* convert to uppercase        */
 150   3            inline[i] = toupper(inline[i]);
 151   3          }
 152   2      
 153   2          for (i = 0; inline[i] == ' '; i++);        /* skip blanks                 */
 154   2      

⌨️ 快捷键说明

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