disp.lst

来自「单片及c语言轻松入门的随书光盘」· LST 代码 · 共 154 行

LST
154
字号
C51 COMPILER V7.06   DISP                                                                  02/28/2006 10:27:32 PAGE 1   


C51 COMPILER V7.06, COMPILATION OF MODULE DISP
OBJECT MODULE PLACED IN disp.OBJ
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE disp.c BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          /*用rtos编写LED数码管显示程序,其中有用于计算的程序*/
   2          /*另加LED流水灯*/
   3          //须加入conf_tny.a51将周期数改为1000(原为10000),即将报时周期改为1ms,将TimeSharing由5改为1,即将时间片改
             -为1ms
   4          /*测试结果:1)可很稳定地显示,LED的闪烁也正常
   5          2)如果将Timer1的定时中断改为1000即1ms发送一次,可以看到LED流水灯速度时显示加快,但同时数码管出现闪烁,系统
             -超载
   6          */
   7          #include "reg51.h"
   8          #include "intrins.h"
   9          #include <rtx51tny.h> /* RTX51 tiny functions & defines */
  10          #define uchar unsigned char
  11          #define uint  unsigned int
  12          #define ulong unsigned long
  13          #define Init 0          //初始化
  14          #define Disp 1          //显示程序定为任务1
  15          #define Led  2          //LED闪烁定为任务2
  16          #define Data 3          //数值处理
  17          #define Key  4      //键盘操作定义为任务3
  18          
  19          bit     StartLedFlash;  //开始/停止LED流动
  20          bit     LeftRight;              //控制流动向左或向右
  21          
  22          uchar code BitTab[]={0x7F,0xBF,0xDF,0xEF,0xF7,0xFB};
  23          uchar code DispTab[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E,0xFF
             -};
  24          uchar DispBuf[6];
  25          ulong  Count=0; //计数值
  26          void job0 (void ) _task_ Init {
  27   1              TH1=-(10000/256);
  28   1              TL1=-(10000%256);       //12M晶振定时10毫秒
  29   1          TMOD|=0x10;         //T/C1工作于定时器方式1
  30   1              ET1=1;                          //定时器T1允许中断
  31   1              TR1=1;                          //定时器T1开始运行
  32   1          PT1=1;                              //高优先级中断
  33   1      
  34   1              os_create_task (Disp); /* start task Disp */
  35   1              os_create_task (Led); /* start task Led flash */
  36   1              os_create_task (Data);
  37   1              os_create_task (Key);
  38   1              os_delete_task (0);
  39   1      }
  40          
  41          void Display(void) _task_ Disp{
  42   1          static uchar DispCount;
  43   1              while(1){
  44   2                      P2=0xff;                //全灭
  45   2                      P0=DispTab[DispBuf[DispCount]];
  46   2                      P2=BitTab[DispCount];
  47   2                      DispCount++;
  48   2                      if(DispCount==6)
  49   2                              DispCount=0;
  50   2                      os_wait2(K_IVL,4);      
  51   2              }
  52   1      }
C51 COMPILER V7.06   DISP                                                                  02/28/2006 10:27:32 PAGE 2   

  53          void Timer1() interrupt 3
  54          {       TH1=-(10000/256);
  55   1              TL1=-(10000%256);       //12M晶振定时10毫秒
  56   1              isr_send_signal(Led);
  57   1      }
  58          void LedFlash(void) _task_ Led{
  59   1              static uchar FlashLed=0xfe;
  60   1              static uchar LedCount;
  61   1              while(1)
  62   1              {       LedCount++;
  63   2                      Count++;                //计数值不断加1
  64   2                      if(LedCount>=100)       //如果计数次数等于或超过100,由于定时器每10ms送一次信号,故意味着1s为一个周期
  65   2                      {
  66   3                              if(StartLedFlash)  //如果开始运行
  67   3                              {
  68   4                                      P1=FlashLed;
  69   4                                      if(LeftRight)   
  70   4                                              FlashLed=_crol_(FlashLed,1);
  71   4                                      else
  72   4                                              FlashLed=_cror_(FlashLed,1);
  73   4                              }               
  74   3                              LedCount=0;
  75   3                      }
  76   2                      os_wait(K_SIG,1,0);             //等待信号送到
  77   2              }
  78   1      }
  79          
  80          void DataProcess(void) _task_ Data{
  81   1              ulong tmp;
  82   1              while(1){
  83   2                      tmp=Count;
  84   2                      DispBuf[5]=tmp%10;
  85   2                      tmp/=10;
  86   2                      DispBuf[4]=tmp%10;
  87   2                      tmp/=10;
  88   2                      DispBuf[3]=tmp%10;
  89   2                      tmp/=10;
  90   2                      DispBuf[2]=tmp%10;
  91   2                      tmp/=10;
  92   2                      DispBuf[1]=tmp%10;
  93   2                      DispBuf[0]=tmp/10;
  94   2              }
  95   1      }
  96          
  97          void KeyValue(uchar KeyV)
  98          {       if((KeyV|0xfb)!=0xff)   //11011111 P3.2位被按下
  99   1              {       StartLedFlash=1;
 100   2              }
 101   1              else if((KeyV|0xf7)!=0xff)
 102   1              {       StartLedFlash=0;
 103   2              }
 104   1              else if((KeyV|0xef)!=0xff)
 105   1              {       LeftRight=1;
 106   2              }
 107   1              else if((KeyV|0xdf)!=0xff)
 108   1              {       LeftRight=0;
 109   2              }
 110   1      }
 111          
 112          void KeyProcess(void) _task_ Key{
 113   1              uchar tmp;
 114   1              while(1)
C51 COMPILER V7.06   DISP                                                                  02/28/2006 10:27:32 PAGE 3   

 115   1              {       P3|=0x3c;       //中间4位置高电平
 116   2                      tmp=P3;
 117   2                      tmp|=0xc3;      //两边4位置高电平
 118   2                      if(tmp!=0xff)
 119   2                              KeyValue(tmp);
 120   2                      os_wait(K_IVL,2,0);
 121   2              }
 122   1      }
 123          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    501    ----
   CONSTANT SIZE    =     23    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     13       4
   IDATA SIZE       =   ----    ----
   BIT SIZE         =      2    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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