?? 24c08.lst
字號(hào):
C51 COMPILER V7.20 24C08 05/15/2009 19:28:52 PAGE 1
C51 COMPILER V7.20, COMPILATION OF MODULE 24C08
OBJECT MODULE PLACED IN 24C08.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE 24C08.C BROWSE DEBUG OBJECTEXTEND
line level source
1 /**********************************************************
2 24c08掉電保護(hù)試驗(yàn)程序
3 功能描述:從00-99計(jì)數(shù),中間因意外斷電,當(dāng)再次來電時(shí)
4 數(shù)碼管將接著掉電前的數(shù)字繼續(xù)計(jì)數(shù)
5 ***********************************************************/
6 #include <reg52.H>
7
8 #include <stdio.h>
9
10 #include <absacc.h>
11
12 unsigned char code table[]={ 0xc0,0xf9,0xa4,0xb0,0x99,0x92,
13
14 0x82,0xf8,0x80,0x90,0x40};
15
16 unsigned char sec; //定義計(jì)數(shù)值,每過1 秒,sec加1
17
18 unsigned int tcnt; //定時(shí)中斷次數(shù)
19
20 bit write=0; //寫24C08 的標(biāo)志;
21
22 sbit gewei=P2^0; //個(gè)位選通定義
23
24 sbit shiwei=P2^1; //十位選通定義
25
26 /*********************************************************
27 與單片機(jī)連接引腳定義
28 *********************************************************/
29
30 sbit scl=P3^7; // 24c08 SCL
31
32 sbit sda=P3^6; // 24c08 SDA
33 /*********************************************************
34 延時(shí)
35 *********************************************************/
36 void delay1(unsigned char x)
37
38 { unsigned int i;
39 1
40 1 for(i=0;i<x;i++);
41 1
42 1 }
43 /*************************************************
44
45 **************************************************/
46 void flash()
47
48 { ; ; }
49 /******************************************************
50 24c08 初始化子程序
51 ******************************************************/
52 void x24c08_init()
53
54 {scl=1;
55 1 flash();
C51 COMPILER V7.20 24C08 05/15/2009 19:28:52 PAGE 2
56 1 sda=1;
57 1 flash();
58 1 }
59 /******************************************************
60 啟動(dòng)(I2C)總線
61 ******************************************************/
62 void start()
63
64 { sda=1;
65 1 flash();
66 1 scl=1;
67 1 flash();
68 1 sda=0;
69 1 flash();
70 1 scl=0;
71 1 flash();
72 1 }
73 /*********************************************************
74 停止(I2C)總線
75 *********************************************************/
76 void stop()
77
78 {sda=0;
79 1 flash();
80 1 scl=1;
81 1 flash();
82 1 sda=1;
83 1 flash();}
84 /*********************************************************
85 寫一個(gè)字節(jié)程序
86 *********************************************************/
87 void writex(unsigned char j)
88
89 { unsigned char i,temp;
90 1
91 1 temp=j;
92 1
93 1 for (i=0;i<8;i++)
94 1
95 1 {temp=temp<<1;
96 2 scl=0;
97 2 flash();
98 2 sda=CY;
99 2 flash();
100 2 scl=1;
101 2 flash();
102 2 }
103 1
104 1 scl=0;
105 1 flash();
106 1 sda=1;
107 1 flash();
108 1
109 1 }
110
111 /*********************************************************
112 讀一個(gè)字節(jié)程序
113 *********************************************************/
114 unsigned char readx()
115
116 {
117 1
C51 COMPILER V7.20 24C08 05/15/2009 19:28:52 PAGE 3
118 1 unsigned char i,j,k=0;
119 1
120 1 scl=0; flash(); sda=1;
121 1
122 1 for (i=0;i<8;i++)
123 1
124 1 {
125 2
126 2 flash(); scl=1; flash();
127 2
128 2 if (sda==1) j=1;
129 2
130 2 else j=0;
131 2
132 2 k=(k<<1)|j;
133 2
134 2 scl=0;}
135 1
136 1 flash(); return(k);
137 1
138 1 }
139 /*********************************************************
140 (I2C)線時(shí)鐘
141 *********************************************************/
142 void clock()
143
144 {
145 1
146 1 unsigned char i=0;
147 1
148 1 scl=1;
149 1 flash();
150 1
151 1 while ((sda==1)&&(i<255))i++;
152 1
153 1 scl=0;
154 1 flash();
155 1
156 1 }
157
158
159 /*********************************************************
160 從24c02 的地址address 中讀取一個(gè)字節(jié)數(shù)據(jù)
161 *********************************************************/
162 unsigned char x24c08_read(unsigned char address)
163
164 {
165 1
166 1 unsigned char i;
167 1
168 1 start(); writex(0xa0);
169 1
170 1 clock(); writex(address);
171 1
172 1 clock(); start();
173 1
174 1 writex(0xa1); clock();
175 1
176 1 i=readx(); stop();
177 1
178 1 delay1(10);
179 1
C51 COMPILER V7.20 24C08 05/15/2009 19:28:52 PAGE 4
180 1 return(i);
181 1
182 1 }
183 /*********************************************************
184 向24c02 的address地址中寫入一字節(jié)數(shù)據(jù)info
185 *********************************************************/
186 void x24c08_write(unsigned char address,unsigned char info)
187
188 {
189 1
190 1 EA=0;
191 1
192 1 start(); writex(0xa0);
193 1
194 1 clock(); writex(address);
195 1
196 1 clock(); writex(info);
197 1
198 1 clock(); stop();
199 1
200 1 EA=1;
201 1
202 1 delay1(50);
203 1
204 1 }
205 /*********************************************************
206 延時(shí)程序
207 *********************************************************/
208
209
210 void Delay(unsigned int tc)
211
212 {
213 1
214 1 while( tc != 0 )
215 1
216 1 {unsigned int i;
217 2
218 2 for(i=0; i<100; i++);
219 2
220 2 tc--;}
221 1
222 1 }
223 /*********************************************************
224 LED顯示函數(shù)
225 *********************************************************/
226 void LED()
227
228 {
229 1
230 1 shiwei=0; P0=table[sec/10]; Delay(8); shiwei=1;
231 1
232 1 gewei=0; P0=table[sec%10]; Delay(5); gewei=1;
233 1
234 1 }
235
236 void t0(void) interrupt 1 using 0 //定時(shí)中斷服務(wù)函數(shù)
237
238 {
239 1
240 1 TH0=(65536-50000)/256; //對(duì)TH0 TL0 賦值
241 1
C51 COMPILER V7.20 24C08 05/15/2009 19:28:52 PAGE 5
242 1 TL0=(65536-50000)%256; //重裝計(jì)數(shù)初值
243 1
244 1 tcnt++; //每過250ust tcnt 加一
245 1
246 1 if(tcnt==20) //計(jì)滿20次(1 秒)時(shí)
247 1
248 1 {
249 2
250 2 tcnt=0; //重新再計(jì)
251 2
252 2 sec++;
253 2
254 2 write=1; //1 秒寫一次24C08
255 2
256 2 if(sec==100) //定時(shí)100 秒,在從零開始計(jì)時(shí)
257 2
258 2 {sec=0;}
259 2
260 2 }
261 1
262 1 }
263
264 void main(void)
265
266 {
267 1
268 1 TMOD=0x01; //定時(shí)器工作在方式1
269 1
270 1 ET0=1; EA=1;
271 1
272 1 x24c08_init(); //初始化24C08
273 1
274 1 sec=x24c08_read(2);//讀出保存的數(shù)據(jù)賦于sec
275 1
276 1 TH0=(65536-50000)/256; //對(duì)TH0 TL0 賦值
277 1
278 1 TL0=(65536-50000)%256; //使定時(shí)器0.05 秒中斷一次
279 1
280 1 TR0=1; //開始計(jì)時(shí)
281 1
282 1 while(1)
283 1
284 1 {
285 2
286 2 LED();
287 2
288 2 if(write==1) //判斷計(jì)時(shí)器是否計(jì)時(shí)一秒
289 2
290 2 {
291 3
292 3 write=0; //清零
293 3
294 3 x24c08_write(2,sec); //在24c08 的地址2 中寫入數(shù)據(jù)sec
295 3
296 3 }
297 2
298 2 }
299 1
300 1 }
301
C51 COMPILER V7.20 24C08 05/15/2009 19:28:52 PAGE 6
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 397 ----
CONSTANT SIZE = 11 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 3 2
IDATA SIZE = ---- ----
BIT SIZE = 1 ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -