📄 myextra.asm
字号:
CLR P1.0
DJNZ R7,read_bit
RET
;
; Send an ACK to the remote
;
ICack: CLR P3.4 ; Zero DATA
SETB P1.0 ; Raise CLOCK
NOP
NOP
NOP
NOP
CLR P1.0 ; Lower CLOCK
SETB P3.4 ; Release DATA
RET
; Send the STOP condition to the remote
;
ICstop: CLR P3.4 ;Zero DATA
SETB P1.0 ;Raise CLOCK
NOP
NOP
NOP
NOP
NOP
SETB P3.4 ;Raise DATA
RET
; Write complete polling
; exit when complete
complete_poll:
ACALL ICstrt
MOV A,#device_addressWR
ACALL ICsend
JC complete_poll
ret
.equ device_addressWR, 0xA0
.equ device_addressRD, 0xA1
; Read byte from EEPROM
; Entry: DPTR holds address to be accessed
; Exit: ACC
;
eeread: ACALL ICstrt ; Start transfer
MOV A,#device_addressWR
ACALL ICsend ; Write
MOV A,DPH
ACALL ICsend
MOV A,DPL
ACALL ICsend
acall ICstrt
mov a,#device_addressRD
acall ICsend
ACALL ICread ; Get data byte
acall ICstop
ret
; Write byte to eeprom
; Entry: DPTR address to be written
; ACC byte to be written
;
eewrite: mov b,a
acall ICstrt
mov a,#device_addressWR
acall ICsend
mov a,dph
acall ICsend
mov a,dpl
acall ICsend
mov a,b
acall ICsend
acall ICstop
acall complete_poll
ret
; hex dump from external eeprom address 0000H-7FFFH
; DPTR: start address to be displayed
eeprom_dump:
mov dptr,#read_location
lcall pstr
lcall ghex16
lcall newline
mov r2, #16 ;number of lines to print
eedump1: lcall newline
lcall phex16 ;tell 'em the memory location
mov a,#' '
lcall cout
mov r3, #16 ;r3 counts # of bytes to print
eedump2: acall eeread
inc dptr
lcall phex ;print each byte in hex
mov a,#' '
lcall cout
djnz r3,eedump2
djnz r2,eedump1
lcall newline
ret
read_location: .db 13,10,"eeprom address [0000-7FFF] > ",0
; increment ptr
; entry: r0
inc_ptr:
mov a,#1
add a,@r0
mov @r0,a
inc r0
mov a,#0
addc a,@r0
mov @r0,a
ret
; get DPTR
get_dptr:
mov a,@r0
mov dpl,a
inc r0
mov a,@r0
mov dph,a
ret
; save program
; save code from 8000H to eeprom
; the number of byte to be saved was input by user
;
; test with 9000H.....
;
; eeprom address content
; 0000H start address low
; 0001H start address high
; 0002H number of byte low
; 0003H number of byte high
; 0004H XX reserved for future
; 0005H XX
; ..... ..
; 0010H first byte
; 0011H ..
; 7FFFH nn
.equ ptr2,0xFC ; 16-bit eeprom address pointer
.equ ptr1,0xFE ; 16-bit SRAM address pointer
save_pgm:
mov dptr,#save
lcall pstr
lcall ghex16
jnc no_esc1
ret
no_esc1:
mov a,dpl
mov r2,dph
push dph
push dpl
mov dptr,#0
acall eewrite
mov dptr,#1
mov a,r2
acall eewrite ; save start address to 0000-0001
pop dpl
pop dph
mov r0,#ptr1
mov a,dpl
mov @r0,a
inc r0
mov a,dph
mov @r0,a
mov dptr,#save2
lcall pstr
lcall getnum ; get number of byte to be saved
cpl a
mov dpl,a
mov a,b
cpl a
mov dph,a
inc dptr ; got two's complement of number of bytes
lcall newline
push dph
push dpl
mov a,dpl
mov r2,dph
mov dptr,#2
acall eewrite
mov dptr,#3
mov a,r2
acall eewrite ; save number of byte to 0002-0003
pop dpl
pop dph
mov r0,#ptr2
mov a,#0x10
mov @r0,a ; eeprom start address is 0010H
inc r0
mov a,#0
mov @r0,a
loop_write:
push dph
push dpl
;-----------------------
mov r0,#ptr1
acall get_dptr
movx a,@dptr ; read from 32K SRAM
mov r3,a ; save to r3
mov r0,#ptr2
acall get_dptr
mov a,r3
acall eewrite ; save to eeprom
mov r0,#ptr1
acall inc_ptr ; next source
mov r0,#ptr2
acall inc_ptr ; next destination
;----------------------
pop dpl
pop dph
mov a,#13
lcall cout
lcall pint16u
inc dptr
mov a,dph
orl a,dpl
jnz loop_write
mov dptr,#done2
lcall pstr
ret
save: .db 13,10,"Save Program start address> ",0
save2: .db 13,10,"Number of bytes [0-32768] > ",0
save3: .db 13,10,"Saving...",0
done2: .db 13,"Done..",0
;=========================================================================
; load program from eeprom, write to RAM and jump to start address in SRAM
boot_eeprom:
mov dptr,#loading
lcall pstr
; get start address from eeprom 0000H and 0001H save to ptr1
mov dptr,#0
acall eeread
mov r0,#ptr1
mov @r0,a
mov dptr,#1
acall eeread
mov r0,#ptr1+1
mov @r0,a
; initialize address counter for eeprom to ptr2
mov a,#0x10
mov r0,#ptr2
mov @r0,a
inc r0
mov a,#0
mov @r0,a
; get number of byte from eeprom 0002H-0003H
mov dptr,#2
acall eeread
mov r2,a ; save acc
mov dptr,#3
acall eeread
mov dph,a
mov dpl,r2
loop_read:
push dph ; save counter
push dpl
;========loop body=====================
mov r0,#ptr2
acall get_dptr ; get eeprom address
acall eeread
mov r3,a ; save to r3
mov r0,#ptr1
acall get_dptr
mov a,r3
movx @dptr,a ; write to SRAM
mov r0,#ptr1
acall inc_ptr ; next destination
mov r0,#ptr2
acall inc_ptr ; next source
;----------------------------------------
pop dpl
pop dph
inc dptr
mov a,dph
orl a,dpl
jnz loop_read
mov dptr,#0
acall eeread
mov r2,a
mov dptr,#1
acall eeread
mov dph,a
mov dpl,r2
; call phex16
push dpl
push dph
ret ; run application program
loading: .db 13,10,"Loading...",0
;---------------------------------------------------------;
; ;
; single step strings ;
; ;
;---------------------------------------------------------;
prompt4:.db "), or <ESC> to exit: ",0
prompt8:.db 13,31,136,128,131,129," (",0
abort: .db " Command Aborted.",13,10,0
sserr1: .db 13,161,197," connect INT1 (pin 13) low"
.db 128,186,207,204,13,0
sserr2: .db 148,"2",179,199,174,129," 0013",13,0
sserr3: .db 31,184,179,255,165," vector",174," ",0
ssmsg: .db 13,"Now",134,"ning",166,207,204," mode: "
.db "<RET>=",204,", ?= Help",13,13,0
sskip1: .db "Skipping Instruction-> ",0
ssdmps1:.db 13,10,"Loc: Int RAM Memory Contents",13,10,0
chaccs1:.db "New Acc Value: ",0
help5txt:.db 13
.db 31,207,31,204,31,158,":",13
.db "<RET> ",134,212,246,13
.db " <SP> ",134,212,246,13
.db " '?' ",255,142,215,13
.db " '.' ",255,196,253,"s",13
.db " 'R' ",255," special function",196,"s",13
.db " 'H' ",132,219,192,146,13
.db " 'S' ",252,212,246,13
.db " 'A' ",240,162," Acc value",13
.db " 'Q' ",200,207,204,13,14
squit: .db "Quit",13,10,0
ssnames:.db " ACC B C DPTR R0 R1 R2 R3 R4 R5 R6 R7 SP"
.db " Addr Instruction",13,10,0
;---------------------------------------------------------;
; ;
; disassembler data ;
; ;
;---------------------------------------------------------;
mnu_tbl:.db "ACAL",'L'+128
.db 0
.db "AD",'D'+128
.db 0
.db "ADD",'C'+128
.db "AJM",'P'+128
.db "AN",'L'+128
.db "CJN",'E'+128
.db "CL",'R'+128
.db "CP",'L'+128
.db "D",'A'+128
.db "DE",'C'+128
.db "DI",'V'+128
.db "DJN",'Z'+128
.db "IN",'C'+128
.db "J",'B'+128
.db "JB",'C'+128
.db "J",'C'+128
.db "JM",'P'+128
.db "JN",'B'+128
.db "JN",'C'+128
.db "JN",'Z'+128
.db "J",'Z'+128
.db "LCAL",'L'+128
.db "LJM",'P'+128
.db "MO",'V'+128
.db "MOV",'C'+128
.db "MOV",'X'+128
.db "MU",'L'+128
.db "NO",'P'+128
.db "OR",'L'+128
.db "PO",'P'+128
.db "PUS",'H'+128
.db "RE",'T'+128
.db "RET",'I'+128
.db "R",'L'+128
.db "RL",'C'+128
.db "R",'R'+128
.db "RR",'C'+128
.db "SET",'B'+128
.db "SJM",'P'+128
.db "SUB",'B'+128
.db "SWA",'P'+128
.db "XC",'H'+128
.db "XCH",'D'+128
.db "XR",'L'+128
.db "??",'?'+128
bitmnu: .db 'P','0'+128
.db "TCO",'N'+128
.db 'P','1'+128
.db "SCO",'N'+128
.db 'P','2'+128
.db 'I','E'+128
.db 'P','3'+128
.db 'I','P'+128
.db 'C','0'+128
.db "T2CO",'N'+128
.db "PS",'W'+128
.db 'D','8'+128
.db "AC",'C'+128
.db 'E'+'8'+128
.db 'B'+128
.db 'F'+'8'+128
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -