?? 2401.lst
字號:
C51 COMPILER V7.06 2401 03/02/2006 23:49:39 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE 2401
OBJECT MODULE PLACED IN 2401.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE 2401.C BROWSE DEBUG OBJECTEXTEND
stmt level source
1 /******************************************************************
2 本程序只供學習使用,未經作者許可,不得用于其它任何用途
3 我的郵箱:computer-lov@tom.com
4 歡迎訪問我的blog: http://computer00.21ic.org
5
6 2401.c文件 2401-I2CROM的讀寫函數
7
8 Created by Computer-lov
9 Date: 2004.11.12
10
11 Edit date:2006.3.2
12
13 Version V1.0
14 Copyright(C) Computer-lov 2004-2014
15 All rigths reserved
16 *******************************************************************/
17
18
19 #include "hardware.h"
20 #include "2401.h"
21 #include "main.h"
22
23
24 void delay(void) //延時子程序
25 {
26 1 unsigned char i;
27 1 for(i=0;i<1;i++);
28 1 }
29
30 //************************************** 將一個字節保存到EEROM中 *************************************
-****
31 unsigned char Write_a_EEPROM_data(unsigned char device_addr,unsigned char data_addr,unsigned char w_data)
32 {
33 1 unsigned char i,Device_Addr;
34 1 if(NO_2401)return 0xFF;
35 1 delay();
36 1 SDA=0; //產生一個起始位
37 1 delay();
38 1 Device_Addr=device_addr; //EEROM的地址暫存
39 1 for(i=0;i<7;i++) //輸出設備地址
40 1 {
41 2 SCL=0;
42 2 delay();
43 2 SDA=device_addr&0x80; //SDA上輸出一位數據,高位在前
44 2 device_addr<<=1;
45 2 delay();
46 2 SCL=1;
47 2 delay();
48 2 }
49 1 SCL=0;
50 1 delay();
51 1 SDA=0; //SDA上輸出0,表示寫操作
52 1 delay();
53 1 SCL=1;
54 1 delay();
C51 COMPILER V7.06 2401 03/02/2006 23:49:39 PAGE 2
55 1 SCL=0;
56 1 delay();
57 1 SDA=1; //釋放SDA線
58 1 delay();
59 1 SCL=1;
60 1 delay();
61 1 if(SDA){return 1;} //如果設備未響應,則返回出錯代碼1
62 1 for(i=0;i<8;i++) //輸出數據地址
63 1 {
64 2 SCL=0;
65 2 delay();
66 2 SDA=data_addr&0x80; //SDA上輸出一位數據,高位在前
67 2 data_addr<<=1;
68 2 delay();
69 2 SCL=1;
70 2 delay();
71 2 delay();
72 2 }
73 1 SCL=0;
74 1 delay();
75 1 SDA=1; //釋放SDA線
76 1 delay();
77 1 SCL=1;
78 1 delay();
79 1 if(SDA){return 2;} //如果設備未響應,則返回出錯代碼2
80 1 for(i=0;i<8;i++) //輸出要寫入的數據
81 1 {
82 2 SCL=0;
83 2 delay();
84 2 SDA=w_data&0x80; //SDA上輸出一位數據,高位在前
85 2 w_data<<=1;
86 2 delay();
87 2 SCL=1;
88 2 delay();
89 2 }
90 1 SCL=0;
91 1 delay();
92 1 SDA=1; //釋放SDA線
93 1 delay();
94 1 SCL=1;
95 1 delay();
96 1 if(SDA){return 3;} //如果設備未響應,則返回出錯代碼3
97 1 SCL=0;
98 1 delay();
99 1 SDA=0;
100 1 delay();
101 1 SCL=1;
102 1 delay();
103 1 SDA=1; //產生一個停止位,停止操作
104 1 for(i=0;i<250;i++) //等待數據寫入
105 1 {
106 2 delay();
107 2 }
108 1 for(i=0;i<250;i++)delay();
109 1 return 0; //正確寫入,返回0
110 1 }
111 //****************************************************************************************
112
113 //********************************* 從EEROM中讀取一個字節 *****************************
114 unsigned int Read_a_EEPROM_data(unsigned char device_addr,unsigned char data_addr)
115 {
116 1 unsigned char i,r_data,Device_Addr;
C51 COMPILER V7.06 2401 03/02/2006 23:49:39 PAGE 3
117 1 SDA=0; //產生一個起始位
118 1 delay();
119 1 Device_Addr=device_addr; //EEROM的地址暫存
120 1 for(i=0;i<7;i++) //輸出設備地址
121 1 {
122 2 SCL=0;
123 2 delay();
124 2 SDA=device_addr&0x80; //SDA上輸出一位數據,高位在前
125 2 device_addr<<=1;
126 2 delay();
127 2 SCL=1;
128 2 delay();
129 2 }
130 1 SCL=0;
131 1 delay();
132 1 SDA=0; //SDA上輸出0,表示寫操作
133 1 delay();
134 1 SCL=1;
135 1 delay();
136 1 SCL=0;
137 1 delay();
138 1 SDA=1; //釋放SDA線
139 1 delay();
140 1 SCL=1;
141 1 delay();
142 1 if(SDA) return 0x0100; //如果設備未響應,則返回出錯代碼0x0100
143 1 for(i=0;i<8;i++) //輸出數據地址
144 1 {
145 2 SCL=0;
146 2 delay();
147 2 SDA=data_addr&0x80; //SDA上輸出一位數據,高位在前
148 2 data_addr<<=1;
149 2 delay();
150 2 SCL=1;
151 2 delay();
152 2 delay();
153 2 }
154 1 SCL=0;
155 1 delay();
156 1 SDA=1; //釋放SDA線
157 1 delay();
158 1 SCL=1;
159 1 delay();
160 1 if(SDA) return 0x0200; //如果設備未響應,則返回出錯代碼0x0200
161 1 SCL=0;
162 1 delay();
163 1 SDA=1;
164 1 delay();
165 1 SCL=1;
166 1 delay();
167 1 SDA=0; //產生一個重啟動位
168 1 delay();
169 1 device_addr=Device_Addr; //EEROM的地址
170 1 for(i=0;i<7;i++) //輸出設備地址,一個7位的地址
171 1 {
172 2 SCL=0;
173 2 delay();
174 2 SDA=device_addr&0x80; //SDA上輸出一位數據,高位在前
175 2 device_addr<<=1;
176 2 delay();
177 2 SCL=1;
178 2 delay();
C51 COMPILER V7.06 2401 03/02/2006 23:49:39 PAGE 4
179 2 }
180 1 SCL=0;
181 1 delay();
182 1 SDA=1; //SDA上輸出1,表示讀操作
183 1 delay();
184 1 SCL=1;
185 1 delay();
186 1 SCL=0;
187 1 delay();
188 1 SDA=1; //釋放SDA線
189 1 delay();
190 1 SCL=1;
191 1 delay();
192 1 if(SDA) return 0x0300; //如果設備未響應,則返回出錯代碼0x0300
193 1 for(i=0;i<8;i++) //從EEROM中讀出數據
194 1 {
195 2 SCL=0;
196 2 delay();
197 2 r_data<<=1;
198 2 delay();
199 2 SCL=1;
200 2 if(SDA)r_data=r_data|0x01; //保存一位數據
201 2 delay();
202 2 }
203 1 SCL=0;
204 1 delay();
205 1 SDA=1; //置SDA高電平,表示停止讀出
206 1 delay();
207 1 SCL=1;
208 1 delay();
209 1 SCL=0;
210 1 delay();
211 1 SDA=0;
212 1 delay();
213 1 SCL=1;
214 1 delay();
215 1 SDA=1; //產生一個停止位,停止讀操作
216 1 return r_data; //返回數據
217 1 }
218 //****************************************************************************************
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 361 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 2
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -