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

📄 mstimer.lst

📁 (原创)高精度计时器电路原理图。采用AT89S52加DP8573
💻 LST
📖 第 1 页 / 共 3 页
字号:
C51 COMPILER V8.05a   MSTIMER                                                              03/18/2007 20:51:48 PAGE 1   


C51 COMPILER V8.05a, COMPILATION OF MODULE MSTIMER
OBJECT MODULE PLACED IN msTimer.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE msTimer.C BROWSE DEBUG OBJECTEXTEND

line level    source

   1          //********************************************************************
   2          // Author        : Bing Wang 
   3          // Date          : Mar. 2007
   4          // File          : msTIMER.c
   5          // Hardware      : 89S51/89S52
   6          //********************************************************************
   7          
   8          #include <AT89X52.h>            // SFR definition file.
   9          #include <stdio.h>
  10          #include <absacc.h>                     //
  11          #include <ctype.h>                      //
  12          #include <stdlib.h>                     //
  13          #include <math.h>
  14          
  15          // Interface address definition
  16          // DP8573AN RTC
  17          xdata char DP8573SEC    _at_ 0x0600;
  18          xdata char DP8573MIN    _at_ 0x0700;
  19          xdata char DP8573HOUR   _at_ 0x0800;
  20          xdata char DP8573WEEK   _at_ 0x0E00;
  21          xdata char DP8573DAY    _at_ 0x0900;
  22          xdata char DP8573MONTH  _at_ 0x0A00;
  23          xdata char DP8573YEAR   _at_ 0x0B00;
  24          
  25          xdata char DP8573SECs   _at_ 0x1900;    // Second Save
  26          xdata char DP8573MINs   _at_ 0x1A00;    // Minute Save
  27          xdata char DP8573HOURs  _at_ 0x1B00;    // Hour Save
  28          xdata char DP8573DAYs   _at_ 0x1C00;    // Day Save
  29          xdata char DP8573MONs   _at_ 0x1D00;    // Month Save
  30          
  31          xdata char DP8573MSR    _at_ 0x0000;    // Main Status Register
  32          xdata char DP8573PFR    _at_ 0x0400;    // Periodic Flag Register
  33          xdata char DP8573TSCR   _at_ 0x0400;    // Time Save Control Register
  34          xdata char DP8573RTMR   _at_ 0x0100;    // Real Time Mode Register
  35          xdata char DP8573OMR    _at_ 0x0200;    // Output Mode Register
  36          xdata char DP8573ICR0   _at_ 0x0300;    // Interrupt Control Register 0
  37          xdata char DP8573ICR1   _at_ 0x0400;    // Interrupt Control Register 1
  38          
  39          unsigned char msCNT, Tsecond;
  40          unsigned char SecRTC, MinRTC, HourRTC, WeekRTC, DayRTC, MonthRTC, YearRTC;
  41          unsigned char CmdOld, KeyCmd;
  42          unsigned char second, secondOld, minute, minuteOld, hour, hourOld;
  43          unsigned char day, dayOld, month, monthOld, year, yearOld, timeH, timeL;
  44          
  45          void UART_Init(void)
  46          {
  47   1              SCON = 0x50;    // Setup serial port ctrl reg
  48   1                                              // Mode 1: 8-bit uart var. baud rate
  49   1                                              // REN: enable receiver
  50   1              PCON &= 0x7F;   // Clear SMOD bit in power ctrl reg
  51   1                                              // This bit doubles the baud rate
  52   1              TMOD &= 0xCF;   // Clear M1 and M0 for timer 1
  53   1              TMOD |= 0x20;   // Set M1 for 8-bit autoreload timer
  54   1                                              // TMOD: Timer 1 Mode 2: 8-bit auto-reload timer
  55   1              TH1 = 213;              // 1200 baud with 20MHz xtal
C51 COMPILER V8.05a   MSTIMER                                                              03/18/2007 20:51:48 PAGE 2   

  56   1              TR1 = 1;                // Start timer 1
  57   1              TI = 1;                 // Set TI to indicate ready to xmit
  58   1      }
  59          
  60          void DP8573A_Init(void)
  61          {
  62   1              DP8573MSR = 0x40;       // RS=1
  63   1              DP8573ICR0 = 0x04;      // Interrupt every 1sec
  64   1              DP8573RTMR = 0x00;      // 24 hour mode + stop timer
  65   1              DP8573MSR = 0x00;       // RS=0
  66   1              DP8573PFR = 0x00;       // Clear INT flags + battery backup
  67   1              DP8573TSCR = 0x80;      // Time save enable
  68   1              DP8573SECs = 0x00;      // Clear saved second
  69   1              DP8573MINs = 0x00;      // Clear saved minute
  70   1              DP8573HOURs = 0x00;     // Clear saved hour
  71   1              DP8573DAYs = 0x00;      // Clear saved day
  72   1              DP8573MONs = 0x00;      // Clear saved month
  73   1              DP8573MSR = 0x44;       // RS=1, clear INT flag
  74   1              DP8573RTMR = 0x08;      // Clock start
  75   1      }
  76          
  77          void delay1s(void)
  78          {
  79   1              unsigned int k;
  80   1              for (k=0;k<40000;k++);
  81   1      }
  82          
  83          void delay100ms(void)
  84          {
  85   1              unsigned int k;
  86   1              for (k=0;k<2000;k++);
  87   1      }
  88          
  89          unsigned char KeyScan(void)
  90          {
  91   1              unsigned char keypad;
  92   1      
  93   1              keypad = P1;
  94   1              keypad &= 0x1D;
  95   1      
  96   1              switch (keypad)
  97   1              {
  98   2                      case 0x1C:
  99   2                              keypad = 1;
 100   2                              break;
 101   2                      case 0x19:
 102   2                              keypad = 2;
 103   2                              break;
 104   2                      case 0x15:
 105   2                              keypad = 3;
 106   2                              break;
 107   2                      case 0x0D:
 108   2                              keypad = 4;
 109   2                              break;
 110   2                      default:
 111   2                              keypad = 0;
 112   2                              break;
 113   2              }
 114   1              return keypad;
 115   1      }
 116          
 117          void AdjustRTC(void)
C51 COMPILER V8.05a   MSTIMER                                                              03/18/2007 20:51:48 PAGE 3   

 118          {
 119   1              unsigned char EndCMD, Para, ParaOld, ParaValue;
 120   1      
 121   1              SecRTC = DP8573SEC;
 122   1              SecRTC = (SecRTC>>4)*10 + (SecRTC%16);
 123   1              MinRTC = DP8573MIN;
 124   1              MinRTC = (MinRTC>>4)*10 + (MinRTC%16);
 125   1              HourRTC = DP8573HOUR;
 126   1              HourRTC = (HourRTC>>4)*10 + (HourRTC%16);
 127   1              DayRTC = DP8573DAY;
 128   1              DayRTC = (DayRTC>>4)*10 + (DayRTC%16);
 129   1              MonthRTC = DP8573MONTH;
 130   1              MonthRTC = (MonthRTC>>4)*10 + (MonthRTC%16);
 131   1              YearRTC = DP8573YEAR;
 132   1              YearRTC = (YearRTC>>4)*10 + (YearRTC%16);
 133   1              EndCMD = 0;
 134   1              Para = ParaOld = 0;
 135   1              CmdOld = 0;
 136   1      
 137   1              while (!EndCMD) {
 138   2                      if (KeyCmd != CmdOld) {
 139   3                              switch (KeyCmd) {
 140   4                                      case 1:                                 // Setting
 141   4                                              Para += 1;
 142   4                                              if (Para >= 7) { Para = 0; EndCMD = 1; }
 143   4                                              break;
 144   4                                      case 2:                                 // +
 145   4                                              switch(Para) {
 146   5                                                      case 1:                 // Year
 147   5                                                              if (YearRTC >= 99) YearRTC = 0;
 148   5                                                              else YearRTC++;
 149   5                                                              putchar(16);    // Set cursor to the last 2 chars
 150   5                                                              putchar(14);
 151   5                                                              putchar((YearRTC/10)+48);
 152   5                                                              putchar((YearRTC%10)+48);
 153   5                                                              break;
 154   5                                                      case 2:                 // Month
 155   5                                                              if (MonthRTC >= 12) MonthRTC = 1;
 156   5                                                              else MonthRTC++;
 157   5                                                              putchar(16);    // Set cursor to the last 2 chars
 158   5                                                              putchar(14);
 159   5                                                              putchar((MonthRTC/10)+48);
 160   5                                                              putchar((MonthRTC%10)+48);
 161   5                                                              break;
 162   5                                                      case 3:                 // Day
 163   5                                                              if (DayRTC >= 31) DayRTC = 1;
 164   5                                                              else DayRTC++;
 165   5                                                              putchar(16);    // Set cursor to the last 2 chars
 166   5                                                              putchar(14);
 167   5                                                              putchar((DayRTC/10)+48);
 168   5                                                              putchar((DayRTC%10)+48);
 169   5                                                              break;
 170   5                                                      case 4:                 // Hour
 171   5                                                              if (HourRTC >= 24) HourRTC = 0;
 172   5                                                              else HourRTC++;
 173   5                                                              putchar(16);    // Set cursor to the last 2 chars
 174   5                                                              putchar(14);
 175   5                                                              putchar((HourRTC/10)+48);
 176   5                                                              putchar((HourRTC%10)+48);
 177   5                                                              break;
 178   5                                                      case 5:                 // Minute
 179   5                                                              if (MinRTC >= 59) MinRTC = 0;
C51 COMPILER V8.05a   MSTIMER                                                              03/18/2007 20:51:48 PAGE 4   

 180   5                                                              else MinRTC++;
 181   5                                                              putchar(16);    // Set cursor to the last 2 chars
 182   5                                                              putchar(14);
 183   5                                                              putchar((MinRTC/10)+48);
 184   5                                                              putchar((MinRTC%10)+48);
 185   5                                                              break;
 186   5                                                      case 6:                 // Second
 187   5                                                              if (SecRTC >= 59) SecRTC = 0;
 188   5                                                              else SecRTC++;
 189   5                                                              putchar(16);    // Set cursor to the last 2 chars
 190   5                                                              putchar(14);

⌨️ 快捷键说明

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