; Attempt to erase an 8k block of the 39F512 Flash ROM ; chip on the 8051 development board, from ; http://www.pjrc.com/tech/8051/board3/board_image.html ; This code is in the the public domain. It is distributed in ; the hope that it will be useful, but without any warranty; ; without even the implied warranty of merchantability or fitness ; for a particular purpose. .equ locat, 0xF600 ;Location for this program .equ cout, 0x0030 .equ cin, 0x0032 ;get byte from uart .equ phex, 0x0034 .equ pstr, 0x0038 ;print string @dptr .equ newline, 0x0048 .org locat .db 0xA5,0xE5,0xE0,0xA5 ;signiture .db 35,255,0,0 ;id (35=normal prog) .db 0,0,0,0 ;prompt code vector .dB 0,0,0,0 ;reserved .db 0,0,0,0 ;reserved .db 0,0,0,0 ;reserved .db 0,0,0,0 ;user defined .db 255,255,255,255 ;length and checksum (255=unused) .db "Checksum Memory",0 .org locat+64 ;executable code begins here ;using a couple bytes of internal ram .equ flags, 0x20 .equ range_end, 0x21 .equ stack, 0x40 ; bits withing "flags" .equ do_both_movx_and_movc, 0 .equ do_movc_only, 1 .equ do_movx_only, 2 ;direct access to registers .equ reg6, 6 .equ reg7, 7 start: mov sp, #stack mov psw, #0 mov dptr, #msg_0 lcall pstr ;PAULMON2 Code (0000-1FFF) mov dptr, #msg_1 lcall pstr mov dptr, #0x0000 mov range_end, #0x20 mov flags, #0 setb do_movc_only acall cksum ;Data Only RAM (0000-1FFF) mov dptr, #msg_2 lcall pstr mov dptr, #0x0000 mov range_end, #0x20 mov flags, #0 setb do_movx_only acall cksum ;Data & Code RAM (2000-7FFF) mov dptr, #msg_3 lcall pstr mov dptr, #0x2000 mov range_end, #0x80 mov flags, #0 setb do_both_movx_and_movc acall cksum ;Flash ROM (8000-EFFF) mov dptr, #msg_4 lcall pstr mov dptr, #0x8000 mov range_end, #0xF0 ;mov flags, #0 ;reuse from last one ;setb do_both_movx_and_movc acall cksum ;Demo Programs (F000-F7FF) mov dptr, #msg_5 lcall pstr mov dptr, #0xF000 mov range_end, #0xF8 ;mov flags, #0 ;reuse from last one ;setb do_both_movx_and_movc acall cksum done: mov dptr, #mesgany lcall pstr lcall cin ljmp 0 cksum: mov r2, #0 mov r3, #0 mov r4, #0 mov r6, #255 mov r7, #255 cksum_loop: jb do_both_movx_and_movc, cksum_both jb do_movc_only, cksum_movc_only cksum_movx_only: movx a, @dptr sjmp cksum_add cksum_movc_only: clr a movc a, @a+dptr sjmp cksum_add cksum_both: movx a, @dptr mov b, a clr a movc a, @a+dptr cjne a, b, error cksum_add: xrl reg6, a ;xor into crc early add a, r2 mov r2, a clr a addc a, r3 mov r3, a clr a addc a, r4 mov r4, a compute_crc: mov r5, #8 compute_crc_loop: clr c mov a, r7 rrc a mov r7, a mov a, r6 rrc a mov r6, a jnc compute_crc_skip_xor xrl reg6, #0x01 xrl reg7, #0xA0 compute_crc_skip_xor: djnz r5, compute_crc_loop inc dptr mov a, dph cjne a, range_end, cksum_loop print_cksum: mov dptr, #msg_sum lcall pstr mov a, r4 lcall phex mov a, r3 lcall phex mov a, r2 lcall phex mov a, #'/' lcall cout mov a, r7 lcall phex mov a, r6 lcall phex ljmp newline error: mov dptr, #msg_err ljmp pstr msg_0: .db "Memory Checksum Utility",13,10,0 msg_1: .db " PAULMON2 Code (0000-1FFF):",0 msg_2: .db " Data Only RAM (0000-1FFF):",0 msg_3: .db " Data & Code RAM (2000-7FFF):",0 msg_4: .db " Flash ROM (8000-EFFF):",0 msg_5: .db " Demo Programs (F000-F7FF):",0 msg_sum:.db " Checksum = ",0 msg_err:.db " Hardware Error!!", 13, 10, 0 mesgany:.db "Press any key", 0