📄 at25cxx.lst
字号:
190 ; call enable_write ; must precede each byte write
191
192 ; call disable_write ; cancel write enable (disable writes)
193
194 ; mov a, #FILL ; data
195 ; mov dptr, #123h ; address
196 ; call write_byte ; write
197 ; yyy:
198 ; call read_status ; check write status
199 ; jb NRDY, yyy ; loop until ready
200
201 ; mov dptr, #123h ; address
202 ; call read_byte ; read
203 ; cjne a, #FILL, fault ; jump on compare error
204
205
206 ; Write and verify one byte using COMMANDER.
207
208 ; mov a, #WREN ; must precede each byte write
209 ; call commander
210
211 ; mov a, #WRDI ; cancel write enable (disable writes)
212 ; call commander
213
214 ; mov zdata, #FILL ; data
215 ; mov addr_lo, #23h ; address
MCS-51 MACRO ASSEMBLER CONTROL_AT25XXX 02/06/96 PAGE 5
LOC OBJ LINE SOURCE
216 ; mov addr_hi, #01h ;
217 ; mov a, #WRITE
218 ; call commander
219 ; yyy:
220 ; mov a, #RDSR ; check write status
221 ; call commander
222 ; mov a, zdata ; get status
223 ; jb NRDY, yyy ; loop until ready
224
225 ; mov zdata, #FILL ; data
226 ; mov addr_lo, #23h ; address
227 ; mov addr_hi, #01h ;
228 ; mov a, #READ
229 ; call commander
230 ; cjne zdata, #FILL, fault ; jump on compare error
231
232 ; fault:
233 ; jmp $
234
235
236 byte_fill:
237
238 ; Write every byte in an AT25xxx with the same fill value.
239 ; Writes one address at a time (page mode is not used).
240 ; Waits until previous write cycle is complete before starting next.
241 ; Does not wait for last write cycle to complete before returning.
242 ; Memory write must be re-enabled after each write cycle.
243 ; Returns nothing. Destroys A, DPTR.
244
008B 900000 245 mov dptr, #0 ; initialize address pointer
246 x11:
008E 120113 247 call read_status ; get status in A
0091 20E0FA 248 jb NRDY, x11 ; loop until ready
249
0094 120134 250 call enable_write ; enable memory write
251
0097 7455 252 mov a, #FILL ; get fill value
0099 120165 253 call write_byte ; write data
254
009C A3 255 inc dptr ; advance address pointer
256 ; mov a, dpl ; check low byte
257 ; cjne a, #(LOW SIZE), x11 ; jump if not last
009D E583 258 mov a, dph ; check high byte
009F B402EC 259 cjne a, #(HIGH SIZE), x11 ; jump if not last
00A2 22 260 ret
261
262
263 verify_byte_fill:
264
265 ; Verify that all bytes in an AT25xxx match a fill value.
266 ; Reads and verifies one byte at a time (page mode is not used).
267 ; Waits for device ready before beginning compare.
268 ; Returns CY set to indicate compare fail.
269 ; Destroys A, DPTR.
270
MCS-51 MACRO ASSEMBLER CONTROL_AT25XXX 02/06/96 PAGE 6
LOC OBJ LINE SOURCE
271 x21:
00A3 120113 272 call read_status ; get status in A
00A6 20E0FA 273 jb NRDY, x21 ; loop until ready
274
00A9 900000 275 mov dptr, #0 ; initialize address pointer
276 x22:
00AC 12014E 277 call read_byte ; get data in A
00AF B4550A 278 cjne a, #FILL, x23 ; jump if compare error
279
00B2 A3 280 inc dptr ; advance address pointer
281 ; mov a, dpl ; check low byte
282 ; cjne a, #(LOW SIZE), x22 ; jump if not last
00B3 E583 283 mov a, dph ; check high byte
00B5 B402F4 284 cjne a, #(HIGH SIZE), x22 ; jump if not last
00B8 C3 285 clr c ; clear error flag
00B9 0200BD 286 jmp x24 ; exit
287 x23:
00BC D3 288 setb c ; set error flag
289 x24:
00BD 22 290 ret
291
292
293 page_fill:
294
295 ; Write every byte in an AT25xxx with the same fill value.
296 ; Writes one page at a time.
297 ; Waits until previous write cycle is complete before starting next.
298 ; Does not wait for last write cycle to complete before returning.
299 ; Memory write must be re-enabled after each write cycle.
300 ; Returns nothing. Destroys A, B, DPTR, KOUNT.
301
302 ; First fill buffer.
303
00BE 75F008 304 mov b, #PSIZE ; bytes per page
00C1 7820 305 mov index, #buffer ; point to buffer
306 x31:
00C3 7655 307 mov @index, #FILL ; put fill value in buffer
00C5 08 308 inc index ; advance pointer
00C6 D5F0FA 309 djnz b, x31 ; next byte
310
311 ; Copy buffer to device, one page at a time.
312
00C9 7F40 313 mov kount, #NPAGES ; initialize page counter
00CB 900000 314 mov dptr, #0 ; initialize address pointer
315 x32:
00CE 120113 316 call read_status ; get status in A
00D1 20E0FA 317 jb NRDY, x32 ; loop until ready
318
00D4 120134 319 call enable_write ; enable memory write
320
00D7 1201A8 321 call write_page ; write data from buffer into device
322
323 ; Add page size to address pointer.
324
00DA E582 325 mov a, dpl ; get low byte
MCS-51 MACRO ASSEMBLER CONTROL_AT25XXX 02/06/96 PAGE 7
LOC OBJ LINE SOURCE
00DC 2408 326 add a, #PSIZE ; add page size
00DE F582 327 mov dpl, a ; save low byte
00E0 5002 328 jnc x33 ; jump if high byte not affected
00E2 0583 329 inc dph ; increment high byte
330 x33:
00E4 DFE8 331 djnz kount, x32 ; next page
00E6 22 332 ret
333
334
335 verify_page_fill:
336
337 ; Verify that all bytes in an AT25xxx match a fill value.
338 ; Reads and verifies one page at a time.
339 ; Waits for device ready before beginning compare.
340 ; Returns CY set to indicate compare fail.
341 ; Destroys A, B, DPTR, INDEX, KOUNT.
342
343 x41:
00E7 120113 344 call read_status ; get status in A
00EA 20E0FA 345 jb NRDY, x41 ; loop until ready
346
347 ; Copy device page to buffer.
348
00ED 7F40 349 mov kount, #NPAGES ; initialize page counter
00EF 900000 350 mov dptr, #0 ; initialize address pointer
351 x42:
00F2 120183 352 call read_page ; read data from device into buffer
353
354 ; Verify buffer contents.
355
00F5 75F008 356 mov b, #PSIZE ; bytes per page
00F8 7820 357 mov index, #buffer ; point to buffer
358 x43:
00FA B65514 359 cjne @index, #FILL, x45 ; jump if compare fails
00FD 08 360 inc index ; advance pointer
00FE D5F0F9 361 djnz b, x43 ; next byte
362
363 ; Add page size to address pointer.
364
0101 E582 365 mov a, dpl ; get low byte
0103 2408 366 add a, #PSIZE ; add page size
0105 F582 367 mov dpl, a ; save low byte
0107 5002 368 jnc x44 ; jump if high byte not affected
0109 0583 369 inc dph ; increment high byte
370 x44:
010B DFE5 371 djnz kount, x42 ; next page
010D C3 372 clr c ; clear error flag
010E 020112 373 jmp x46 ; exit
374 x45:
0111 D3 375 setb c ; set error flag
376 x46:
0112 22 377 ret
378
379
380 read_status:
MCS-51 MACRO ASSEMBLER CONTROL_AT25XXX 02/06/96 PAGE 8
LOC OBJ LINE SOURCE
381
382 ; Read device status.
383 ; Returns status byte in A.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -