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

📄 ceshi.lst

📁 单片机8位数码管换屏交替显示
💻 LST
字号:
C51 COMPILER V7.50   CESHI                                                                 01/31/2007 08:54:53 PAGE 1   


C51 COMPILER V7.50, COMPILATION OF MODULE CESHI
OBJECT MODULE PLACED IN ceshi.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE ceshi.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          #include <at892051.h>
   2          #include <math.h>
   3          #include <stdio.h>
   4          
   5          #define TIMER0_ENABLE TL0=TH0; TR0=1; //TR0 = 1,启动T
   6          #define TIMER0_DISABLE TR0=0;
   7          
   8          sbit RESET = P1^7;
   9          sbit SCK = P1^6;
  10          sbit RCK = P1^5;
  11          sbit SER = P1^4;
  12          sbit DB = P1^2;
  13          sbit ZB = P1^3;
  14          
  15          unsigned char code dispcode[]={0xc0,0xf9,0xa4,0xb0,0x99,          //0,1,2,3,4
  16                                         0x92,0x82,0xf8,0x80,0x90,                  //5,6,7,8,9
  17                                         0x88,0x83,0xc6,0xa1,0x86,                  //a,b,c,d,e
  18                                                                     0xff};                                                     //f-灭 
  19          /*
  20          unsigned char code dispcode[]={0x40,0x79,0x24,0x30,0x19,          //0,1,2,3,4
  21                                         0x12,0x02,0x78,0x00,0x10,                  //5,6,7,8,9
  22                                         0x08,0x03,0x46,0x21,0x06,                  //a,b,c,d,e
  23                                                                     0x7f,0x00};                                            //f,灭
  24          */
  25                                                                                                  
  26          unsigned char bdata SF;
  27          sbit S7 =  SF^7;
  28          sbit S6 =  SF^6;
  29          sbit S5 =  SF^5;
  30          sbit S4 =  SF^4;
  31          sbit S3 =  SF^3;
  32          sbit S2 =  SF^2;
  33          sbit S1 =  SF^1;
  34          sbit S0 =  SF^0;
  35          
  36          unsigned char getch;
  37          unsigned long DBData;                     //大包数据
  38          unsigned long ZBData;                                     //中包数据
  39          unsigned long FactData;
  40          unsigned long mul = 10000;
  41          unsigned char data PartData[5];
  42          void PSendChar(unsigned char getch);
  43          void DisPlay(unsigned long FactData);
  44          void delay_5ms(unsigned int t);
  45          
  46          void main ( )
  47          {
  48   1        
  49   1      
  50   1        EA = 0;
  51   1        TMOD=0x22;             //定时器0为工作模式2(8位自动重装),0为模式2(8位自动重装) 
  52   1        PCON=0x00;
  53   1        TH0=(256-96);         //9600bps 就是 1000000/9600=104.167微秒 执行的时间是104.167*11.0592/12= 96 
  54   1        TL0=TH0;
  55   1        ET0=1;                //定时器/记数器T0的溢出中断允许位,ET,允 许中断
C51 COMPILER V7.50   CESHI                                                                 01/31/2007 08:54:53 PAGE 2   

  56   1        EA=1;
  57   1        DB = 0;
  58   1        ZB = 0;
  59   1        RCK = 0;
  60   1        SCK = 0;
  61   1        while (1)
  62   1         {
  63   2                RESET = 0;                                 //复位,清屏
  64   2            RESET = 1;
  65   2            DB = 1;                                                                    //置大包标志
  66   2            DisPlay(0x3ABC);
  67   2                delay_5ms(15000);                                                      //延时1.25ms
  68   2                DB = 0;
  69   2                RESET = 0;                                 //复位,清屏
  70   2            RESET = 1;                                                                 
  71   2                SCK = 0;
  72   2                ZB = 1;                                                                        //置中包标志
  73   2                DisPlay(0x1f78);
  74   2                delay_5ms(15000);                                                      //延时1.25ms
  75   2                ZB = 0;
  76   2              }
  77   1      }
  78          //***********************************************************************************//
  79          //                                5位串行移位数码显示程序                                                        //
  80          //                                                                         (74LS595)                                                                    //
  81          //***********************************************************************************//
  82          void DisPlay(unsigned long FactData)
  83          {
  84   1         unsigned char i;
  85   1         unsigned char j;
  86   1         unsigned long mul = 10000;
  87   1      
  88   1         for (j = 0;j < 5;j++)                                                 //十六进制转换为十进制
  89   1          {
  90   2                PartData[4-j] = FactData/mul;
  91   2                FactData = FactData%mul       ;
  92   2                mul = mul / 10;
  93   2          }
  94   1            if (PartData[4] == 0 )                                    //高位灭0处理
  95   1                 {
  96   2                   PartData[4] = 0x0f;
  97   2                       if (PartData[3] == 0 ) 
  98   2                         {
  99   3                           PartData[3] = 0x0f;
 100   3                         }
 101   2                 }                                                                                            
 102   1         RCK = 0;
 103   1         for(i = 0; i<= 4; i++)                                        //赋显示值
 104   1          {
 105   2            getch = dispcode[PartData[i]];
 106   2                if (i == 2)                                        //小数点第3位固定显示
 107   2                 {
 108   3                   getch = getch & 0x7f;
 109   3                 } 
 110   2                PSendChar(getch);        
 111   2          }
 112   1         RCK = 1;
 113   1         for (j = 0;j < 5;j++)                                         //清显示缓冲区
 114   1           {
 115   2                 PartData[j] = 0x00;
 116   2               }
 117   1      }
C51 COMPILER V7.50   CESHI                                                                 01/31/2007 08:54:53 PAGE 3   

 118          
 119          /*
 120          void IntTimer0() interrupt 1    //定时器计数器0的中断    
 121          {
 122              SCK = 0;
 123          }
 124          
 125          
 126          
 127          void PSendChar(unsigned char getch)
 128          {
 129              SF = getch;
 130              TIMER0_ENABLE;   //记数器0启动
 131              SER = S7;        //先送出低位
 132                  SCK =1;
 133             while(SCK) ;
 134              SER = S6; 
 135                  SCK = 1;
 136             while(SCK) ;
 137              SER = S5; 
 138                  SCK = 1;
 139             while(SCK);
 140              SER = S4;
 141                  SCK = 1;
 142             while(SCK);
 143              SER = S3;
 144                  SCK = 1;
 145             while(SCK);                           
 146              SER = S2;
 147                  SCK = 1;
 148             while(SCK);
 149              SER = S1;
 150                  SCK = 1;
 151             while(SCK);
 152              SER = S0; 
 153                  SCK = 1;
 154             while(SCK);
 155              TIMER0_DISABLE; //停止timer
 156          }
 157          */
 158          
 159          void PSendChar(unsigned char getch)                      //移位输出数据
 160          {
 161   1          unsigned char m;
 162   1              SF = getch;
 163   1          for (m=0;m<8;m++) 
 164   1              {
 165   2            if (S7 == 1) 
 166   2                SER =1; 
 167   2                else SER=0;                                                 //移位时钟
 168   2            SCK = 0;
 169   2            SF <<= 1;
 170   2            SCK = 1;
 171   2              }
 172   1          return;
 173   1      }
 174          
 175          //************************************************************************//
 176          //                              延时50ms程序                //
 177          //************************************************************************// 
 178          void delay_5ms(unsigned int t)
 179          {
C51 COMPILER V7.50   CESHI                                                                 01/31/2007 08:54:53 PAGE 4   

 180   1        unsigned char j;  
 181   1        for(;t>0;t--)   
 182   1        for(j=19000;j>0;j--) ;
 183   1        return;
 184   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    321    ----
   CONSTANT SIZE    =     16    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     23      10
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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