📄 x.lst
字号:
C51 COMPILER V7.50 X 08/20/2006 14:48:06 PAGE 1
C51 COMPILER V7.50, COMPILATION OF MODULE X
OBJECT MODULE PLACED IN X.OBJ
COMPILER INVOKED BY: E:\Program Files\keil\C51\BIN\C51.EXE X.C BROWSE DEBUG OBJECTEXTEND
line level source
1 //2003.3.12
2 //write by sunny
3 //03.4.23 rewrite by sunny
4 #include "main.h"
5 #include "X.h"
6
7 #define CS25045 P16
8 #define CLK25045 P17
9 #define I25045 P35
10 #define O25045 P34
11 #define WREN_INST 0x06
12 #define WRDI_INST 0x04
13 #define WRSR_INST 0x01
14 #define RDSR_INST 0x05
15 #define WRITE_INST 0x02
16 #define READ_INST 0x03
17 #define STATUS_REG 0x30 //watch dog = 1ms
18 #define INIT_STATE 0x09
19 #define MAX_POLL 0x99
20 #define SLIC 0x30
21
22 #define HIGH 1
23 #define LOW 0
24
25 //user's functions:
26 //set wotch dog time
27 void SetWatchDog()
28 {
29 1 Write25045StatusRigester(STATUS_REG);
30 1 }
31 //feed watch Dog
32 void FeedDog()
33 {
34 1 CS25045 = LOW;
35 1 CS25045 = HIGH;
36 1 }
37
38 ////////////////////////////////////////////////////////////
39 //internal use fuctions:
40 //send a byte to 25045
41 void OutByte25045(unsigned char outbyte)
42 {
43 1 unsigned char temp;
44 1 for(temp = 0; temp <8; temp ++)
45 1 {
46 2 CLK25045 = LOW;
47 2 I25045 = (bit)(outbyte & 0x80);
48 2 CLK25045 = HIGH;
49 2 outbyte = outbyte<<1;
50 2 }
51 1 I25045 = LOW;
52 1 }
53 //received a byte from 25045
54 unsigned char InByte25045()
55 {
C51 COMPILER V7.50 X 08/20/2006 14:48:06 PAGE 2
56 1 unsigned char received = 0x00;
57 1 unsigned char temp;
58 1 for(temp = 0; temp <8; temp ++)
59 1 {
60 2 CLK25045 = HIGH;
61 2 CLK25045 = LOW;
62 2 received = received <<1;
63 2 O25045 = HIGH;
64 2 received += (unsigned char)O25045;
65 2 }
66 1 return received ;
67 1
68 1 }
69 //set 25045 write enable
70 void Set25045WriteEnable()
71 {
72 1 CLK25045 = LOW;
73 1 CS25045 = LOW;
74 1 OutByte25045(WREN_INST);
75 1 CLK25045 = LOW;
76 1 CS25045 = HIGH;
77 1 }
78 //set 25045 write disable
79 void Reset25045WriteEnable()
80 {
81 1 CLK25045 = LOW;
82 1 CS25045 = LOW;
83 1 OutByte25045(WRDI_INST);
84 1 CLK25045 = LOW;
85 1 CS25045 = HIGH;
86 1
87 1 }
88 //write 25045 status rigester
89 void Write25045StatusRigester(unsigned char reg)
90 {
91 1 Set25045WriteEnable();
92 1
93 1 CLK25045 = LOW;
94 1 CS25045 = LOW;
95 1 OutByte25045(WRSR_INST);
96 1 OutByte25045( reg);
97 1 CLK25045 = LOW;
98 1 CS25045 = HIGH;
99 1 WipPoll25045();
100 1
101 1 Reset25045WriteEnable();
102 1 }
103 //read 25045 status rigester
104 unsigned char Read25045StatusRigester()
105 {
106 1 unsigned char statusrigester;
107 1 CLK25045 = LOW;
108 1 CS25045 = LOW;
109 1 OutByte25045(RDSR_INST);
110 1 statusrigester = InByte25045();
111 1 CLK25045 = LOW;
112 1 CS25045 = HIGH;
113 1 return statusrigester;
114 1 }
115
116 //write byte to 25045; 0<=address<=1ff
117 void ByteWrite25045EEROM(unsigned char writebyte,unsigned int address)
C51 COMPILER V7.50 X 08/20/2006 14:48:06 PAGE 3
118 {
119 1 unsigned char temp = WRITE_INST;
120 1 Set25045WriteEnable();
121 1
122 1 CLK25045 = LOW;
123 1 CS25045 = LOW;
124 1 if(address >= 0x100)
125 1 temp = temp | 0x03;
126 1 OutByte25045(temp);
127 1 OutByte25045((unsigned char)address);
128 1 OutByte25045(writebyte);
129 1 CLK25045 = LOW;
130 1 CS25045 = HIGH;
131 1 WipPoll25045();
132 1
133 1 Reset25045WriteEnable();
134 1
135 1 }
136
137 unsigned char ByteRead25045EEROM(unsigned int address)
138 {
139 1 unsigned char readbyte;
140 1 unsigned char temp = READ_INST;
141 1 CLK25045 = LOW;
142 1 CS25045 = LOW;
143 1 if(address >= 0x100)
144 1 temp = temp | 0x03;
145 1 OutByte25045(temp);
146 1 OutByte25045((unsigned char)address);
147 1 readbyte = InByte25045();
148 1 CLK25045 = LOW;
149 1 CS25045 = HIGH;
150 1 return readbyte;
151 1 }
152
153 //wait for write complete;
154 void WipPoll25045()
155 {
156 1 unsigned char temp = MAX_POLL;
157 1 unsigned char statusregister = 0x00;
158 1 while (temp >1)
159 1 {
160 2 temp --;
161 2 statusregister = Read25045StatusRigester();
162 2 if (statusregister&0x01 == 0x00)
163 2 temp = 0x01;//out loop
164 2 }
165 1 }
166
167 //write page 2byte to 25045; 0<=address<=1ff,高字节在高位
168 unsigned char DataWrite25045EEROM(unsigned int writedata,unsigned int address)
169 {
170 1 unsigned char temp = WRITE_INST;
171 1 if(address >0x1FF )
172 1 return FALSE;
173 1 Set25045WriteEnable();
174 1 CLK25045 = LOW;
175 1 CS25045 = LOW;
176 1 if(address >= 0x100)
177 1 temp = temp | 0x03;
178 1 OutByte25045(temp);
179 1 OutByte25045((unsigned char)address);
C51 COMPILER V7.50 X 08/20/2006 14:48:06 PAGE 4
180 1 OutByte25045((unsigned char)writedata);
181 1 OutByte25045((unsigned char)(writedata>>8));
182 1 CLK25045 = LOW;
183 1 CS25045 = HIGH;
184 1 WipPoll25045();
185 1 Reset25045WriteEnable();
186 1 return TRUE;
187 1 }
188 unsigned int DataRead25045EEROM(unsigned int address)
189 {
190 1 unsigned char temp = READ_INST;
191 1 unsigned int temp1;
192 1 if(address >0x1FF )
193 1 return FALSE;
194 1 CLK25045 = LOW;
195 1 CS25045 = LOW;
196 1 if(address >= 0x100)
197 1 temp = temp | 0x03;
198 1 OutByte25045(temp);
199 1 OutByte25045((unsigned char)address);
200 1 temp = InByte25045();
201 1 temp1 = InByte25045();
202 1 temp1 = (temp1<<8)+temp;
203 1 CLK25045 = LOW;
204 1 CS25045 = HIGH;
205 1 return temp1;
206 1 }
207
208
209 //write page /4byte to 25045; 0<=address<=1ff
210 unsigned char PageWrite25045EEROM(unsigned int address,unsigned char *writeByteArray)
211 {
212 1 unsigned char temp = WRITE_INST;
213 1 if(address >0x1FF )
214 1 return FALSE;
215 1 Set25045WriteEnable();
216 1 CLK25045 = LOW;
217 1 CS25045 = LOW;
218 1 if(address >= 0x100)
219 1 temp = temp | 0x03;
220 1 OutByte25045(temp);
221 1 OutByte25045((unsigned char)address);
222 1 OutByte25045(*writeByteArray);
223 1 OutByte25045(*(writeByteArray+1));
224 1 OutByte25045(*(writeByteArray+2));
225 1 OutByte25045(*(writeByteArray+3));
226 1 CLK25045 = LOW;
227 1 CS25045 = HIGH;
228 1 WipPoll25045();
229 1 Reset25045WriteEnable();
230 1 return TRUE;
231 1 }
232
233 //read page /4byte to 25045; 0<=address<=1ff
234 unsigned char PageRead25045EEROM(unsigned int address,unsigned char *readByteArray)
235 {
236 1 unsigned char temp = READ_INST;
237 1 if(address >0x1FF )
238 1 return FALSE;
239 1 CLK25045 = LOW;
240 1 CS25045 = LOW;
241 1 if(address >= 0x100)
C51 COMPILER V7.50 X 08/20/2006 14:48:06 PAGE 5
242 1 temp = temp | 0x03;
243 1 OutByte25045(temp);
244 1 OutByte25045((unsigned char)address);
245 1 *(readByteArray) = InByte25045();
246 1 *(readByteArray+1) = InByte25045();
247 1 *(readByteArray+2) = InByte25045();
248 1 *(readByteArray+3) = InByte25045();
249 1 CLK25045 = LOW;
250 1 CS25045 = HIGH;
251 1 return TRUE;
252 1 }
253
254
255 //write data to 25045
256 void Write25045EEROM(unsigned int address,unsigned char *writeArray,unsigned char num)
257 {
258 1 unsigned char tempaddress = 0x00;
259 1 while ( num > 0 )
260 1 {
261 2 if ( num <= 4 )
262 2 num = 0;
263 2 else num -=4;
264 2 PageWrite25045EEROM(address+tempaddress*4,(writeArray+tempaddress*4));
265 2 tempaddress++;
266 2 }
267 1 }
268
269 //read data from 25045
270 void Read25045EEROM(unsigned int address,unsigned char *readArray,unsigned char num)
271 {
272 1 unsigned char biasaddress = 0x00;
273 1 while ( num > 0 )
274 1 {
275 2 if ( num <= 4 )
276 2 num = 0;
277 2 else num -=4;
278 2 PageRead25045EEROM(address+biasaddress*4,(readArray+biasaddress*4));
279 2 biasaddress++;
280 2 }
281 1 }
282
283
284
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 632 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 15
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 + -