既然来了ISP,咱就来个更猛的,串口ISP 的sourcde code
ORG 00000H
SJMP L0002
L0002:
MOV SP,#50H
MOV 20H,#00H
MOV P3,#0FFH
ACALL L0024
JNB 20H.0,IspMain
ResetToApp:
MOV IFMT,#00H
MOV ISPCR,#20H
SJMP $
IspMain:
ACALL L0036
CLR TR0
CLR TF0
CLR TI
CLR RI
AJMP CheckID
L0024:
MOV P3,#0FFH
MOV R0,#26H
L0029:
JB RXD,L0033
NOP
DJNZ R0,L0029
MOV Var48,#44H
RET
L0033:
SETB 20H.0
RET
L0036:
MOV TMOD,#12H
MOV R2,#16H
L003B:
MOV Var37,#00H
MOV Var31,#77H
MOV R7,#55H
ACALL SendByte
JB RXD,L004E
ACALL L036A
DJNZ R2,L003B
SJMP ResetToApp
L004E:
MOV R0,#0AH
L0050:
CLR TR0
MOV TMOD,#11H
MOV TH0,#00H
MOV TL0,#00H
CLR TF0
JB RXD,$
JNB RXD,$
SETB TR0
JB RXD,$
JNB RXD,$
CLR TR0
MOV R7,#02H
L006F:
CLR C
MOV A,TH0
RRC A
MOV TH0,A
MOV A,TL0
RRC A
MOV TL0,A
DJNZ R7,L006F
CLR C
MOV A,#00H
SUBB A,TL0
MOV Var31,A
MOV Var37,TH0
MOV A,Var37
JNZ L0094
MOV 36H,#00H
MOV A,TL0
CLR C
SUBB A,#08H
JC L00AA
L0094:
CLR C
MOV A,TH0
RRC A
MOV 36H,A
MOV A,TL0
RRC A
MOV 30H,A
JZ L00AA
CLR C
MOV A,#00H
SUBB A,30H
MOV 30H,A
SJMP L00AD
L00AA:
MOV 30H,#0FEH
L00AD:
MOV TMOD,#12H
MOV A,Var37
JZ L00C4
MOV TH0,#00H
MOV TL0,#00H
CLR TF0
SETB TR0
MOV R7,#10H
L00C0:
ACALL L01FD
DJNZ R7,L00C0
L00C4:
MOV TH0,Var31
MOV TL0,Var31
CLR TF0
SETB TR0
MOV R7,#16H
L00D0:
JNB TF0,$
CLR TF0
DJNZ R7,L00D0
CLR TR0
MOV R7,#55H
ACALL SendByte
MOV R7,#0AAH
ACALL SendByte
MOV R7,#00H
ACALL SendByte
MOV R7,#0FFH
ACALL SendByte
MOV R7,#11H
ACALL SendByte
MOV R7,Var37
ACALL SendByte
MOV R7,Var31
ACALL SendByte
MOV IFADRL,#01H
MOV R7,SCMD
MOV DevIDH,R7
ACALL SendByte
MOV IFADRL,#00H
MOV R7,SCMD
MOV DevIDL,R7
ACALL SendByte
ACALL RecvByte
CJNE R7,#55H,L0124
MOV 49H,#4FH
ACALL RecvByte
CJNE R7,#0AAH,L0126
MOV 4AH,#5FH
ACALL L036A
MOV 4BH,#49H
MOV R7,#ACK
ACALL SendByte
MOV 4CH,#53H
RET
L0124:
ACALL RecvByte
L0126:
DJNZ R0,L012A
AJMP ResetToApp
L012A:
AJMP L0050
RecvByte:
MOV A,Var37
JNZ L015C
MOV R7,#08H
CLR TR0
MOV TH0,Var31
MOV TL0,30H
CLR TF0
JB RXD,$
SETB TR0
JNB TF0,$
CLR TF0
L0146:
JNB TF0,$
MOV C,RXD
CLR TF0
RRC A
DJNZ R7,L0146
JNB TF0,$
CLR TF0
CLR TR0
JNB RXD,$
MOV R7,A
RET
L015C:
MOV R7,#08H
CLR TR0
CLR TF0
MOV TH0,#00H
MOV TL0,#00H
JB RXD,$
SETB TR0
MOV A,36H
JZ L0179
MOV R4,A
L0172:
JNB TF0,$
CLR TF0
DJNZ R4,L0172
L0179:
MOV TL0,30H
JNB TF0,$
CLR TF0
L0181:
MOV R4,Var37
L0183:
JNB TF0,$
CLR TF0
DJNZ R4,L0183
MOV TL0,Var31
JNB TF0,$
MOV C,RXD
CLR TF0
RRC A
DJNZ R7,L0181
JNB TF0,$
CLR TF0
CLR TR0
JNB RXD,$
MOV R7,A
RET
SendByte:
MOV A,Var37
JNZ L01DD
MOV A,R7
MOV R7,#09H
MOV TH0,Var31
MOV TL0,Var31
CLR TF0
CLR C
SETB TR0
L01B5:
MOV TXD,C
RRC A
JNB TF0,$
CLR TF0
DJNZ R7,L01B5
SETB TXD
JNB TF0,$
CLR TF0
JNB TF0,$
CLR TF0
JNB TF0,$
CLR TF0
JNB TF0,$
CLR TF0
JNB TF0,$
CLR TF0
CLR TR0
RET
L01DD:
MOV A,R7
MOV R7,#09H
MOV TH0,#00H
MOV TL0,#00H
CLR TF0
CLR C
SETB TR0
L01EB:
MOV TXD,C
RRC A
ACALL L01FD
DJNZ R7,L01EB
SETB TXD
MOV R7,#05H
L01F6:
ACALL L01FD
DJNZ R7,L01F6
CLR TR0
RET
L01FD:
MOV R4,Var37
L01FF:
JNB TF0,$
CLR TF0
DJNZ R4,L01FF
MOV TL0,Var31
JNB TF0,$
CLR TF0
RET
CheckID:
MOV 4DH,#50H
MOV R5,#0DH
MOV DPTR,#03ACH
L0217:
CLR A
MOVC A,@A+DPTR
CJNE A,DevIDH,L0261
MOV A,#01H
MOVC A,@A+DPTR
CJNE A,DevIDL,L0261
CJNE R5,#0CH,L0225
L0225:
JC L0229
SETB Flag_GE12
L0229:
CJNE R5,#03H,L022C
L022C:
JNC L0230
SETB Flag_L3
L0230:
MOV A,#02H
MOVC A,@A+DPTR
MOV DevPara,A
MOV R1,#05H
MOV R0,#40H
L0239:
ACALL RecvByte
MOV A,R7
MOV @R0,A
INC R0
DJNZ R1,L0239
MOV A,40H
CJNE A,#0C0H,L0268
ADD A,41H
ADD A,PkgSizeH
ADD A,PkgZizeL
ADD A,44H
JNZ L0268
MOV A,41H
JNB Flag_L3,L0258
MOV CKCON,A
SJMP IspEraseAp
L0258:
JB Flag_GE12,L026E
ANL A,#0FH
MOV ISPCR,A
SJMP IspEraseAp
L0261:
INC DPTR
INC DPTR
INC DPTR
DJNZ R5,L0217
AJMP ResetToApp
L0268:
MOV R7,#0FEH
ACALL SendByte
AJMP ResetToApp
L026E:
MOV 0BFH,A
IspEraseAp:
MOV IFMT,#03H
MOV R1,DevPara
MOV R2,#00H
JNB Flag_L3,L027D
MOV ISPCR,#0C3H
L027D:
MOV A,R2
RL A
ANL A,#0FEH
MOV IFADRH,A
MOV IFADRL,#00H
ACALL IspSequent
INC R2
DJNZ R1,L027D
MOV R7,#ACK
ACALL SendByte
MOV AddrH,#00H
MOV AddrL,#00H
MOV IFMT,#02H
JNB Flag_L3,L029E
MOV ISPCR,#42H
L029E:
MOV A,PkgSizeH
JZ L02A9
MOV R1,A
L02A3:
ACALL Rec_Pgm
ACALL Rec_Pgm
DJNZ R1,L02A3
L02A9:
MOV A,PkgZizeL
JNB ACC.7,L02B2
ACALL Rec_Pgm
MOV A,PkgZizeL
L02B2:
ANL A,#7FH
MOV R1,A
JZ CheckSum
MOV R6,A
ACALL RecvPkg
MOV A,R1
MOV R6,A
ACALL IspProgram
MOV R7,#ACK
ACALL SendByte
CheckSum:
MOV AddrH,#00H
MOV AddrL,#00H
MOV IFMT,#01H
JNB Flag_L3,L02D1
MOV ISPCR,#41H
L02D1:
MOV A,PkgSizeH
JZ L02DC
MOV R1,A
L02D6:
ACALL CkSumVerify
ACALL CkSumVerify
DJNZ R1,L02D6
L02DC:
MOV A,PkgZizeL
JNB ACC.7,L02E5
ACALL CkSumVerify
MOV A,PkgZizeL
L02E5:
ANL A,#7FH
JZ PgmEnd
MOV R6,A
ACALL CalCkSum
ACALL SendCkSum
ACALL RecvByte
PgmEnd:
MOV IFMT,#00H
AJMP ResetToApp
Rec_Pgm:
MOV R6,#80H
ACALL RecvPkg
MOV R6,#80H
ACALL IspProgram
MOV R7,#ACK
ACALL SendByte
RET
RecvPkg:
MOV R0,#80H
L0304:
ACALL RecvByte
MOV A,R7
MOV @R0,A
INC R0
DJNZ R6,L0304
RET
IspProgram:
MOV R0,#80H
L030E:
MOV A,@R0
MOV IFADRH,AddrH
MOV IFADRL,AddrL
MOV IFD,A
ACALL IspSequent
INC AddrL
MOV A,AddrL
JNZ L0321
INC AddrH
L0321:
INC R0
DJNZ R6,L030E
RET
CkSumVerify:
MOV R6,#80H
ACALL CalCkSum
ACALL SendCkSum
ACALL RecvByte
CJNE R7,#ACK,PgmEnd
RET
CalCkSum:
MOV CurCkSumL,#00H
MOV CurCkSumH,#00H
L0337:
MOV IFADRH,AddrH
MOV IFADRL,AddrL
ACALL IspSequent
MOV A,IFD
CLR C
ADD A,CurCkSumL
MOV CurCkSumL,A
JNC L034A
INC CurCkSumH
L034A:
INC AddrL
MOV A,AddrL
JNZ L0352
INC AddrH
L0352:
DJNZ R6,L0337
RET
SendCkSum:
MOV R7,CurCkSumH
ACALL SendByte
MOV R7,CurCkSumL
ACALL SendByte
MOV A,CurCkSumH
CPL A
MOV R7,A
ACALL SendByte
MOV A,CurCkSumL
CPL A
MOV R7,A
ACALL SendByte
RET
L036A:
MOV TH0,Var31
MOV TL0,Var31
CLR TF0
SETB TR0
MOV R3,#10H
L0376:
JNB TF0,$
CLR TF0
DJNZ R3,L0376
CLR TR0
RET
IspSequent:
ORL ISPCR,#80H
MOV SCMD,#46H
PUSH R0
MOV R0,#48H
CJNE @R0,#44H,L03AA
INC R0
CJNE @R0,#4FH,L03AA
INC R0
CJNE @R0,#5FH,L03AA
INC R0
CJNE @R0,#49H,L03AA
INC R0
CJNE @R0,#53H,L03AA
INC R0
CJNE @R0,#50H,L03AA
POP R0
MOV SCMD,#0B9H
ANL ISPCR,#7FH
RET
L03AA:
AJMP ResetToApp
DB 0F8H
DB 01H
DB 0EH
DB 0F8H
DB 02H
DB 0EH
DB 0F1H
DB 10H
DB 7CH
DB 0F1H
DB 08H
DB 7CH
DB 0F1H
DB 04H
DB 7CH
DB 0F0H
DB 02H
DB 1CH
DB 0F0H
DB 01H
DB 1CH
DB 0F2H
DB 02H
DB 0EH
DB 0F3H
DB 04H
DB 1DH
DB 0F4H
DB 10H
DB 7EH
DB 0F0H
DB 04H
DB 1CH
DB 0F7H
DB 04H
DB 1EH
DB 0F5H
DB 04H
DB 1EH |