ZDBMS/output/RTC.lst

284 lines
14 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

C51 COMPILER V9.01 RTC 02/22/2025 15:36:22 PAGE 1
C51 COMPILER V9.01, COMPILATION OF MODULE RTC
OBJECT MODULE PLACED IN .\output\RTC.obj
COMPILER INVOKED BY: D:\Tool\Keil\C51\BIN\C51.EXE code_drv\RTC.c LARGE OPTIMIZE(7,SIZE) REGFILE(.\output\MCUCore_Load.OR
-C) BROWSE INTVECTOR(0X1000) INCDIR(.\header_app;.\header_drv;.\code_gasguage;.\code_classb\iec60730_lib\include;.\code_c
-lassb\iec60730_proc\Include;.\code_classb\config) DEBUG OBJECTEXTEND PRINT(.\output\RTC.lst) OBJECT(.\output\RTC.obj)
line level source
1 /********************************************************************************
2 Copyright (C), Sinowealth Electronic. Ltd.
3 Author: Sino
4 Version: V0.0
5 Date: 2020/04/26
6 History:
7 V2.0 2020/04/26 Preliminary
8 ********************************************************************************/
9 #include "Main.h"
10
11
12 BOOL bRTCErr;
13 BOOL bRTCTwiRWErr;
14 U8 xdata ucRTCTwiRWErrDelayCnt;
15 RTC_VAR xdata RTC; //For External RTC
16
17 /*************************************************************************************************
18 * 函数名: RTCTwiCheck
19 * 参 数: 无
20 * 返回值: 无
21 * 描 述: 连续5S检测到RTC的I2C通讯错误则置位bRTCErr=1
22 *************************************************************************************************/
23 void RTCTwiCheck(void)
24 {
25 1 if(bEnEEPRomBK)
26 1 {
27 2 if(bRTCTwiRWErr)
28 2 {
29 3 if(++ucRTCTwiRWErrDelayCnt >= TIME_1S_5S)
30 3 {
31 4 bRTCErr = 1;
32 4 ucRTCTwiRWErrDelayCnt = TIME_1S_5S;
33 4 }
34 3 }
35 2 else
36 2 {
37 3 ucRTCTwiRWErrDelayCnt = 0;
38 3 }
39 2 }
40 1 }
41
42
43 /*************************************************************************************************
44 * 函数名: RTCWrite
45 * 参 数: WrAddr: 寄存器地址Length数据长度WrBuf数据缓存Buf
46 * 返回值: 无
47 * 描 述: RTC写寄存器操作如果出错连续写两次
48 *************************************************************************************************/
49 BOOL RTCWrite(U8 WrAddr, U8 Length, U8 xdata *WrBuf)
50 {
51 1 BOOL Result = 0;
52 1 U8 i;
53 1
C51 COMPILER V9.01 RTC 02/22/2025 15:36:22 PAGE 2
54 1 if(!bRTCErr)
55 1 {
56 2 for(i=0; i<5; i++)
57 2 {
58 3 #ifdef TWI_Hardware_Module
59 3 if(TwiWrite(RTC_ID, WrAddr, TWI_ADDR_1B, Length, TWI_CRC_NO, WrBuf))
60 3 {
61 4 Result = 1;
62 4 break;
63 4 }
64 3 #else
if(Result = TwiWrite(RTC_ID, WrAddr, Length, WrBuf))
{
Result = 1;
break;
}
#endif
71 3 Delay1ms(1);
72 3 }
73 2 }
74 1 bRTCTwiRWErr = !Result;
75 1
76 1 return Result;
77 1 }
78
79
80 /*************************************************************************************************
81 * 函数名: RTCRead
82 * 参 数: RdAddr: 寄存器地址Length数据长度WrBuf数据缓存Buf
83 * 返回值: 无
84 * 描 述: RTC读寄存器操作如果出错连续读两次
85 *************************************************************************************************/
86 BOOL RTCRead(U8 RdAddr, U8 Length, U8 xdata *RdBuf)
87 {
88 1 BOOL Result = 0;
89 1 U8 i;
90 1
91 1 if(!bRTCErr)
92 1 {
93 2 for(i=0; i<5; i++)
94 2 {
95 3 #ifdef TWI_Hardware_Module
96 3 if(TwiRead(RTC_ID, RdAddr, TWI_ADDR_1B, Length, TWI_CRC_NO, RdBuf))
97 3 {
98 4 Result = 1;
99 4 break;
100 4 }
101 3 #else
if(TwiRead(RTC_ID, RdAddr, Length, RdBuf))
{
Result = 1;
break;
}
#endif
108 3 Delay1ms(1);
109 3 }
110 2 }
111 1 bRTCTwiRWErr = !Result;
112 1
113 1 return Result;
114 1 }
115
C51 COMPILER V9.01 RTC 02/22/2025 15:36:22 PAGE 3
116 /*************************************************************************************************
117 * 函数名: RTCReadTime
118 * 参 数: RdAddr: 寄存器地址Length数据长度WrBuf数据缓存Buf
119 * 返回值: 无
120 * 描 述: RTC读寄存器操作如果出错连续读两次
121 *************************************************************************************************/
122 BOOL RTCReadTime(RTC_VAR xdata *RtcRdVal)
123 {
124 1 U8 xdata rtcbuf[9];
125 1 BOOL Result = 0;
126 1
127 1 if(RTCRead(0x00, 9, &rtcbuf)) //从RTC读取时间
128 1 {
129 2 if((rtcbuf[7]&0x01) == 0x00) //judge RTCF bit看是否曾经掉过电
130 2 {
131 3 if( ((rtcbuf[2]&0x80) == 0) //不是24小时制
132 3 || ((rtcbuf[0]&0x70) > 0x50) || ((rtcbuf[0]&0x0F) > 0x09) || ((rtcbuf[0]&0x7F) > 0x59)
133 3 || ((rtcbuf[1]&0x70) > 0x50) || ((rtcbuf[1]&0x0F) > 0x09) || ((rtcbuf[1]&0x7F) > 0x59)
134 3 || ((rtcbuf[2]&0x30) > 0x20) || ((rtcbuf[2]&0x0F) > 0x09) || ((rtcbuf[2]&0x2F) > 0x24)
135 3 || ((rtcbuf[3]&0x30) > 0x30) || ((rtcbuf[3]&0x0F) > 0x09) || ((rtcbuf[3]&0x3F) > 0x31) || (!(r
-tcbuf[3]&0x3F))
136 3 || ((rtcbuf[4]&0x10) > 0x10) || ((rtcbuf[4]&0x0F) > 0x09) || ((rtcbuf[4]&0x1F) > 0x12) || (!(r
-tcbuf[4]&0x1F))
137 3 || ((rtcbuf[5]&0xF0) > 0x90) || ((rtcbuf[5]&0x0F) > 0x09) || ((rtcbuf[5]&0xFF) > 0x99)
138 3 || ((rtcbuf[6]&0x07) > 0x06) ) //对小时制及数据合法性进行检查
139 3 {
140 4 rtcbuf[0] = RtcRdVal->Second; //数据不合法可能是因为RTC未初始化导致
141 4 rtcbuf[1] = RtcRdVal->Minute;
142 4 rtcbuf[2] = RtcRdVal->Hour;
143 4 rtcbuf[3] = RtcRdVal->Date;
144 4 rtcbuf[4] = RtcRdVal->Month;
145 4 rtcbuf[5] = RtcRdVal->Year;
146 4 rtcbuf[6] = RtcRdVal->Week;
147 4
148 4 Result = RTCModifyTime((RTC_VAR xdata *)(&rtcbuf));
149 4 }
150 3 else
151 3 {
152 4 RtcRdVal->Second = rtcbuf[0]; //数据合法则保存从RTC读回的时间
153 4 RtcRdVal->Minute = rtcbuf[1];
154 4 RtcRdVal->Hour = rtcbuf[2]&0x1F;
155 4 RtcRdVal->Date = rtcbuf[3];
156 4 RtcRdVal->Month = rtcbuf[4];
157 4 RtcRdVal->Year = rtcbuf[5];
158 4 RtcRdVal->Week = rtcbuf[6];
159 4
160 4 Result = 1;
161 4 }
162 3 }
163 2 else //曾经掉电过认为RTC不准。
164 2 {
165 3 Result = RTCModifyTime((RTC_VAR xdata *)RtcRdVal); //将当前的时间或从E2中读取的时间或固定
-时间重新写入RTC
166 3 }
167 2 }
168 1
169 1 return Result;
170 1 }
171
172
173 /*************************************************************************************************
174 * 函数名: RTCModifyTime
C51 COMPILER V9.01 RTC 02/22/2025 15:36:22 PAGE 4
175 * 参 数: RTC将RTC参数传递进来进行RTC更新
176 * 返回值: 无
177 * 描 述: RTC读寄存器操作如果出错连续读两次
178 *************************************************************************************************/
179 BOOL RTCModifyTime(RTC_VAR xdata *RtcMdyVal)
180 {
181 1 BOOL Result = 0;
182 1 U8 xdata rtcdata;
183 1 U8 xdata rtctemp[7];
184 1
185 1 rtcdata = 0x90;
186 1 Result = RTCWrite(RTC_REG_STATUS, 1, &rtcdata);
187 1
188 1 rtctemp[0] = RtcMdyVal->Second;
189 1 rtctemp[1] = RtcMdyVal->Minute;
190 1 rtctemp[2] = RtcMdyVal->Hour|0x80; //设置为24小时制
191 1 rtctemp[3] = RtcMdyVal->Date;
192 1 rtctemp[4] = RtcMdyVal->Month;
193 1 rtctemp[5] = RtcMdyVal->Year;
194 1 rtctemp[6] = RtcMdyVal->Week;
195 1
196 1 Result = RTCWrite(RTC_REG_SECOND, 7, (U8 xdata *)&rtctemp);
197 1
198 1 return Result;
199 1 }
200
201
202 /*************************************************************************************************
203 * 函数名: RTCInitTime
204 * 参 数: RTC将RTC参数传递进来进行RTC初始化
205 * 返回值: 无
206 * 描 述: 初始化从EEP读取保存的RTC时间参数进行第一次初始化如果EEP没有保存则默认初始化时间20年5月1<E69C88>
-<2D>12点
207 *************************************************************************************************/
208 BOOL RTCInitTime(RTC_VAR xdata *RtcInitVal)
209 {
210 1 BOOL Result = 0;
211 1 U8 xdata rtcbuf[9];
212 1 U8 xdata i;
213 1 U8 xdata checksum = 0;
214 1
215 1 MemorySet(rtcbuf, 0, sizeof(rtcbuf));
216 1
217 1 E2PRomRead(E2PROM_RTC_ADDR, 9, rtcbuf); //从E2备份区读出RTC数据
218 1 for(i=0; i<7; i++)
219 1 {
220 2 checksum += rtcbuf[i];
221 2 }
222 1
223 1 if((rtcbuf[7]!=checksum) || (rtcbuf[8]!=0x5a)) //若校验失败说明E2读出的时间不可靠直接把<E68EA5>
-龀<>奔淠美从<E7BE8E>
224 1 {
225 2 rtcbuf[0] = 0x00; //second
226 2 rtcbuf[1] = 0x00; //minute
227 2 rtcbuf[2] = 0x12; //hour
228 2 rtcbuf[3] = 0x01; //date
229 2 rtcbuf[4] = 0x05; //month
230 2 rtcbuf[5] = 0x20; //year
231 2 rtcbuf[6] = 0x05; //week
232 2 }
233 1
234 1 MemoryCopy(rtcbuf, (U8 xdata *)RtcInitVal, 7); //从E2读出的时间或出厂时间先放到RTC时间寄存器
C51 COMPILER V9.01 RTC 02/22/2025 15:36:22 PAGE 5
-中存起来
235 1 Result = RTCReadTime((RTC_VAR xdata *)RtcInitVal);
236 1
237 1 return Result;
238 1 }
239
240
241
242
243
244
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 958 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = 8 43
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = 2 5
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)