📄 rtc.lst
字号:
C51 COMPILER V7.06 RTC 10/13/2006 09:21:10 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE RTC
OBJECT MODULE PLACED IN rtc.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE rtc.c LARGE BROWSE DEBUG OBJECTEXTEND
stmt level source
1 #include <./Atmel/at89x52.h>
2 #include <stdio.h>
3 #include "source.h"
4 #include <intrins.h>
5 #include <absacc.h>
6 //_nop_();0.65us fosc=18.432
7 /*i2c max rate: 100k, so delay is needed*/
8 #define DELAY _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop
-_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_()
9 #define I2CDATA SDA /*为I2C的数据口*/
10 #define I2CSETDATA SDA=1 /*设置SDA为1*/
11 #define I2CCLRDATA SDA=0 /*设置SDA为0*/
12 #define I2CSETCLK SCL=1 /*设置SCL为1*/
13 #define I2CCLRCLK SCL=0 /*设置SCL为0*/
14 void i2c_start(){//为I2C的开始时序列
15 1 I2CSETDATA;
16 1 I2CSETCLK;
17 1 DELAY;
18 1 I2CCLRDATA;
19 1 DELAY;
20 1 I2CCLRCLK;
21 1 }
22 void i2c_stop(){//为I2C的停止时序
23 1 I2CCLRCLK;
24 1 I2CCLRDATA;
25 1 DELAY;
26 1 I2CSETCLK;
27 1 DELAY;
28 1 I2CSETDATA;
29 1 }
30 void i2c_write_byte(unsigned char ch)//为I2C的写一个字节的时序
31 {
32 1 unsigned char i=8;
33 1 while(i--){
34 2 I2CCLRCLK;_nop_();
35 2 if(ch&0x80)
36 2 I2CSETDATA;
37 2 else
38 2 I2CCLRDATA;
39 2 ch<<=1;DELAY;
40 2 I2CSETCLK;DELAY;
41 2 }
42 1 I2CCLRCLK;
43 1 }
44
45 unsigned char i2c_read_byte(void)//为I2C的读一个字节的时序
46 {
47 1 unsigned char i=8;
48 1 unsigned char ddata=0;
49 1 I2CSETDATA ;
50 1 while (i--){
51 2 ddata<<=1 ;
52 2 I2CCLRCLK;DELAY;
53 2 I2CSETCLK;DELAY;
54 2 ddata|=I2CDATA;
C51 COMPILER V7.06 RTC 10/13/2006 09:21:10 PAGE 2
55 2 }
56 1 I2CCLRCLK;
57 1 return ddata;
58 1 }
59 bit i2c_wait_ack(void)//为I2C的等待应答时序
60 {
61 1 unsigned char errtime=255;//因故障接收方无ACK 超时值为255
62 1 I2CSETDATA;DELAY;
63 1 I2CSETCLK ;DELAY;
64 1 while(I2CDATA){
65 2 errtime--;
66 2 if (!errtime){
67 3 i2c_stop();
68 3 return 0;
69 3 }
70 2 }
71 1 I2CCLRCLK;
72 1 return 1;
73 1 }
74 void i2c_send_ack(void)//为I2C的发送应答时序
75 {
76 1 I2CCLRDATA; DELAY;
77 1 I2CSETCLK; DELAY;
78 1 I2CCLRCLK;
79 1 }
80
81 void i2c_send_notack(void)//为I2C的发送无应答的时序列
82 {
83 1 I2CSETDATA ; DELAY;
84 1 I2CSETCLK ; DELAY;
85 1 I2CCLRCLK;
86 1 }
87 #define RTCWTIME 0X64
88 #define RTCRTIME 0X65
89 #define RTCRHOUR 0X67
90 #define RTCWSTAT 0X62
91 #define RTCWINT1 0X68
92 #define RTCWINT2 0X6A
93 unsigned char MSBTOLSM(unsigned char ch){//把MSB形式的字节转化为LSM的形式
94 1 unsigned char tmp=0;
95 1 unsigned char cvt;
96 1 unsigned char i;
97 1 cvt=ch;
98 1 for(i=0;i<8;i++){
99 2 tmp>>=1;
100 2 if(cvt&0x80){
101 3 tmp |=0x80;
102 3 }
103 2 else{
104 3 }
105 2 cvt<<=1;
106 2 }
107 1 return tmp;
108 1 }
109 unsigned char SD2000_set_time(struct RTC_TIME *p){//为SDA200设置时间的函数
110 1 unsigned char ch;
111 1 EA=0;
112 1 i2c_start();
113 1 i2c_write_byte(RTCWTIME);
114 1 ch=MSBTOLSM(p->year);
115 1 if(i2c_wait_ack()){
116 2 i2c_write_byte(ch);
C51 COMPILER V7.06 RTC 10/13/2006 09:21:10 PAGE 3
117 2 ch=MSBTOLSM(p->month);
118 2 i2c_wait_ack();
119 2 i2c_write_byte(ch);
120 2 ch=MSBTOLSM(p->dayom);
121 2 i2c_wait_ack();
122 2 i2c_write_byte(ch);
123 2 ch=MSBTOLSM(p->week);
124 2 i2c_wait_ack();
125 2 i2c_write_byte(ch);
126 2 ch=MSBTOLSM(p->hour);
127 2 i2c_wait_ack();
128 2 i2c_write_byte(ch);
129 2 ch=MSBTOLSM(p->minute);
130 2 i2c_wait_ack();
131 2 i2c_write_byte(ch);
132 2 ch=MSBTOLSM(p->second);
133 2 i2c_wait_ack();
134 2 i2c_write_byte(ch);
135 2 i2c_wait_ack();
136 2 i2c_stop();
137 2 }
138 1 else{
139 2 // RTC write ack error.
140 2 }
141 1 EA=1;
142 1 return 1;
143 1 }
144 unsigned char SD2000_read_time(struct RTC_TIME *p){//为SDA2000读时间(年月日时分秒)的函数
145 1 unsigned char ch;
146 1 EA=0;
147 1 i2c_start();
148 1 i2c_write_byte(RTCRTIME);
149 1 if(!i2c_wait_ack()){
150 2 EA=1;
151 2 return 0;//no ack.
152 2 }
153 1 ch=i2c_read_byte();
154 1 i2c_send_ack();
155 1 p->year=MSBTOLSM(ch);
156 1 ch=i2c_read_byte();
157 1 i2c_send_ack();
158 1 p->month=MSBTOLSM(ch);
159 1 ch=i2c_read_byte();
160 1 i2c_send_ack();
161 1 p->dayom=MSBTOLSM(ch);
162 1 ch=i2c_read_byte();
163 1 i2c_send_ack();
164 1 p->week=MSBTOLSM(ch);
165 1 ch=i2c_read_byte();
166 1 i2c_send_ack();
167 1 p->hour=MSBTOLSM(ch);
168 1 p->hour &=0x3f;//24 hour AM/PM bit ivalid.
169 1 ch=i2c_read_byte();
170 1 i2c_send_ack();
171 1 p->minute=MSBTOLSM(ch);
172 1 ch=i2c_read_byte();
173 1 i2c_send_notack();
174 1 p->second=MSBTOLSM(ch);
175 1 i2c_stop();
176 1 EA=1;
177 1 }
178 void SD2000_read_hour(struct RTC_TIME *p){//为SDA2000读时间(时分秒)的函数
C51 COMPILER V7.06 RTC 10/13/2006 09:21:10 PAGE 4
179 1 unsigned char ch;
180 1 i2c_start();
181 1 i2c_write_byte(RTCRHOUR);
182 1 if(i2c_wait_ack()){
183 2 // I2c read ack ok.
184 2 }
185 1 else{
186 2 //I2c read ack error.
187 2 return;
188 2 }
189 1 ch=i2c_read_byte();
190 1 i2c_send_ack();
191 1 ch=MSBTOLSM(ch);
192 1 ch &=0x3f;//24 hour AM/PM bit invalid.
193 1 ch=i2c_read_byte();
194 1 i2c_send_ack();
195 1 ch=MSBTOLSM(ch);
196 1 ch=i2c_read_byte();
197 1 i2c_send_notack();
198 1 ch=MSBTOLSM(ch);
199 1 i2c_stop();
200 1 }
*** WARNING C280 IN LINE 178 OF RTC.C: 'p': unreferenced local variable
201 void SD2000_set_status(unsigned char ch){//为SDA200的设置状态函数
202 1 EA=0;
203 1 i2c_start();
204 1 i2c_write_byte(RTCWSTAT);
205 1 if(i2c_wait_ack()){
206 2 //I2c set status ack ok.
207 2 }
208 1 else{
209 2 //I2c set status ack error.
210 2 EA=1;
211 2 return;
212 2 }
213 1 ch |=0x40;//interrupt 1 output vaild.
214 1 i2c_write_byte(ch);//24hour 1Hz interrupt.
215 1 i2c_wait_ack();
216 1 i2c_stop();
217 1 for(ch=0;ch<250;ch++){
218 2 ;//delay;
219 2 }
220 1 i2c_start();
221 1 i2c_write_byte(RTCWINT1);
222 1 if(i2c_wait_ack()){
223 2 //I2c set Freq ack ok.
224 2 }
225 1 else{
226 2 // I2c set Freq ack error.
227 2 EA=1;
228 2 return;
229 2 }
230 1 i2c_write_byte(0);//f7~f0=0;
231 1 i2c_wait_ack();
232 1 i2c_write_byte(1);//f15=1,f14~f8=0;
233 1 i2c_wait_ack();
234 1 i2c_stop();
235 1 EA=1;
236 1 }
237
238 void SD2000_set_freq(unsigned char ch1,unsigned char ch2, unsigned char ch3){//为SDA200设置中断频率的函数
239 1 unsigned char ch;
C51 COMPILER V7.06 RTC 10/13/2006 09:21:10 PAGE 5
240 1 EA=0;
241 1 i2c_start();
242 1 i2c_write_byte(RTCWSTAT);
243 1 if(i2c_wait_ack()){
244 2 //I2c set status ack ok.
245 2 }
246 1 else{
247 2 //I2c set status ack error.
248 2 EA=1;
249 2 return;
250 2 }
251 1 ch=MSBTOLSM(ch1);
252 1 i2c_write_byte(ch);//24hour 1Hz interrupt.
253 1 i2c_wait_ack();
254 1 i2c_stop();
255 1 for(ch=0;ch<250;ch++){
256 2 ;//delay;
257 2 }
258 1 i2c_start();
259 1 i2c_write_byte(RTCWINT1);
260 1 if(i2c_wait_ack()){
261 2 //I2c set Freq ack ok.
262 2 }
263 1 else{
264 2 // I2c set Freq ack error.
265 2 EA=1;
266 2 return;
267 2 }
268 1 ch=MSBTOLSM(ch2);
269 1 // f0~f7=%bx",ch
270 1 i2c_write_byte(ch);//f7~f0=0;
271 1 i2c_wait_ack();
272 1 ch=MSBTOLSM(ch3);
273 1 // f8~f15=%bx",ch
274 1 i2c_write_byte(ch);//f15=1,f14~f8=0;
275 1 i2c_wait_ack();
276 1 i2c_stop();
277 1 EA=1;
278 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 912 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- 6
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 1 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -