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

📄 washer.lst

📁 Keil uVision2下用C语言开发的洗衣机嵌入式系统代码
💻 LST
字号:
C51 COMPILER V6.21  WASHER                                                                 01/23/2002 18:02:34 PAGE 1   


C51 COMPILER V6.21, COMPILATION OF MODULE WASHER
OBJECT MODULE PLACED IN Washer.OBJ
COMPILER INVOKED BY: C:\KEIL\C51\BIN\C51.EXE Washer.c BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          /*------------------------------------------------------------------*-
   2          
   3             Washer.C (v1.01)
   4          
   5            ------------------------------------------------------------------
   6          
   7             Multi-state framework for washing-machine controller.
   8          
   9          
  10             COPYRIGHT
  11             ---------
  12          
  13             This code is associated with the book:
  14          
  15             EMBEDDED C by Michael J. Pont 
  16             [Pearson Education, 2002: ISBN: 0-201-79523-X].
  17          
  18             This code is copyright (c) 2001 by Michael J. Pont.
  19           
  20             See book for copyright details and other information.
  21          
  22          -*------------------------------------------------------------------*/
  23          
  24          #include "Main.H"
  25          #include "Port.H"
  26          
  27          #include "Washer.H"
  28          
  29          // ------ Private data type declarations ---------------------------
  30          
  31          // Possible system states
  32          typedef enum {INIT, START, FILL_DRUM, HEAT_WATER, 
  33                        WASH_01, WASH_02, ERROR} eSystem_state;
  34          
  35          // ------ Private function prototypes ------------------------------
  36          
  37          tByte WASHER_Read_Selector_Dial(void);
  38          bit   WASHER_Read_Start_Switch(void);
  39          bit   WASHER_Read_Water_Level(void);
  40          bit   WASHER_Read_Water_Temperature(void);
  41          
  42          void  WASHER_Control_Detergent_Hatch(bit);
  43          void  WASHER_Control_Door_Lock(bit);
  44          void  WASHER_Control_Motor(bit);
  45          void  WASHER_Control_Pump(bit);
  46          void  WASHER_Control_Water_Heater(bit);
  47          void  WASHER_Control_Water_Valve(bit);
  48          
  49          // ------ Private constants ----------------------------------------
  50          
  51          #define OFF 0
  52          #define ON 1
  53          
  54          #define MAX_FILL_DURATION (tLong) 1000
  55          #define MAX_WATER_HEAT_DURATION (tLong) 1000
C51 COMPILER V6.21  WASHER                                                                 01/23/2002 18:02:34 PAGE 2   

  56          
  57          #define WASH_01_DURATION 30000
  58          
  59          // ------ Private variables ----------------------------------------
  60          
  61          static eSystem_state System_state_G;
  62          
  63          static tWord Time_in_state_G;
  64          
  65          static tByte Program_G;
  66          
  67          // Ten different programs are supported
  68          // Each one may or may not use detergent
  69          static tByte Detergent_G[10] = {1,1,1,0,0,1,0,1,1,0};
  70          
  71          // Each one may or may not use hot water
  72          static tByte Hot_Water_G[10] = {1,1,1,0,0,1,0,1,1,0};
  73          
  74          /* --------------------------------------------------------------- */
  75          void WASHER_Init(void)
  76             {
  77   1         System_state_G = INIT;
  78   1         }
  79          
  80          
  81          /* --------------------------------------------------------------- */
  82          void WASHER_Update(void)
  83             {
  84   1         // Call once per second
  85   1         switch (System_state_G)
  86   1            {
  87   2                case INIT:
  88   2                   {
  89   3               // For demo purposes only
  90   3               Debug_port = (tByte) System_state_G;
  91   3      
  92   3               // Set up initial state
  93   3               // Motor is off
  94   3               WASHER_Control_Motor(OFF);
  95   3      
  96   3               // Pump is off
  97   3               WASHER_Control_Pump(OFF);
  98   3      
  99   3               // Heater is off
 100   3               WASHER_Control_Water_Heater(OFF);
 101   3      
 102   3               // Valve is closed
 103   3               WASHER_Control_Water_Valve(OFF);
 104   3      
 105   3               // Wait (indefinitely) until START is pressed
 106   3               if (WASHER_Read_Start_Switch() != 1)
 107   3                          {
 108   4                              return;
 109   4                              }
 110   3               
 111   3               // Start switch pressed...
 112   3               // Read the selector dial
 113   3               Program_G = WASHER_Read_Selector_Dial();
 114   3      
 115   3                       // Change state
 116   3               System_state_G = START;
 117   3                       break;
C51 COMPILER V6.21  WASHER                                                                 01/23/2002 18:02:34 PAGE 3   

 118   3               }
 119   2      
 120   2            case START: 
 121   2               {
 122   3               // For demo purposes only
 123   3               Debug_port = (tByte) System_state_G;
 124   3      
 125   3               // Lock the door
 126   3               WASHER_Control_Door_Lock(ON);
 127   3      
 128   3               // Start filling the drum
 129   3               WASHER_Control_Water_Valve(ON);
 130   3      
 131   3               // Release the detergent (if any)
 132   3               if (Detergent_G[Program_G] == 1)
 133   3                  {
 134   4                  WASHER_Control_Detergent_Hatch(ON);
 135   4                  }
 136   3      
 137   3               // Ready to go to next state
 138   3               System_state_G = FILL_DRUM;
 139   3               Time_in_state_G = 0;
 140   3      
 141   3               break;
 142   3               }
 143   2      
 144   2            case FILL_DRUM: 
 145   2               {
 146   3               // For demo purposes only
 147   3               Debug_port = (tByte) System_state_G;
 148   3      
 149   3               // Remain in this state until drum is full
 150   3               // NOTE: Timeout facility included here
 151   3               if (++Time_in_state_G >= MAX_FILL_DURATION)
 152   3                  {
 153   4                  // Should have filled the drum by now...
 154   4                  System_state_G = ERROR;
 155   4                  }
 156   3      
 157   3               // Check the water level
 158   3               if (WASHER_Read_Water_Level() == 1)
 159   3                  {
 160   4                  // Drum is full
 161   4      
 162   4                  // Does the program require hot water?
 163   4                  if (Hot_Water_G[Program_G] == 1)
 164   4                     {
 165   5                     WASHER_Control_Water_Heater(ON);
 166   5      
 167   5                     // Ready to go to next state
 168   5                     System_state_G = HEAT_WATER;
 169   5                     Time_in_state_G = 0;
 170   5                     }
 171   4                  else
 172   4                     {
 173   5                     // Using cold water only
 174   5                     // Ready to go to next state
 175   5                     System_state_G = WASH_01;
 176   5                     Time_in_state_G = 0;
 177   5                     }
 178   4                  }
 179   3               break;
C51 COMPILER V6.21  WASHER                                                                 01/23/2002 18:02:34 PAGE 4   

 180   3               }
 181   2      
 182   2            case HEAT_WATER: 
 183   2               {
 184   3               // For demo purposes only
 185   3               Debug_port = (tByte) System_state_G;
 186   3      
 187   3               // Remain in this state until water is hot
 188   3               // NOTE: Timeout facility included here
 189   3               if (++Time_in_state_G >= MAX_WATER_HEAT_DURATION)
 190   3                  {
 191   4                  // Should have warmed the water by now...
 192   4                  System_state_G = ERROR;
 193   4                  }
 194   3      
 195   3               // Check the water temperature
 196   3               if (WASHER_Read_Water_Temperature() == 1)
 197   3                  {
 198   4                  // Water is at required temperature
 199   4                  // Ready to go to next state
 200   4                  System_state_G = WASH_01;
 201   4                  Time_in_state_G = 0;
 202   4                  }
 203   3      
 204   3               break;
 205   3               }
 206   2      
 207   2            case WASH_01: 
 208   2               {
 209   3               // For demo purposes only
 210   3               Debug_port = (tByte) System_state_G;
 211   3      
 212   3               // All wash program involve WASH_01
 213   3               // Drum is slowly rotated to ensure clothes are fully wet
 214   3               WASHER_Control_Motor(ON);
 215   3      
 216   3               if (++Time_in_state_G >= WASH_01_DURATION)
 217   3                  {
 218   4                  System_state_G = WASH_02;
 219   4                  Time_in_state_G = 0;
 220   4                  }
 221   3      
 222   3               break;
 223   3               }
 224   2      
 225   2            // REMAINING WASH PHASES OMITTED HERE ...
 226   2      
 227   2            case WASH_02: 
 228   2               {
 229   3               // For demo purposes only
 230   3               Debug_port = (tByte) System_state_G;
 231   3      
 232   3               break;
 233   3               }
 234   2      
 235   2            case ERROR: 
 236   2               {
 237   3               // For demo purposes only
 238   3               Debug_port = (tByte) System_state_G;
 239   3      
 240   3               break;
 241   3               }
C51 COMPILER V6.21  WASHER                                                                 01/23/2002 18:02:34 PAGE 5   

 242   2            }
 243   1         }
 244          
 245          /* --------------------------------------------------------------- */
 246          tByte WASHER_Read_Selector_Dial(void)
 247             {
 248   1         // User code here...
 249   1      
 250   1         return 0;
 251   1         }
 252          
 253          /* --------------------------------------------------------------- */
 254          bit WASHER_Read_Start_Switch(void)
 255             {
 256   1         // Simplified for demo ...
 257   1      
 258   1         if (Start_pin == 0)
 259   1            {
 260   2                // Start switch pressed
 261   2                return 1;
 262   2                }
 263   1         else
 264   1            {
 265   2            return 0;
 266   2            }
 267   1         }
 268          
 269          /* --------------------------------------------------------------- */
 270          bit WASHER_Read_Water_Level(void)
 271             {
 272   1         // User code here...
 273   1      
 274   1         return 1;
 275   1         }
 276          
 277          /* --------------------------------------------------------------- */
 278          bit WASHER_Read_Water_Temperature(void)
 279             {
 280   1         // User code here...
 281   1      
 282   1         return 1;
 283   1         }
 284          
 285          /* --------------------------------------------------------------- */
 286          void WASHER_Control_Detergent_Hatch(bit State)
 287             {
 288   1         bit Tmp = State;
 289   1         // User code here...
 290   1         }
 291          
 292          /* --------------------------------------------------------------- */
 293          void WASHER_Control_Door_Lock(bit State)
 294             {
 295   1         bit Tmp = State;
 296   1         // User code here...
 297   1         }
 298          
 299          /* --------------------------------------------------------------- */
 300          void WASHER_Control_Motor(bit State)
 301             {
 302   1         bit Tmp = State;
 303   1         // User code here...
C51 COMPILER V6.21  WASHER                                                                 01/23/2002 18:02:34 PAGE 6   

 304   1         }
 305          
 306          /* --------------------------------------------------------------- */
 307          void WASHER_Control_Pump(bit State)
 308             {
 309   1         bit Tmp = State;
 310   1         // User code here...
 311   1         }
 312          
 313          /* --------------------------------------------------------------- */
 314          void WASHER_Control_Water_Heater(bit State)
 315             {
 316   1         bit Tmp = State;
 317   1         // User code here...
 318   1         }
 319          
 320          /* --------------------------------------------------------------- */
 321          void WASHER_Control_Water_Valve(bit State)
 322             {
 323   1         bit Tmp = State;
 324   1         // User code here...
 325   1         }
 326          
 327          /*------------------------------------------------------------------*-
 328            ---- END OF FILE -------------------------------------------------
 329          -*------------------------------------------------------------------*/
 330          
 331          
 332          
 333          
 334          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    302    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     24    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----      12
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

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