?? i2c.lst
字號:
C51 COMPILER V3.20, SN-50203013 I2C 03/14/07 15:02:59 PAGE 1
DOS C51 COMPILER V3.20, COMPILATION OF MODULE I2C
OBJECT MODULE PLACED IN I2C.OBJ
COMPILER INVOKED BY: D:\COMP51\BIN\C51.EXE I2C.C DB OE SMALL ROM(LARGE)
stmt level source
1 #define uchar unsigned char
2 #define uint unsigned int
3 #define ulong unsigned long
4 #pragma ROM(LARGE)
5 #include <reg52.h>
6 #include <intrins.h>
7 #include <pub2000.h>
8 #pragma RB(0)
9
10 #define nop _nop_();
11
12 uchar bdata PCFByte;
13 sbit PCFBit0 = PCFByte^0;
14 sbit PCFBit1 = PCFByte^1;
15 sbit PCFBit2 = PCFByte^2;
16 sbit PCFBit3 = PCFByte^3;
17 sbit PCFBit4 = PCFByte^4;
18 sbit PCFBit5 = PCFByte^5;
19 sbit PCFBit6 = PCFByte^6;
20 sbit PCFBit7 = PCFByte^7;
21
22 void start()
23 {
24 1 RSDA = 1;
25 1 RSCK = 1;
26 1 nop;nop;nop;nop;
27 1 RSDA = 0;
28 1 nop; nop; nop; nop; nop;
29 1 RSCK = 0;
30 1 }
31
32 void stop()
33 {
34 1 RSCK = 0;
35 1 RSDA = 0;
36 1 nop; nop; nop; nop;
37 1 RSCK = 1;
38 1 nop; nop; nop; nop; nop;
39 1 RSDA = 1;
40 1 }
41
42 bit waitAck()
43 {
44 1 // debug
45 1 // uint errtime=255;/*因故障接收方無ACK,超時值為255*/
46 1 uchar errtime=255;
47 1
48 1 RSDA=1; nop;nop;
49 1 RSCK=1; nop;nop;
50 1 while ( RSDA )
51 1 {
52 2 errtime--;
53 2 if ( errtime==0)
54 2 {stop();
55 3 return 0;
C51 COMPILER V3.20, SN-50203013 I2C 03/14/07 15:02:59 PAGE 2
56 3 }
57 2 else;
58 2 }
59 1 RSCK=0;
60 1 return 1;
61 1 }
62
63 void shiftOut(uchar byte)
64 {
65 1 uchar i;
66 1 bit flag;
67 1 PCFByte=byte;
68 1
69 1 RSCK=0; nop;nop; RSDA=PCFBit7; nop; nop; RSCK=1; nop; nop;nop;nop;
70 1 RSCK=0; nop;nop; RSDA=PCFBit6; nop; nop; RSCK=1; nop; nop;nop;nop;
71 1 RSCK=0; nop;nop; RSDA=PCFBit5; nop; nop; RSCK=1; nop; nop;nop;nop;
72 1 RSCK=0; nop;nop; RSDA=PCFBit4; nop; nop; RSCK=1; nop; nop;nop;nop;
73 1 RSCK=0; nop;nop; RSDA=PCFBit3; nop; nop; RSCK=1; nop; nop;nop;nop;
74 1 RSCK=0; nop;nop; RSDA=PCFBit2; nop; nop; RSCK=1; nop; nop;nop;nop;
75 1 RSCK=0; nop;nop; RSDA=PCFBit1; nop; nop; RSCK=1; nop; nop;nop;nop;
76 1 RSCK=0; nop;nop; RSDA=PCFBit0; nop; nop; RSCK=1; nop; nop;nop;nop;
77 1 RSCK = 0;
78 1 }
79
80 uchar shiftIn()
81 {
82 1 uchar i;
83 1 uchar byte;
84 1
85 1 RSDA = 1;
86 1 RSCK=0; nop; nop; RSCK = 1; nop;nop; PCFBit7=RSDA;
87 1 RSCK=0; nop; nop; RSCK = 1; nop;nop; PCFBit6=RSDA;
88 1 RSCK=0; nop; nop; RSCK = 1; nop;nop; PCFBit5=RSDA;
89 1 RSCK=0; nop; nop; RSCK = 1; nop;nop; PCFBit4=RSDA;
90 1 RSCK=0; nop; nop; RSCK = 1; nop;nop; PCFBit3=RSDA;
91 1 RSCK=0; nop; nop; RSCK = 1; nop;nop; PCFBit2=RSDA;
92 1 RSCK=0; nop; nop; RSCK = 1; nop;nop; PCFBit1=RSDA;
93 1 RSCK=0; nop; nop; RSCK = 1; nop;nop; PCFBit0=RSDA;
94 1 RSCK=0;
95 1 return PCFByte;
96 1 }
97
98 void noAck()
99 {
100 1 RSDA = 1;
101 1 nop; nop; nop; nop;
102 1 RSCK = 1;
103 1 nop; nop; nop; nop;
104 1 RSCK = 0;
105 1 }
106 /*
void ack()
{
RSDA=0; nop; nop; nop; nop;
RSCK=1; nop; nop; nop; nop;
RSCK=0;
}
*/
114
115 /********* 24c256 **********/
116 union {
117 uint llll;
C51 COMPILER V3.20, SN-50203013 I2C 03/14/07 15:02:59 PAGE 3
118 uchar buff[2];
119 } data DW;
120
121 char rdByte(uchar chip)
122 {
123 1 uchar byte;
124 1 chip++;
125 1 start();
126 1 shiftOut(chip); waitAck();
127 1 byte = shiftIn(); noAck();
128 1 return byte;
129 1 }
130
131 uchar rd24c256(uint addr)
132 {
133 1 uchar volume;
134 1 uchar chip;
135 1
136 1 DW.llll=addr;
137 1
138 1 chip=0xa0;
139 1 start();
140 1 shiftOut(chip); waitAck();
141 1 shiftOut( DW.buff[0] ); waitAck();
142 1 shiftOut( DW.buff[1] ); waitAck();
143 1 volume = rdByte(chip);
144 1 stop();
145 1
146 1 return volume;
147 1 }
148
149 bit wr24c256(uint addr, uchar byte)
150 {
151 1 uint kk;
152 1 uchar i=0;
153 1 uchar chip;
154 1 bit flag;
155 1
156 1 DW.llll=addr;
157 1 WP=0;
158 1 chip=0xa0;
159 1 start();
160 1 shiftOut(chip); waitAck();
161 1 shiftOut( DW.buff[0] ); waitAck();
162 1 shiftOut( DW.buff[1] ); waitAck();
163 1 shiftOut(byte); waitAck();
164 1 stop();
165 1 for (kk=0;kk<800;kk++) nop;
166 1 WP=1;
167 1 }
168
169 void init24c256()
170 {
171 1 stop();
172 1 }
173 /************ pcf8563 ************/
174 struct
175 {
176 uchar Sec;
177 uchar Min;
178 uchar Hour;
179 uchar Day;
C51 COMPILER V3.20, SN-50203013 I2C 03/14/07 15:02:59 PAGE 4
180 uchar Week;
181 uchar MonthCentury; //D7bit:Century; D7=1:19xx D7=0:20xx
182 uchar Year;
183 } Clock;
184
185
186 uchar rdPCF8563Byte(uchar loc)
187 {
188 1 uchar byte;
189 1
190 1 // if ( loc>=16 ) return 0xff; else;
191 1
192 1 start();
193 1 shiftOut(0xa2); waitAck();
194 1 shiftOut(loc); waitAck();
195 1
196 1 start();
197 1 shiftOut(0xa3); waitAck();
198 1 byte=shiftIn(); noAck();
199 1 stop();
200 1 }
201
202 void wrPCF8563Byte(uchar loc,uchar byte)
203 {
204 1 // if (loc>=16 ) return; else;
205 1 start();
206 1 shiftOut(0xa2); waitAck();
207 1 shiftOut(loc); waitAck();
208 1 shiftOut(byte); waitAck();
209 1 stop();
210 1 }
211
212 void setClock()
213 {
214 1 uchar * xp;
215 1 uchar i;
216 1
217 1 xp=&Clock.Sec;
218 1
219 1 start();
220 1 shiftOut(0xa2); waitAck();
221 1 shiftOut(0x2); waitAck();
222 1 for ( i=0;i<7;i++ )
223 1 { shiftOut(xp[i]); waitAck(); }
224 1 stop();
225 1 }
226
227 void getClock()
228 {
229 1 uchar i;
230 1 uchar * xp;
231 1
232 1 xp=&Clock.Sec;
233 1 for (i=0;i<7;i++) xp[i]=rdPCF8563Byte(0x2+i);
234 1
235 1 Clock.Sec&=0x7f;
236 1 Clock.Min&=0x7f;
237 1 Clock.Hour&=0x3f;
238 1 Clock.Day&=0x3f;
239 1 Clock.MonthCentury&=0x1f; //0x9f:include Century flag;
240 1 }
241 void setAlarmMMHH(uchar min,uchar hour)
C51 COMPILER V3.20, SN-50203013 I2C 03/14/07 15:02:59 PAGE 5
242 {
243 1 wrPCF8563Byte(0x1,0x0);
244 1 wrPCF8563Byte(0x9,min);
245 1 wrPCF8563Byte(0xa,hour);
246 1 wrPCF8563Byte(0x1,0x2);
247 1 }
248
249 void clrAlarm()
250 {
251 1 wrPCF8563Byte(0x01,0x00);
252 1 // wrPCF8563Byte(0x09,0x80);
253 1 // wrPCF8563Byte(0x0a,0x80);
254 1 // wrPCF8563Byte(0x0b,0xaa);
255 1 // wrPCF8563Byte(0x0c,0xaa);
256 1 // wrPCF8563Byte(0x0d,0x00);
257 1 // wrPCF8563Byte(0x0e,0x03);
258 1 }
259
260 // return=1:have Alarm;=0 not have alarm
261 bit rdAlarmFlag()
262 {
263 1 uchar byte;
264 1
265 1 byte=rdPCF8563Byte(0x1);
266 1 byte&=0x08;
267 1 if ( byte!=0x08 ) return 0;
268 1 else return 1;
269 1 }
270
271 void clrAlarmFlag()
272 {
273 1 wrPCF8563Byte(0x01,0x00);
274 1 }
275
276 void initPCF8563()
277 {
278 1 uchar byte;
279 1 // set Ctrl/Status1 register (address 00H)
280 1 // Test1=0:normal mode
281 1 // stop=0 :RTC source clock runs
282 1 // testC=0:power-on reset override facility is disabled(set to logic 0 for mormal operation).
283 1 wrPCF8563Byte(0x0,0x0);
284 1
285 1 // wrPCF8563Byte(0x0b,0xaa); // disable Day alarm
286 1 wrPCF8563Byte(0x0c,0xaa); // disable week alarm
287 1
288 1 // set Ctrl/Status2 register (address 01H)
289 1 // TI/TP = X
290 1 // AF =1: alarm flag remains unchanged
291 1 // TF =0: timer flag is cleared
292 1 // AIE=0: alarm interrupt disabled;
293 1 // TIE=0: timer interrupt disabled;
294 1 byte=rdPCF8563Byte(0x1);
295 1 byte &= 0xa;
296 1 wrPCF8563Byte(0x1,0);
297 1
298 1
299 1 // set CLKOUT CONTRAL register(address 0DH)
300 1 // FE =0:the CLKOUT output is inhibited and the CLKOUT output is set to high-impedance.
301 1 // FD1,FD0=0,0:These bits control the frequency output on the CLKOUT Fclkout=32.768kHz.
302 1 wrPCF8563Byte(0xd,0x0);
303 1
C51 COMPILER V3.20, SN-50203013 I2C 03/14/07 15:02:59 PAGE 6
304 1 // set Countdown registers (address 0EH)
305 1 // TE =0:timer is disabled.
306 1 // TD1,TD0=0,0:
307 1 wrPCF8563Byte(0xe,0x0);
308 1 // set timer countdown value register
309 1 wrPCF8563Byte(0xf,0x0);
310 1
311 1 getClock();
312 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 767 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 10 11
IDATA SIZE = ---- ----
BIT SIZE = ---- 2
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -