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

📄 time.lst

📁 AT89c52控制数码管带温度显示的万年历
💻 LST
字号:
C51 COMPILER V8.02   TIME                                                                  12/19/2011 20:44:09 PAGE 1   


C51 COMPILER V8.02, COMPILATION OF MODULE TIME
OBJECT MODULE PLACED IN time.OBJ
COMPILER INVOKED BY: D:\单片机软件\Keil3\C51\BIN\C51.EXE time.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          //Title:calendar
   2          //Author:liclny
   3          //Date;10:45 2007-04-02
   4          //QQ:43524751
   5          #include "reg51.h"
   6          #define uchar unsigned char
   7          #define uint     unsigned int
   8          sbit DQ   = P3^7;
   9          sbit sign = P3^3;
  10          sbit set_key = P3^0;
  11          sbit up_key = P3^1;
  12          sbit down_key = P3^2;
  13          
  14          uint sec;
  15          uint min=23;
  16          uint hour=12;
  17          uint day=10;
  18          uint month=10;
  19          uint yearl=7;
  20          uint yearh=20;
  21          uint tcnt;
  22          uint cursor=0;
  23          uchar a=0xff;
  24          uchar code Seg[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
  25          
  26          void delay(uint t)
  27          {
  28   1             uint i;
  29   1             while(t--)
  30   1             {for (i=0;i<125;i++);}
  31   1      }
  32          void Tdelay(unsigned int i)
  33          {
  34   1              while(i--);
  35   1      }
  36          void Kdelay()
  37          {
  38   1             uchar i,j;
  39   1             for(i=100;i>0;i--) 
  40   1             for(j=248;j>0;j--);
  41   1      }
  42          Init_DS18B20(void)
  43          {
  44   1              unsigned char x=0;
  45   1              DQ = 1;    
  46   1              Tdelay(8);  
  47   1              DQ = 0;    
  48   1              Tdelay(80); 
  49   1              DQ = 1;    
  50   1              Tdelay(14);
  51   1              Tdelay(20);
  52   1      }
  53          //读一个字节
  54          ReadOneChar(void)
  55          {
C51 COMPILER V8.02   TIME                                                                  12/19/2011 20:44:09 PAGE 2   

  56   1              unsigned char i=0;
  57   1              unsigned char dat = 0;
  58   1              for (i=8;i>0;i--)
  59   1              {
  60   2                   DQ = 0; 
  61   2                   dat>>=1;
  62   2                   DQ = 1; 
  63   2                   if(DQ)
  64   2                    dat|=0x80;
  65   2                   Tdelay(4);
  66   2              }
  67   1              return(dat);
  68   1      }//写一个字节
  69          WriteOneChar(unsigned char dat)
  70          {
  71   1              unsigned char i=0;
  72   1              for (i=8; i>0; i--)
  73   1              {
  74   2                   DQ = 0;
  75   2                   DQ = dat&0x01;
  76   2                   Tdelay(5);
  77   2                   DQ = 1;
  78   2                   dat>>=1;
  79   2              }
  80   1      }//读取温度
  81          ReadTemperature(void)
  82          {
  83   1              unsigned char a=0;
  84   1              unsigned char b=0;
  85   1              unsigned int t=0;
  86   1              float tt=0;
  87   1              Init_DS18B20();
  88   1              WriteOneChar(0xCC); 
  89   1              WriteOneChar(0x44); 
  90   1              Init_DS18B20();
  91   1              WriteOneChar(0xCC); 
  92   1              WriteOneChar(0xBE);
  93   1              a=ReadOneChar();
  94   1              b=ReadOneChar();
  95   1              t=b;
  96   1              t<<=8;
  97   1              t=t|a;
  98   1              tt=t*0.0625;        
  99   1              t= tt*10+0.5;      
 100   1              return(t);
 101   1      }
 102          void display(uchar L1,uchar L2,uchar L3,uchar L4,uchar L5,uchar L6,uchar L7,uchar L8,uchar L9,uchar L10,uc
             -har L11,uchar L12,uchar L13,uchar L14,uchar L15,uchar L16)
 103          {
 104   1             P2=0x7F;P0=L1;delay(1);     //yearh
 105   1             P2=0xBF;P0=L2;delay(1);     //yearh
 106   1             if(cursor==6){P2=0xDF|a;P0=L3;delay(1);}else{P2=0xDF;P0=L3;delay(1);}      //yearl
 107   1             if(cursor==6){P2=0xEF|a;P0=L4;delay(1);}else{P2=0xEF;P0=L4;delay(1);}      //yearl
 108   1             if(cursor==5){P2=0xF7|a;P0=L5;delay(1);}else{P2=0xF7;P0=L5;delay(1);}      //month
 109   1             if(cursor==5){P2=0xFB|a;P0=L6;delay(1);}else{P2=0xFB;P0=L6;delay(1);}      //month
 110   1             if(cursor==4){P2=0xFD|a;P0=L7;delay(1);}else{P2=0xFD;P0=L7;delay(1);}      //day
 111   1             if(cursor==4){P2=0xFE|a;P0=L8;delay(1);}else{P2=0xFE;P0=L8;delay(1);}      //day
 112   1             P2=0xFF;
 113   1             if(cursor==3){P1=0x7F|a;P0=L9;delay(1);}else{P1=0x7F;P0=L9;delay(1);}      //hour
 114   1             if(cursor==3){P1=0xBF|a;P0=L10;delay(1);}else{P1=0xBF;P0=L10;delay(1);}     //hour
 115   1             if(cursor==2){P1=0xDF|a;P0=L11;delay(1);}else{P1=0xDF;P0=L11;delay(1);} //min
 116   1             if(cursor==2){P1=0xEF|a;P0=L12;delay(1);}else{P1=0xEF;P0=L12;delay(1);} //min
C51 COMPILER V8.02   TIME                                                                  12/19/2011 20:44:09 PAGE 3   

 117   1             if(cursor==1){P1=0xF7|a;P0=L13;delay(1);}else{P1=0xF7;P0=L13;delay(1);} //sec
 118   1             if(cursor==1){P1=0xFB|a;P0=L14;delay(1);}else{P1=0xFB;P0=L14;delay(1);} //sec
 119   1             P1=0xFD;P0=L15;delay(1); //temp
 120   1             P1=0xFE;P0=L16;delay(1); //temp
 121   1             P1=0xFF;
 122   1      }
 123          main()
 124          {   
 125   1             uint i;    
 126   1             TMOD=0x02;               //设置模式为定时器T0的模式2 (8位自动重装计数初值的计数值)        
 127   1             TH0=0x06;                //设置计数器初值,靠TH0存储重装的计数值X0=256-250=6
 128   1             TL0=0x06;
 129   1             TR0=1;                   //启动T0
 130   1             ET0=1;                   //开启定时器T0中断允许
 131   1             EA=1;                    //开启中断总控制
 132   1             while(1)
 133   1             {
 134   2                 if(set_key==0)
 135   2                 {
 136   3                     Kdelay();
 137   3                     if(set_key==0)
 138   3                     {
 139   4                         cursor++;
 140   4                         if(cursor>=7){cursor=0;}
 141   4                     }
 142   3                 }
 143   2                 if(up_key==0)
 144   2                 {
 145   3                     Kdelay();
 146   3                     if(up_key==0)
 147   3                     {
 148   4                         if(cursor==1){sec++;if(sec==60)sec=0;}
 149   4                         if(cursor==2){min++;if(min==60)min=0;}
 150   4                         if(cursor==3){hour++;if(hour==24)hour=0;}
 151   4                         if(cursor==4){day++;if(day==31)day=1;}
 152   4                         if(cursor==5){month++;if(month==13)month=1;}
 153   4                         if(cursor==6){yearl++;if(yearl==100)yearl=0;}
 154   4                         if(cursor==7){yearh++;if(yearh==30)yearh=20;}
 155   4                     }
 156   3                 }
 157   2                 if(down_key==0)
 158   2                 {
 159   3                     Kdelay();
 160   3                     if(down_key==0)
 161   3                     {
 162   4                         if(cursor==1){sec--;if(sec==00)sec=59;}
 163   4                         if(cursor==2){min--;if(min==0)min=59;}
 164   4                         if(cursor==3){hour--;if(hour==0)hour=23;}
 165   4                         if(cursor==4){day--;if(day==0)day=31;}
 166   4                         if(cursor==5){month--;if(month==0)month=12;}
 167   4                         if(cursor==6){yearl--;if(yearl==0)yearl=99;}
 168   4                         if(cursor==7){yearh--;if(yearh==20)yearh=30;}
 169   4                     }
 170   3                 }
 171   2                 i=ReadTemperature();
 172   2                 display(Seg[yearh/10],Seg[yearh%10],Seg[yearl/10],Seg[yearl%10],Seg[month/10],Seg[month%10],Seg
             -[day/10],Seg[day%10],Seg[hour/10],Seg[hour%10],Seg[min/10],Seg[min%10],Seg[sec/10],Seg[sec%10],Seg[i/100],Seg[i/10%10]);
             -     
 173   2             }
 174   1      }
 175          void t0(void)interrupt 1 using 0      //t0的中断程序
 176          {
C51 COMPILER V8.02   TIME                                                                  12/19/2011 20:44:09 PAGE 4   

 177   1             tcnt++;
 178   1             if(tcnt==4000)//定时器的定时计数,4000次250us为1秒
 179   1             {
 180   2                 tcnt=0;
 181   2                 sign=~sign;
 182   2                 a=~a;
 183   2                 sec++;
 184   2                 if(sec==60)
 185   2                 {     
 186   3                     sec=0;
 187   3                     min++;
 188   3                     if(min==60)
 189   3                     {
 190   4                         min=0;
 191   4                         hour++;
 192   4                         if(hour==24)
 193   4                         {
 194   5                             hour=0;
 195   5                             day++;
 196   5                             if(month==2&&((yearl==0&&yearh%4==0)||(yearl!=0&&yearl%4==0))&&day==30)day=1;  
 197   5                             else if(month==2&&day==29)day=1;
 198   5                             else if((month==4||month==6||month==9||month==11)&&day==31)day=1;
 199   5                             else if(day==32)day=1;
 200   5                             if(day==1)
 201   5                             {
 202   6                             month++;
 203   6                             if(month==13)
 204   6                             {
 205   7                                 month=1;
 206   7                                 yearl++;
 207   7                                 if(yearl==100)
 208   7                                 {
 209   8                                     yearl=0;
 210   8                                     yearh++;
 211   8                                     if(yearh==100)
 212   8                                     {
 213   9                                         yearh=20;
 214   9                                     }
 215   8                                 }
 216   7                             }
 217   6                         }
 218   5                         }
 219   4                     }
 220   3                 }
 221   2             }
 222   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1776    ----
   CONSTANT SIZE    =     10    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     19      23
   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 + -