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

📄 test.lst

📁 一个51单片机温度控制器,又一个示范如何在2051这样的小内存小ROM单片机上实现实时多任务小例子.使用时间片和状态机来完成任务的调度,而不是靠任务切换机制(这样小的资源是不足以支持RTOS的)
💻 LST
📖 第 1 页 / 共 3 页
字号:
 238   2                      if (temper_not_test_count == 0){
 239   3                              TEMPER_KEY = 1;                 //停止放电,开始充电
 240   3                              temp_test_cycle = TESTING;
C51 COMPILER V7.04   TEST                                                                  05/10/2004 15:25:07 PAGE 5   

 241   3                              temper_test_count = 0;
 242   3                      }
 243   2              }
 244   1              //测温例程结束
 245   1      
 246   1              jiffies++;
 247   1              if (jiffies < 10)
 248   1                      return;
 249   1              jiffies = 0;
 250   1              sys_wake_up = 1;
 251   1              sys_clock++;
 252   1              if(timer_isr_stop)
 253   1                      return;
 254   1              if(!(warm_start || light_start || jx_start))
 255   1                      return;
 256   1              time_ms++;
 257   1              if(time_ms == 1000)//同步闪烁与字符跳变
 258   1                      disp_flash = 0;
 259   1              if (time_ms == 1000){//1000 == 1 Sec{
 260   2                      time_ms = 0;
 261   2                      time_sec++;
 262   2              }
 263   1              if (time_sec == 60){
 264   2                      time_sec = 0;
 265   2                      time_min++;
 266   2                      if(time_min == 1440)
 267   2                              time_min = 0;
 268   2              }
 269   1      }
 270          
 271          void timer_init(void){
 272   1              TMOD=0x02;                      //自动重装模式
 273   1      //      TH0=TL0=0x9b;//12M
 274   1      //      TH0=TL0=0x7a;//16M
 275   1      //      TH0=TL0=0x75;//16.59M
 276   1      //      TH0=TL0=0x72;//17M
 277   1      //      TH0=TL0=0x37;//24M
 278   1              TH0=TL0=-200;//24M
 279   1              EA=1;
 280   1              ET0=1;
 281   1              TR0=1;
 282   1      
 283   1              TEMPER_KEY = 0;         //开机即开始对电容放电.
 284   1      }
 285          
 286          void out_time(unsigned int out_time){
 287   1              disp_buff[3] = font[(out_time/100)%10];
 288   1              disp_buff[4] = font[(out_time/10)%10];
 289   1              disp_buff[5] = font[out_time%10];
 290   1      }
 291          
 292          void out_temper(unsigned char out_temper){
 293   1      #if 0
                      disp_buff[0] = 0;
                      disp_buff[1] = font[(temper_gate/1000)%10];
                      disp_buff[3] = font[(temper_gate/100)%10];
                      disp_buff[4] = font[(temper_gate/10)%10];
                      disp_buff[5] = font[temper_gate%10];
              #else
 300   1              disp_buff[0] = font[(out_temper/10)%10];
 301   1              disp_buff[1] = font[out_temper%10];
 302   1      #endif
C51 COMPILER V7.04   TEST                                                                  05/10/2004 15:25:07 PAGE 6   

 303   1      }
 304          
 305          void out_jx_light(void){
 306   1              unsigned char jx_light_st = 0;
 307   1              if (jx_start)
 308   1                      jx_light_st |= 0x0f;
 309   1              if (light_start)
 310   1                      jx_light_st |= 0xf0;
 311   1              disp_buff[2] = jx_light_st;
 312   1      }
 313          
 314          
 315          
 316          typedef struct temper_tab_s{
 317                  unsigned int temper_gate;
 318                  unsigned char temper;
 319          }temper_tab_t;
 320          
 321          
 322          
 323          unsigned char temper_gate2temper(unsigned int _temper_gate){
 324   1              unsigned int t = 55626;
 325   1              t /= (_temper_gate/10);
 326   1              t -= 273;
 327   1              if (t>255)
 328   1                      return 0;
 329   1              return (unsigned char)t;
 330   1      }
 331          
 332          #define FUCTION_TEMPER10                0
 333          #define FUCTION_TEMPER                  1
 334          #define FUCTION_TIME_MIN100             2
 335          #define FUCTION_TIME_MIN10              3
 336          #define FUCTION_TIME_MIN                4
 337          #define FUCTION_NORMAL                  5
 338          unsigned char function_select = FUCTION_NORMAL;
 339          
 340          bit key_set = 0;
 341          bit key_func = 0;
 342          bit key_power = 0;
 343          bit key_warm_start = 0;
 344          bit key_light_start = 0;
 345          bit key_jx_start = 0;
 346          
 347          #define PUSH_DELAY 200          //100ms
 348          #define FIRST_PUSH_DELAY 500            //250ms
 349          
 350          unsigned int light_timer_start = 0;
 351          unsigned int light_timer = 30;          //紫外线定时时长固定为30分钟
 352          unsigned int jx_timer_start = 0;
 353          unsigned int jx_timer = 30;             //加香定时时长固定为30分钟
 354          #define TEMPER_LIMIT_MAX 50                     //最高可设温度
 355          unsigned char temper_limit = 50;                //默认最高温35度
 356          #define TIMER_LONG_MAX 360                              //最长可设加热时间
 357          unsigned int warm_timer_start = 0;
 358          unsigned int warm_timer = 60;           //默认加热时间,单位为秒
 359          
 360          unsigned int last_key_press_time = 0;
 361          #define NOPRESS_TIMER_MAX 5000          //5秒
 362          
 363          bit power_status = 1;
 364          unsigned int set_temper_limit_delay = 32000;
C51 COMPILER V7.04   TEST                                                                  05/10/2004 15:25:07 PAGE 7   

 365          
 366          void key_scan(void){
 367   1              //按键为高电平触发.
 368   1              if (key_reg){
 369   2                      last_key_press_time = sys_clock;
 370   2              }else{
 371   2                      if(function_select != FUCTION_NORMAL && (unsigned int)(sys_clock - last_key_press_time > NOPRESS_TIMER_M
             -AX)){
 372   3                              key_reg = KEY_FUNC;
 373   3                              function_select = FUCTION_NORMAL - 1;
 374   3                      }
 375   2              }
 376   1      
 377   1              if(key_reg & KEY_SET){
 378   2                      disp_flash = 0;
 379   2                      if(!key_set){//原来未按下才处理,否则不作处理.
 380   3                              if (function_select != FUCTION_NORMAL)
 381   3                                      timer_isr_stop = 1;
 382   3                              if (function_select == FUCTION_TIME_MIN100){
 383   4                                      warm_timer = (warm_timer/1000)*1000 + (warm_timer + 100)%1000;
 384   4                              }else if (function_select == FUCTION_TIME_MIN10){
 385   4                                      warm_timer = (warm_timer/100)*100 + (warm_timer + 10)%100;
 386   4                              }else if (function_select == FUCTION_TIME_MIN){
 387   4                                      warm_timer = (warm_timer/10)*10 + (warm_timer + 1)%10;
 388   4                              }else if (function_select == FUCTION_TEMPER10){
 389   4                                      temper_limit = (temper_limit/100)*100 + (temper_limit + 10)%100;
 390   4                                      if (temper_limit/10 > (TEMPER_LIMIT_MAX + 9)/10)
 391   4                                              temper_limit = 0;
 392   4                              }else if (function_select == FUCTION_TEMPER){
 393   4                                      temper_limit = (temper_limit/10)*10 + (temper_limit + 1)%10;
 394   4                              }
 395   3                              key_set = 1;
 396   3                      }
 397   2              }else
 398   1                      key_set = 0;
 399   1      
 400   1              if(key_reg & KEY_FUNC){
 401   2                      disp_flash = 0;
 402   2                      if(!key_func){//原来未按下,改变设置模式,否则不作处理.
 403   3                              if (function_select == FUCTION_NORMAL){
 404   4                                      function_select = 0;
 405   4                              }else{
 406   4                                      function_select++;
 407   4                                      if (function_select == FUCTION_NORMAL){
 408   5                                              if (timer_isr_stop){
 409   6                                                      timer_isr_stop = 0;
 410   6                                                      time_ms = 0;
 411   6                                              }
 412   5                                              disp_on = 1;
 413   5                                              if (temper_limit > TEMPER_LIMIT_MAX)
 414   5                                                      temper_limit = TEMPER_LIMIT_MAX;
 415   5                                              if (warm_timer > TIMER_LONG_MAX)
 416   5                                                      warm_timer = TIMER_LONG_MAX;
 417   5                                      }
 418   4                              }
 419   3                              key_func = 1;
 420   3                      }
 421   2              }else
 422   1                      key_func = 0;
 423   1      
 424   1              if(key_reg & KEY_WARM_START){
 425   2                      if(!key_warm_start){//原来未按下,改变设置模式,否则不作处理.
C51 COMPILER V7.04   TEST                                                                  05/10/2004 15:25:07 PAGE 8   

 426   3                              warm_start= !warm_start;
 427   3                              if(warm_start)
 428   3                                      warm_timer_start = time_min;
 429   3                              key_warm_start = 1;
 430   3                      }
 431   2              }else
 432   1                      key_warm_start = 0;
 433   1      
 434   1              if(key_reg & KEY_LIGHT_START){
 435   2                      if(!key_light_start){//原来未按下,改变设置模式,否则不作处理.
 436   3                              light_start= !light_start;
 437   3                              if(light_start)
 438   3                                      light_timer_start = time_min;
 439   3                              key_light_start = 1;
 440   3                      }
 441   2              }else
 442   1                      key_light_start = 0;
 443   1      
 444   1              if(key_reg & KEY_JX_START){
 445   2                      if(!key_jx_start){//原来未按下,改变设置模式,否则不作处理.
 446   3                              jx_start= !jx_start;
 447   3                              if(jx_start)
 448   3                                      jx_timer_start = time_min;
 449   3                              key_jx_start = 1;
 450   3                      }
 451   2              }else
 452   1                      key_jx_start = 0;
 453   1      
 454   1      
 455   1              if(key_reg & KEY_ALL_START){
 456   2                      warm_timer_start = time_min;
 457   2                      warm_start = 1;
 458   2                      light_timer_start = time_min;
 459   2                      light_start = 1;
 460   2                      jx_timer_start = time_min;
 461   2                      jx_start = 1;
 462   2              }
 463   1      
 464   1              if(key_reg & KEY_POWER){
 465   2                      if(!key_power){//原来未按下,改变设置模式,否则不作处理.
 466   3                              power_status = !power_status;
 467   3                              temper_limit = temper+20;
 468   3                              key_power = 1;
 469   3                              disp_on = 1;
 470   3                              if (temper_limit > TEMPER_LIMIT_MAX)
 471   3                                      temper_limit = TEMPER_LIMIT_MAX;
 472   3                              set_temper_limit_delay = 32000;
 473   3                      }
 474   2              }else
 475   1                      key_power = 0;
 476   1      
 477   1              if (!power_status){
 478   2                      function_select = FUCTION_NORMAL;
 479   2                      timer_isr_stop = 0;
 480   2                      jx_start = 0;
 481   2                      light_start = 0;

⌨️ 快捷键说明

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