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

📄 lcd_clock.lst

📁 用Led显示时间,年月日和时分秒。 动态显示的数码管。用定时器控制
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.20   LCD_CLOCK                                                             02/27/2008 10:00:01 PAGE 1   


C51 COMPILER V7.20, COMPILATION OF MODULE LCD_CLOCK
OBJECT MODULE PLACED IN lcd_clock.OBJ
COMPILER INVOKED BY: E:\Keil C\C51\BIN\C51.EXE lcd_clock.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          #include<reg51.h>
   2          #include<intrins.h>
   3          #define u8 unsigned char
   4          #define u16 unsigned int
   5          typedef struct  {
   6                                                  char hour;
   7                                                  char minute;
   8                                                  char second;
   9                                          }time;
  10          typedef struct {
  11                                                  int year;
  12                                                  char month;
  13                                                  char day;
  14                                          }date;
  15          date today={2008,02,25};
  16          time now={23,59,00};
  17          u8 code dayofmonth[]={31,28,31,30,31,30,31,31,30,31,30,31};
  18          
  19          
  20          
  21          u8 flag;
  22          char secondlow,secondhigh,minutelow,minutehigh,hourlow,hourhigh,daylow,dayhigh,monthlow,monthhigh,
  23                   yearlow,yearsecondlow,yearthirdlow,yearhigh;
  24          u16 tick;
  25          sbit rs=P3^5;
  26          sbit rw=P3^6;
  27          sbit en=P3^7;
  28          sbit mode=P3^0;
  29          sbit up=P3^1;
  30          sbit down=P3^2;
  31          #define lcdcommand 0
  32          #define lcddate 1
  33          
  34          char monthofday(char month,int year)//返回月的天数
  35          {
  36   1              if(month==2&&year%4==0)
  37   1              {
  38   2                      return(29);     
  39   2              }
  40   1              else
  41   1              {
  42   2                      return(dayofmonth[month]);
  43   2              }
  44   1      }
  45          void delay(u8 z)
  46          {
  47   1              u8 x,y;
  48   1              for(x=z;x>0;x--)
  49   1                      for(y=110;y>0;y--);
  50   1      }
  51          
  52          void timer0()interrupt 1
  53          {
  54   1              TMOD=0x01;
  55   1              TH0=(65536-5000)/256;
C51 COMPILER V7.20   LCD_CLOCK                                                             02/27/2008 10:00:01 PAGE 2   

  56   1              TL0=(65536-5000)%256;
  57   1              TR0=1;
  58   1              EA=1;
  59   1              tick++;
  60   1              if(tick==200)
  61   1              {
  62   2                      tick=0;
  63   2                      now.second++;
  64   2                      if(now.second==60)
  65   2                      {
  66   3                              now.second=0;
  67   3                              now.minute++;
  68   3                              if(now.minute==60)
  69   3                              {
  70   4                                      now.minute=0;
  71   4                                      now.hour++;
  72   4                                      if(now.hour==24)
  73   4                                      {
  74   5                                              now.hour=0;
  75   5                                              today.day++;
  76   5                                              if(today.day==monthofday(today.month,today.year))
  77   5                                              {
  78   6                                                      today.day=1;
  79   6                                                      today.month++;
  80   6                                                      if(today.month==13)
  81   6                                                      {
  82   7                                                              today.month=1;
  83   7                                                          today.year++;
  84   7                                                              if(today.year==9999)
  85   7                                                              {
  86   8                                                                      today.year=1900;
  87   8                                                              }
  88   7                                                      }       
  89   6                                              }
  90   5                                      }
  91   4                              }
  92   3                      }
  93   2              }
  94   1      }
  95          
  96          void write_lcd(bit writestyle,u8 input)
  97          {
  98   1              rw=0;
  99   1              rs=writestyle;
 100   1              _nop_();
 101   1              P1=input;
 102   1              en=1;
 103   1              delay(5);//这一句延时要足够长才行。
 104   1              en=0;   
 105   1              
 106   1      }
 107          
 108          /*void write_sfr(char second,char minute,char hour,char day,char month,int year)
 109          {
 110          
 111          }*/
 112          void initialize()
 113          {
 114   1              write_lcd(lcdcommand,0x38);
 115   1              write_lcd(lcdcommand,0x0c);
 116   1              write_lcd(lcdcommand,0x06);
 117   1              write_lcd(lcdcommand,0x01);
C51 COMPILER V7.20   LCD_CLOCK                                                             02/27/2008 10:00:01 PAGE 3   

 118   1              write_lcd(lcdcommand,0x80);
 119   1      }
 120          
 121          void timer0_initialize()
 122          {
 123   1              EA=0;
 124   1              TMOD=0x01;
 125   1              TH0=(65536-5000)/256;
 126   1              TL0=(65536-5000)%256;
 127   1              ET0=1;
 128   1              TR0=1;
 129   1              tick=0;
 130   1              EA=1;
 131   1              
 132   1      }
 133          void write_second_nocursor()
 134          {
 135   1              write_lcd(lcdcommand,0x80+0x40+11);
 136   1              write_lcd(lcddate,secondhigh+0x30);
 137   1              write_lcd(lcddate,secondlow+0x30);
 138   1      }
 139          void write_second()
 140          {
 141   1              write_lcd(lcdcommand,0x80+0x40+11);
 142   1              write_lcd(lcddate,secondhigh+0x30);
 143   1              write_lcd(lcdcommand,0x06);
 144   1              write_lcd(lcdcommand,0x0e);
 145   1              write_lcd(lcdcommand,0x0c);
 146   1              write_lcd(lcddate,secondlow+0x30);
 147   1      }
 148          void write_minute()
 149          {
 150   1              write_lcd(lcdcommand,0x38);
 151   1              write_lcd(lcdcommand,0x80+0x40+8);
 152   1              write_lcd(lcddate,minutehigh+0x30);
 153   1              write_lcd(lcdcommand,0x06);
 154   1              write_lcd(lcdcommand,0x0e);
 155   1              write_lcd(lcdcommand,0x0c);
 156   1              write_lcd(lcddate,minutelow+0x30);
 157   1              write_lcd(lcddate,0x30+10);//加上冒号
 158   1      }
 159          void write_hour()
 160          {
 161   1              write_lcd(lcdcommand,0x80+0x40+5);
 162   1              write_lcd(lcddate,hourhigh+0x30);
 163   1              write_lcd(lcdcommand,0x06);
 164   1              write_lcd(lcdcommand,0x0e);
 165   1              write_lcd(lcdcommand,0x0c);
 166   1              write_lcd(lcddate,hourlow+0x30);
 167   1              write_lcd(lcddate,0x30+10);//加上冒号
 168   1      }
 169          void write_day()
 170          {
 171   1              write_lcd(lcdcommand,0x80+12);
 172   1              write_lcd(lcddate,dayhigh+0x30);
 173   1              write_lcd(lcdcommand,0x06);
 174   1              write_lcd(lcdcommand,0x0e);
 175   1              write_lcd(lcdcommand,0x0c);
 176   1              write_lcd(lcddate,daylow+0x30);
 177   1      }
 178          void write_month()
 179          {
C51 COMPILER V7.20   LCD_CLOCK                                                             02/27/2008 10:00:01 PAGE 4   

 180   1              write_lcd(lcdcommand,0x80+9);
 181   1              write_lcd(lcddate,monthhigh+0x30);
 182   1              write_lcd(lcdcommand,0x06);
 183   1              write_lcd(lcdcommand,0x0e);
 184   1              write_lcd(lcdcommand,0x0c);
 185   1              write_lcd(lcddate,monthlow+0x30);
 186   1      }
 187          void write_year()
 188          {
 189   1              write_lcd(lcdcommand,0x80+4);
 190   1              write_lcd(lcddate,yearhigh+0x30);
 191   1              write_lcd(lcddate,yearthirdlow+0x30);
 192   1              write_lcd(lcddate,yearsecondlow+0x30);
 193   1              write_lcd(lcdcommand,0x06);
 194   1              write_lcd(lcdcommand,0x0e);
 195   1              write_lcd(lcdcommand,0x0c);//这三句用来在最末位显示光标
 196   1              write_lcd(lcddate,yearlow+0x30);
 197   1      }
 198          void keyscan()
 199          {
 200   1              if(mode==0)
 201   1              {
 202   2                      delay(20);
 203   2                      if(mode==0)
 204   2                      {
 205   3                              flag++;
 206   3                              if(flag==7)
 207   3                              {
 208   4                                      flag=0;
 209   4                              }
 210   3                      }
 211   2                      while(!mode);
 212   2              }
 213   1              if(flag==6)
 214   1              {
 215   2                      TR0=0;
 216   2                      write_lcd(lcdcommand,0x0c);
 217   2                      if(up==0)
 218   2                      {
 219   3                              delay(20);
 220   3                              if(up==0)
 221   3                              {
 222   4                                      now.second++;
 223   4                                      if(now.second==60)
 224   4                                      {
 225   5                                              now.second=0;
 226   5                                      }
 227   4                              }
 228   3                              while(!up);
 229   3                      }       
 230   2                      if(down==0)
 231   2                      {
 232   3                              delay(20);
 233   3                              if(down==0)
 234   3                              {
 235   4                                      now.second--;
 236   4                                      if(now.second==-1)
 237   4                                      {
 238   5                                              now.second=59;
 239   5                                      }

⌨️ 快捷键说明

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