|
|
|
|
C51 COMPILER V9.56.0.0 DS1302 04/28/2022 23:43:37 PAGE 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
C51 COMPILER V9.56.0.0, COMPILATION OF MODULE DS1302
|
|
|
|
|
OBJECT MODULE PLACED IN ds1302.OBJ
|
|
|
|
|
COMPILER INVOKED BY: D:\Keil_v5\C51\BIN\C51.EXE ds1302.c OPTIMIZE(8,SPEED) BROWSE DEBUG OBJECTEXTEND TABS(2)
|
|
|
|
|
|
|
|
|
|
line level source
|
|
|
|
|
|
|
|
|
|
1 #include"ds1302.h"
|
|
|
|
|
2
|
|
|
|
|
3 //---DS1302д<EFBFBD><EFBFBD><EFBFBD>Ͷ<EFBFBD>ȡʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>---//
|
|
|
|
|
4 //---<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD>дλ;-------//
|
|
|
|
|
5 uchar code READ_RTC_ADDR[7] = {0x81, 0x83, 0x85, 0x87, 0x89, 0x8b, 0x8d};
|
|
|
|
|
6 uchar code WRITE_RTC_ADDR[7] = {0x80, 0x82, 0x84, 0x86, 0x88, 0x8a, 0x8c};
|
|
|
|
|
7
|
|
|
|
|
8 //---DS1302ʱ<EFBFBD>ӳ<EFBFBD>ʼ<EFBFBD><EFBFBD>2013<EFBFBD><EFBFBD>1<EFBFBD><EFBFBD>1<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڶ<EFBFBD>12<EFBFBD><EFBFBD>00<EFBFBD><EFBFBD>00<EFBFBD>롣---//
|
|
|
|
|
9 //---<EFBFBD>洢˳<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD>洢<EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>BCD<EFBFBD><EFBFBD>---//
|
|
|
|
|
10
|
|
|
|
|
11 uchar TIME[7] = {0X00, 0X01, 0x23, 0x28, 0x04, 0x04, 0x22};
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
|
|
14 void Ds1302Write(uchar addr, uchar dat)
|
|
|
|
|
15 {
|
|
|
|
|
16 1 uchar n;
|
|
|
|
|
17 1 RST = 0;
|
|
|
|
|
18 1 _nop_();
|
|
|
|
|
19 1
|
|
|
|
|
20 1 SCLK = 0;//<EFBFBD>Ƚ<EFBFBD>SCLK<EFBFBD>õ͵<EFBFBD>ƽ<EFBFBD><EFBFBD>
|
|
|
|
|
21 1 _nop_();
|
|
|
|
|
22 1 RST = 1; //Ȼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>RST(CE)<EFBFBD>øߵ<EFBFBD>ƽ<EFBFBD><EFBFBD>
|
|
|
|
|
23 1 _nop_();
|
|
|
|
|
24 1
|
|
|
|
|
25 1 for (n=0; n<8; n++)//<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD>Ͱ<EFBFBD>λ<EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
26 1 {
|
|
|
|
|
27 2 DSIO = addr & 0x01;//<EFBFBD><EFBFBD><EFBFBD>ݴӵ<EFBFBD>λ<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
28 2 addr >>= 1;
|
|
|
|
|
29 2 SCLK = 1;//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>DS1302<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
30 2 _nop_();
|
|
|
|
|
31 2 SCLK = 0;
|
|
|
|
|
32 2 _nop_();
|
|
|
|
|
33 2 }
|
|
|
|
|
34 1 for (n=0; n<8; n++)//д<EFBFBD><EFBFBD>8λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
35 1 {
|
|
|
|
|
36 2 DSIO = dat & 0x01;
|
|
|
|
|
37 2 dat >>= 1;
|
|
|
|
|
38 2 SCLK = 1;//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>DS1302<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
39 2 _nop_();
|
|
|
|
|
40 2 SCLK = 0;
|
|
|
|
|
41 2 _nop_();
|
|
|
|
|
42 2 }
|
|
|
|
|
43 1
|
|
|
|
|
44 1 RST = 0;//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
45 1 _nop_();
|
|
|
|
|
46 1 }
|
|
|
|
|
47
|
|
|
|
|
48 uchar Ds1302Read(uchar addr)
|
|
|
|
|
49 {
|
|
|
|
|
50 1 uchar n,dat,dat1;
|
|
|
|
|
51 1 RST = 0;
|
|
|
|
|
52 1 _nop_();
|
|
|
|
|
53 1
|
|
|
|
|
54 1 SCLK = 0;//<EFBFBD>Ƚ<EFBFBD>SCLK<EFBFBD>õ͵<EFBFBD>ƽ<EFBFBD><EFBFBD>
|
|
|
|
|
55 1 _nop_();
|
|
|
|
|
C51 COMPILER V9.56.0.0 DS1302 04/28/2022 23:43:37 PAGE 2
|
|
|
|
|
|
|
|
|
|
56 1 RST = 1;//Ȼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>RST(CE)<EFBFBD>øߵ<EFBFBD>ƽ<EFBFBD><EFBFBD>
|
|
|
|
|
57 1 _nop_();
|
|
|
|
|
58 1
|
|
|
|
|
59 1 for(n=0; n<8; n++)//<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD>Ͱ<EFBFBD>λ<EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
60 1 {
|
|
|
|
|
61 2 DSIO = addr & 0x01;//<EFBFBD><EFBFBD><EFBFBD>ݴӵ<EFBFBD>λ<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
62 2 addr >>= 1;
|
|
|
|
|
63 2 SCLK = 1;//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>DS1302<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
64 2 _nop_();
|
|
|
|
|
65 2 SCLK = 0;//DS1302<EFBFBD>½<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
66 2 _nop_();
|
|
|
|
|
67 2 }
|
|
|
|
|
68 1 _nop_();
|
|
|
|
|
69 1 for(n=0; n<8; n++)//<EFBFBD><EFBFBD>ȡ8λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
70 1 {
|
|
|
|
|
71 2 dat1 = DSIO;//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
72 2 dat = (dat>>1) | (dat1<<7);
|
|
|
|
|
73 2 SCLK = 1;
|
|
|
|
|
74 2 _nop_();
|
|
|
|
|
75 2 SCLK = 0;//DS1302<EFBFBD>½<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
76 2 _nop_();
|
|
|
|
|
77 2 }
|
|
|
|
|
78 1
|
|
|
|
|
79 1 RST = 0;
|
|
|
|
|
80 1 _nop_(); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ΪDS1302<EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD>ȶ<EFBFBD>ʱ<EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ġ<EFBFBD>
|
|
|
|
|
81 1 SCLK = 1;
|
|
|
|
|
82 1 _nop_();
|
|
|
|
|
83 1 DSIO = 0;
|
|
|
|
|
84 1 _nop_();
|
|
|
|
|
85 1 DSIO = 1;
|
|
|
|
|
86 1 _nop_();
|
|
|
|
|
87 1 return dat;
|
|
|
|
|
88 1 }
|
|
|
|
|
89
|
|
|
|
|
90 void Ds1302Init()
|
|
|
|
|
91 {
|
|
|
|
|
92 1 uchar n;
|
|
|
|
|
93 1 Ds1302Write(0x8E,0X00); //<EFBFBD><EFBFBD>ֹд<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǹر<EFBFBD>д<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
94 1 for (n=0; n<7; n++)//д<EFBFBD><EFBFBD>7<EFBFBD><EFBFBD><EFBFBD>ֽڵ<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>źţ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
95 1 {
|
|
|
|
|
96 2 Ds1302Write(WRITE_RTC_ADDR[n],TIME[n]);
|
|
|
|
|
97 2 }
|
|
|
|
|
98 1 Ds1302Write(0x8E,0x80); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
99 1 }
|
|
|
|
|
100
|
|
|
|
|
101 void Ds1302ReadTime()
|
|
|
|
|
102 {
|
|
|
|
|
103 1 uchar n;
|
|
|
|
|
104 1 for (n=0; n<7; n++)//<EFBFBD><EFBFBD>ȡ7<EFBFBD><EFBFBD><EFBFBD>ֽڵ<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>źţ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
105 1 {
|
|
|
|
|
106 2 TIME[n] = Ds1302Read(READ_RTC_ADDR[n]);
|
|
|
|
|
107 2 }
|
|
|
|
|
108 1 }
|
|
|
|
|
109
|
|
|
|
|
110
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MODULE INFORMATION: STATIC OVERLAYABLE
|
|
|
|
|
CODE SIZE = 184 ----
|
|
|
|
|
CONSTANT SIZE = 14 ----
|
|
|
|
|
XDATA SIZE = ---- ----
|
|
|
|
|
PDATA SIZE = ---- ----
|
|
|
|
|
C51 COMPILER V9.56.0.0 DS1302 04/28/2022 23:43:37 PAGE 3
|
|
|
|
|
|
|
|
|
|
DATA SIZE = 7 ----
|
|
|
|
|
IDATA SIZE = ---- ----
|
|
|
|
|
BIT SIZE = ---- ----
|
|
|
|
|
END OF MODULE INFORMATION.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
|