?? icd仿真器的源程序.txt
字號:
movlw 2 ; Do the Program Instruction
call CmdWRITE
movlw 8 ; Start the Programming
call CmdSEND
HCPPL_VerifySkip
movf NextRX, w ; Now, Wait through the Next Character for Programming
addlw 2
call RXBufReset
movwf CmdReady
HCPPL_Cycle12Wait ; Wait for the Two Cycles To End
movf NextRX, w
subwf CmdReady, w
btfss STATUS, Z
goto HCPPL_Cycle12Wait
HCPPL_Cycle3 ; Have Waited for the Data to Take
btfsc Verify
goto HCPPL_Cycle3Do ; Don't End Programming if Verify Set
btfss FlashEPROM
goto HCPPL_Cycle3Do ; Flash, Don't have to Stop Programming
movlw 0x00E ; EEPROM - Send End Programming Command
call CmdSEND
HCPPL_Cycle3Do ; Now, See if the Instruction was Entered
movlw 4
call CmdREAD
bcf STATUS, C ; Compare the Values to Written
rrf PData + 1, w
xorwf TData + 1, w
btfss STATUS, Z ; If NOT Zero, then MisCompare
goto HC_Error
rrf PData, w ; Carry Flag Still Valid
xorwf TData, w
btfss STATUS, Z
goto HC_Error ; MisCompare Somewhere
movlw 6 ; Increment the PIC's Internal PC
call CmdSEND
incf PC ; Increment the Program Counter
btfsc STATUS, Z
incf PC + 1
movf NextRX, w ; Wait for the Cycle to End (and Restart)
movwf CmdReady
HCPPL_Cycle3Wait ; Wait for the Next Character
movf CmdReady, w
subwf NextRX, w
btfsc STATUS, Z
goto HCPPL_Cycle3Wait
decfsz LineCount
goto HCP_ProgramLoop ; Now, Get the Next Character
movf NextRX, w ; Reset Where we Are
movwf NextINS
addlw 0x0FF ; #### - Check Back by 1
andlw RXBuf + 7
iorlw RXBuf
; xorlw RXBuf ; Are we at the Start of the Buffer?
; movlw 0x0FF
; btfsc STATUS, Z
; movlw RXBufEnd - RXBuf ; Move the Buffer Back By 1
; addwf NextINS, w
movwf FSR
movf INDF, w ; Do we Have a Character Match?
xorlw ':'
btfss STATUS, Z
goto HCP_Loop ; No, Stick With Current
movf FSR, w ; Yes, Pass to the Program
movwf NextINS
goto HCP_Loop ; Check out the Next Line
HC_Error ; Error - Display and Return
call DownLoadWait
movlw 1 ; Start a New Line
call DispMSG
movlw 6 ; Put in Error - Message
call DispMSG
movf PC + 1, w
call DispHEX
movf PC, w
call DispHEX
movlw ' ' ; Put In the Data As Well
call SendCHAR
movlw 'A' ; Show the Actual Value
call SendCHAR
movlw '-'
call SendCHAR
movf PData + 1, w
call DispHEX
movf PData, w
call DispHEX
movlw ' ' ; Show the Expected
call SendCHAR
movlw 'E'
call SendCHAR
movlw '-'
call SendCHAR
movf TData + 1, w
call DispHEX
movf TData, w
call DispHEX
bsf CurError ; Setup so that Last Error Get's Set correctly
goto HCP_End
HCP_Finished ; Wait for the Last 0x00A
clrf TData ; Do a Maximum Delay (1/10 Second)
clrf TData + 1
HCP_FinishedLoop ; Loop Here Until get 0x00A or TimeOut
movlw 1 ; Timeout Check Loop
addwf TData
decfsz TData + 1
goto HCP_FinishedSkip
goto HCP_End
HCP_FinishedSkip
movf NextINS, w
subwf NextRX, w ; Look for the Next Character
btfsc STATUS, Z
goto HCP_FinishedLoop
movf NextINS, w ; Look at the Value at NextINS
movwf FSR
movf NextRX, w ; Setup the Point to the Next Character
movwf NextINS
movlw 0x00A ; Do we Have the Last 0x00A?
xorwf INDF, w
btfss STATUS, Z
goto HCP_FinishedLoop
HCP_End ; Finished Programming - Reset the Power and End
movlw 1 ; End the Current Line
call DispMSG
call Poweroff ; Turn off the Power & RB6/RB7 Drivers
goto Prompt
HC_NotProgram ; Not Program, Check for Verify
xorlw 'P' ^ 'V' ; Do we Have a Verify Instruction?
btfss STATUS, Z
goto HC_Invalid
HC_Verify
bsf Verify ; Set the Verify Flag
clrf PC + 1 ; Clear the PIC's PC
clrf PC
goto HCP_Start ; Use the Programmer's Code for Verifying
HC_Invalid
movlw 3 ; Put in "Invalid Message"
call DispMSG
goto Prompt
PAGE
; Subroutines
DownLoadWait ; Wait for the DownLoad to Complete
movf NextRX, w ; Make Sure the Next Instruction to be Read is the Same as the
movwf NextINS ; Current...
movlw 5 ; Add 5 to RTCHI to Get the End Condition
addwf RTCHI, w
movwf Temp ; Use this as a Compare for the Wait
DLW_Loop ; Loop Around Here until a New Character OR 1 Second
movf NextRX, w ; Do we Have a New Character in from the Serial Port?
subwf NextINS, w
btfss STATUS, Z
goto DownLoadWait ; Yes, Wait through the Next Character
movf Temp, w ; Have we waited 1 Sec from the Previous Character?
subwf RTCHI, w
btfss STATUS, Z
goto DLW_Loop ; Nope, Keep Looping Around
return
BlankCheck ; Check to See if the EPROM Device is Blank
call PowerON ; Turn On Power & Enable RB6/RB7 Drivers
movlw 5 ; Put in "Blank" Message - Wait for Vpp to Stabilize
call DispMSG
btfsc TXStart ; Wait for the Previous Send to End
goto $ - 1
clrf PC + 1 ; Clear the Program Counter Values
clrf PC
BC_Loop ; Loop Around Here and Read Each Location
movlw 4 ; Read the Current Location
call CmdREAD
movlw 0x07F ; Check the Values Returned
xorwf PData + 1, w
btfss STATUS, Z
goto BC_Error ; MisCompare
movlw 0x0FE
xorwf PData, w
btfss STATUS, Z
goto BC_Error
movlw 6 ; Value is Okay
call CmdSEND ; Increment the PIC's PC
incf PC ; Increment the Program Counter
btfsc STATUS, Z
incf PC + 1
movlw 4 ; Have we Checked all the Values?
subwf PC + 1, w
btfss STATUS, Z ; If Zero, Have to Move Into Configuration Memory
goto BC_Skip
movlw 0x020 ; Now, Do the Configuration Memory Starting @ 0x02000
movwf PC + 1
clrf PC
movlw 0 ; Get the Configuration Value
call CmdWRITE
BC_Skip ; Now, See if We're at the End
movlw 0x020 ; In Configuration Memory?
xorwf PC + 1, w
btfss STATUS, Z
goto BC_Loop ; Nope...
movlw 0x010 ; Past the End of Configuration Memory?
xorwf PC, w
btfss STATUS, Z
goto BC_Loop
clrf Command ; Note that BlankCheck Was Successful
goto BC_End ; Finished, Turn Off the PIC Power
BC_Error ; Error, Print the Hex Address of the Non-Zero
movf PC + 1, w
call DispHEX
movf PC, w
call DispHEX
movlw '-' ; Put In the Data As Well
call SendCHAR
movf PData + 1, w
call DispHEX
movf PData, w
call DispHEX
movlw 1 ; Mark that we have the Error
movwf Command
BC_End ; Finished Doing the Blank Check
call Poweroff
return ; Return to the Caller
PowerON ; Turn on Power & Enable RB6/RB7 Drivers
movlw 0x0CF ; Make Sure the Values are Low
andwf PORTB
bsf STATUS, RP0 ; Turn On the Output Bits
movlw 0x0CF ; RB4 and RB5 for RB6 & RB7
andwf TRISB & 0x07F
bcf STATUS, RP0
bsf PORTA, 0 ; Turn On U2's Power
movlw 1 ; Start a New Line - Wait for Power and Output to Stabilize
call DispMSG
bsf PORTB, 1 ; Turn On U2's Vpp
return
Poweroff ; Turn off the Power and RB6/RB7 Drivers
bsf STATUS, RP0 ; Turn On the Output Bits
movlw 0x030 ; RB4 and RB5 for RB6 & RB7
iorwf TRISB & 0x07F
bcf STATUS, RP0
bcf PORTB, 1 ; Turn off U2's Vpp
bcf PORTA, 0 ; Turn off U2's Power
return
CmdSEND ; Send the Command to U2
movwf CSTemp ; Save the Command for Sending
movlw 6 ; Only Sending 6 Characters
movwf CCount
bcf INTCON, GIE
CS_Loop ; Loop Around Here for Each Bit
bsf PORTB, 4 ; Make the Clock High
bcf PORTB, 5 ; Start with the Data Low
btfsc CSTemp, 0 ; Do we Set the Value High?
bsf PORTB, 5
bcf PORTB, 4 ; Finished with the Data
nop ; Put Here to Make Sure Timing is Equal
rrf CSTemp ; Move Next Bit to Position "0"
decfsz CCount ; Do 6x
goto CS_Loop
bcf PORTB, 5 ; Make Sure RB7 Is Low Upon Return
bsf INTCON, GIE
return
CmdWRITE ; Write Data to the PIC
call CmdSEND ; Assume Leading Character is in "w"
goto $ + 1 ; Match Cycles with the Read
nop
movlw 16 ; Can Send Data - Takes 16 Cycles
movwf CCount
bcf INTCON, GIE
CW_Loop
bsf PORTB, 4 ; Make the Clock High
bcf PORTB, 5 ; Start with the Data Low
btfsc PData, 0 ; Do we Set the Value High?
bsf PORTB, 5
bcf PORTB, 4 ; Finished with the Data
rrf PData + 1 ; Shift Over the Data
rrf PData
decfsz CCount ; Do 6x
goto CW_Loop
bcf PORTB, 5 ; Make Sure Everything is Low Upon Exit
bsf INTCON, GIE
return
CmdREAD ; Read Data from the PIC
call CmdSEND ; Assume Leading Character is in "w"
bsf STATUS, RP0 ; Make RB7 an Input Bit
bsf TRISB & 0x07F, 5
bcf STATUS, RP0
movlw 16 ; Can Send Data - Takes 16 Cycles
movwf CCount
bcf INTCON, GIE
CR_Loop
bsf PORTB, 4 ; Make the Clock High
bcf STATUS, C ; Get Read Value
btfsc PORTB, 5 ; Is the Bit High?
bsf STATUS, C
bcf PORTB, 4 ; Finished with the Data
rrf PData + 1 ; Shift Over the Data
rrf PData
decfsz CCount ; Do 6x
goto CR_Loop
bcf PORTB, 5 ; Make Sure RB7 is Low Upon Exit
bsf INTCON, GIE
bsf STATUS, RP0 ; Restore RB7 to Output
bcf TRISB & 0x07F, 5
bcf STATUS, RP0
movlw 0x07F ; Get Rid of Bad Bits on the Ends
andwf PData + 1
movlw 0x0FE
andwf PData
return
SendCHAR ; Send the Character in "w"
btfsc TXStart ; Wait for the Previous Send to End
goto $ - 1
movwf TXOut ; Send out the Character
bsf TXStart ; Tell the Interrupt Handler that it can Send Something
return
DispMSG ; Display a String
movwf Temp ; Save the Temporary Value
clrf FSR ; Use the FSR as the Index to the String
DM_Loop1 ; Find the Correct String to Display
movf Temp ; Are we at the End?
btfsc STATUS, Z
goto DM_Loop2
movf FSR, w ; Get the Character at the Message
call Msg
iorlw 0 ; Is it Equal to Zero?
btfsc STATUS, Z
decf Temp ; Yes, At the End of the String
incf FSR ; Point to the Next Message Character
goto DM_Loop1
DM_Loop2 ; Display the String Indexed by FSR
movf FSR, w ; Send the Current Character
call Msg
iorlw 0 ; At the End of the String?
btfsc STATUS, Z
goto DM_End ; Yes
call SendCHAR
incf FSR
goto DM_Loop2
DM_End
return
DispHEX ; Display the HEX Message
movwf Temp ; Save the Value for Later
swapf Temp, w ; Do the High Nybble First
andlw 0x00F
call HEXTable
call SendCHAR
movf Temp, w
andlw 0x00F
call HEXTable
call SendCHAR
return
RXBufReset ; Reset the value in "w" to a valid RXBuf Value
andlw RXBuf + 7 ; Clear Upper Bits of FSR
iorlw RXBuf
; addlw 0 - ( RXBufEnd + 1 )
; btfsc STATUS, C
; addlw RXBuf - ( RXBufEnd + 1 )
; addlw RXBufEnd + 1
return
; Instruction Delays
Dlay16 ; Dlay 16 Cycles
call Dlay8
Dlay8 ; Dlay 8 Cycles
call Dlay4
Dlay4 ; Dlay 4 Cycles
return
RTCDlay ; Use the RTC to Provide a Real Delay
movf RTCHI, w ; Wait for the programming Command to Complete
addlw 2
movwf CmdReady
RTCD_Loop ; Wait for the Programming Command to Complete
movf RTCHI, w
subwf CmdReady, w
btfss STATUS, Z ; Have we waited long enough?
goto RTCD_Loop
return
HEXTable
addlw 0x036 ; Add '0' + 6 to Value
btfsc STATUS, DC ; If Digit Carry Set, then 'A' - 'F'
addlw 7 ; Add Difference Between '9' and 'A'
addlw 0-6
return
end
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -