⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 icd仿真器的源程序.txt

📁 PIC单片机C源代码集合
💻 TXT
📖 第 1 页 / 共 3 页
字号:

Loop_NoEnter ; Now, Handle the Character (if Possible)

movf Command ; If Something is There - Ignore
btfss STATUS, Z
goto Loop

xorlw 10 ; Make it Regular ASCII
addlw 255 - 'z' ; Get the High limit
addlw 'z' - 'a' + 1 ; Add Lower Limit to Set Carry
btfss STATUS, C ; If Carry Set, then Lower Case
addlw 0x020 ; Carry NOT Set, Restore Character
addlw 'A' ; Add 'A' to restore the Character
movwf Command ; And Store It
call SendCHAR

goto Loop


Handle_Command ; Command Entered, Handle It

movf Command, w ; Handle the Value
xorlw 'E' ; Start with (E)PROM
btfss STATUS, Z
goto HC_NotE ; Nope
HC_E

bsf FlashEPROM ; Set the EEPROM Flag

movlw 1 ; Start the New Line
call DispMSG

goto Prompt


HC_NotE ; Not EPROM

xorlw 'E' ^ 'F' ; Flash?
btfss STATUS, Z
goto HC_NotF
HC_F ; Flash Specified

bcf FlashEPROM

movlw 1 ; Start the New Line
call DispMSG

goto Prompt


HC_NotF ; Flash Not Specified - "H"elp?

clrf SpeedTemp ; Use "SpeedTemp" to Set the Program Speed

xorlw 'F' ^ '1' ; Execute the Program?
btfsc STATUS, Z
goto HC_1MHz ; At One MHz
xorlw '1' ^ '2'
btfsc STATUS, Z
goto HC_2MHz ; At Two MHz
xorlw '2' ^ '4'
btfsc STATUS, Z 
goto HC_4MHz ; At Four MHz
xorlw '4' ^ '8'
btfss STATUS, Z ; At Eight MHz
goto HC_NotExecute ; Nothing Executing
goto HC_8MHz ; Make Sure 8 MHz Setup Correctly

HC_1MHz ; 1 MHz, Increment Temp ( = 3 )
incf SpeedTemp
HC_2MHz ; 2 MHz, Increment Temp ( = 2 )
incf SpeedTemp
HC_4MHz ; 4 MHz, Increment Temp ( = 1 )
incf SpeedTemp 
HC_8MHz ; 8 MHz, No Increment of Temp ( = 0 )

movlw 1 ; start a New Line for Executing
call DispMSG
movlw 4
call DispMSG
movlw 11
call DispMSG
movlw 1
call DispMSG
btfsc TXStart ; Wait for the Previous Send to End
goto $ - 1

bsf PORTA, 0 ; Turn On the Power

rlf SpeedTemp ; Move Temp up to the Correct Speed
rlf SpeedTemp
movlw 0x00C ; Clear any other Bits
andwf SpeedTemp

movlw 0x013 ; Get PORTA for Merging with Temp
andwf PORTA, w
iorwf SpeedTemp, w ; Merge the Temp Bits In as well
movwf PORTA

bsf Passthru ; Enable the Passthru Setup

bsf PORTB, 6 ; Turn On the External Reset
bsf PORTB, 3 ; Enable U2

Run_Loop ; Execute Here, Follow How it's going

btfsc PORTB, 2 ; Output External and PIC Reset According to Button
goto RL_HIGH ; Everything is Running

bcf PORTB, 3 ; Disable U2
bcf PORTB, 6 ; Turn OFF External Reset

goto RL_SerCheck ; Now, Check for a Serial "End" Character

RL_HIGH ; Make Sure Everything's High

bsf PORTB, 6
bsf PORTB, 3

RL_SerCheck ; Now, Wait for the 0x003 Character to End

movf NextINS, w ; See if the Value Has Moved
subwf NextRX, w
btfsc STATUS, Z
goto Run_Loop ; It Hasn't, Keep Looping Around

movf NextINS, w ; Get the Instruction Read In
movwf FSR ; Output It

incf NextINS, w ; Point to the Next Value in the Buffer
call RXBufReset
movwf NextINS

movf INDF, w ; Get the Character That Was Just Read in
xorlw 3 ; Is it the Stop Character?
btfss STATUS, Z
goto Run_Loop ; Nope

bcf PORTB, 6 ; Make External Reset Active
bcf PORTB, 3 ; Turn OFF the PIC
bcf Passthru ; Turn Off the Passthru
bcf PORTA, 0 ; Turn Off the PIC

movlw 1 ; Start a New Line to Show we're Finished
call DispMSG

goto Prompt ; Finished Executing, End and Return


HC_NotExecute ; Nothing Running; Just Programming Commands

xorlw '8' ^ 'B'
btfss STATUS, Z
goto HC_NotBlank
HC_Blank

btfsc FlashEPROM ; If Bit Set, Can Check for Blanks
goto HC_BlankCheck

movlw 3 ; Flash Memory - Can't Check for Blanks
call DispMSG

goto Prompt ; Finished with the Blank Check - End

HC_BlankCheck ; Now, We can Check for Blanks

call BlankCheck ; Use the Subroutine

movlw 1 ; Finish off the Line
call DispMSG

goto Prompt


HC_NotBlank ; Not Blank/Check for Program/Verify

xorlw 'B' ^ 'P'
btfss STATUS, Z
goto HC_NotProgram
HC_Program

clrf PC + 1 ; Clear the PIC's PC
clrf PC

btfss FlashEPROM ; Do we Have Flash (Can Just Program)?
goto HCP_Flash ; Yes, 

HCP_EPROM 

btfsc LastError ; Only Do Blank Check if LastError is NOT Set
goto HCP_Start

call BlankCheck ; See if the Part In there is Blank

movf Command
btfsc STATUS, Z
goto HCP_Start ; The Part is Blank, No Issues with Starting to Program

goto Prompt ; The Part isn't Blank - Error...

HCP_Flash ; Flash Parts

call PowerON ; Turn on VDD/Vpp and Enable RB6/RB7 Drivers

movlw 5 ; Mark that we are Clearing Memory
call DispMSG 

movlw 0x0FE
movwf PData ; Go into the Configuration Memory
movlw 0x07F
movwf PData + 1
movlw 0
call CmdWRITE

movlw 7 ; Go to 0x02007
movwf CmdReady
HCPF_ConfigLoop
movlw 6 ; Increment the Counter
call CmdSEND
decfsz CmdReady
goto HCPF_ConfigLoop

movlw 1 ; David Tait's Defeat Code Protection Code
call CmdSEND

movlw 7
call CmdSEND

movlw 8 ; Burn the New Values In
call CmdSEND

call RTCDlay

movlw 1 ; Microchip's CP Defeat Code
call CmdSEND

movlw 7
call CmdSEND

movlw 0x07F
movwf PData
movlw 0x0FE
movwf PData + 1
movlw 9 ; Do Bulk Erase of Program/Config Memory
call CmdSEND

movlw 8 ; Start Clearing the Memory (Begin Programming)
call CmdSEND

call RTCDlay ; Wait for the Instruction to Complete

call Poweroff ; Turn OFF the Power and RB6 and RB7 Drivers

HCP_Start

incf RTClo, w ; Wait at least 100 usec for the Line to Settle
addlw 2
movwf Command
HCP_Settle
movf Command, w
xorwf RTClo, w
btfss STATUS, Z
goto HCP_Settle

call PowerON ; Turn On Vpp/Vdd and Enable RB6/RB7

movf NextRX, w ; Going to Wait for one Circle of the RTC - Clear the RX Char
movwf NextINS

movlw 9 ; Tell the User to Start the Download
call DispMSG
movlw 11
call DispMSG

movf RTCHI, w ; Will Wait up to One Second
movwf CmdReady
HCP_DLWait ; Have to Wait for RTCHI to Change
movf CmdReady, w
subwf RTCHI, w
btfsc STATUS, Z
goto HCP_DLWait

HCP_DownLoadWait ; Now, Wait for the Data to Start Coming in

movf NextINS, w ; Has something Been Received
subwf NextRX, w
btfsc STATUS, Z
goto HCPDLW_Skip

movf NextINS, w ; Look at the Character
movwf FSR

movlw 3 ; Do we have a "Ctrl-C"?
subwf INDF, w
btfsc STATUS, Z
goto HCP_End ; Yes, End the Programming

goto HCP_Loop ; *Now*, We can Start Programming

HCPDLW_Skip

movf RTCHI, w
xorwf CmdReady, w ; Has RTC Timed Out?
btfss STATUS, Z
goto HCP_DownLoadWait ; Nope, Keep Waiting

movlw 10 ; Display the Timeout Message
call DispMSG

goto HCP_End


HCP_Loop ; Start Programming the PIC

movf NextINS, w ; Wait for the First Byte of the Line to be Loaded
subwf NextRX, w
btfsc STATUS, Z
goto HCP_Loop ; Not Loaded Yet - Keep Waiting

movf NextINS, w ; Get what was Loaded
movwf FSR

movf NextRX, w ; Point to the Next Character after this
movwf NextINS

movf INDF, w ; Get the Character and Check for Valid
xorlw ':'
btfsc STATUS, Z
goto HCPL_GetChars ; Valid Start, Now, Get the Characters

call DownLoadWait ; Wait for the Download to Complete before Sending the Message

movlw 1 ; Invalid File - Error
call DispMSG
movlw 8
call DispMSG
movlw 6
call DispMSG

goto HCP_End

HCPL_GetChars ; Get the Number of Characters Program In

movf NextINS, w ; This will take waiting for two Characters
addlw 2
call RXBufReset
movwf CmdReady
HCPL_GCWait 
movf CmdReady, w
subwf NextRX, w
btfss STATUS, Z ; Do we Have a Match?
goto HCPL_GCWait

movf NextINS, w ; Do we have a Full 8 Characters?
movwf FSR
movf INDF, w
addlw 0 - '1'
btfss STATUS, Z
goto HCPL_GetCount ; Nope, Have to Get the Count

movlw 0x010 ; Else, Doing a Full Line of 8

goto HCPL_HaveGC

HCPL_GetCount ; Have to See what the Value is to Get

incf NextINS, w ; Point to One Past Current
call RXBufReset
movwf FSR

movf INDF, w ; Get the Value
btfsc INDF, 6 ; "A"+?
addlw 0 - 7 ; Yes, Reduce it
addlw 0 - '0' ; Have a Nybble

HCPL_HaveGC ; "w" has 2x the Count Value

movwf LineCount
bcf STATUS, C ; Divide by 2
rrf LineCount

movf NextINS, w ; Skip Over these Two Instructions
addlw 2
call RXBufReset
movwf NextINS

HCPL_GetAddress

addlw 4 ; And Add 4 to it to get the Expected Address value
call RXBufReset
movwf CmdReady
HCPLGA_Wait ; Wait for the four Characters to be Entered
movf NextRX, w
subwf CmdReady, w
btfss STATUS, Z
goto HCPLGA_Wait

HCPLGA_HaveAddress ; Address has been Entered

HCPLGA_Loop ; Loop Here for Each of the Four Characters 

swapf TData + 1, w ; Move Everything Over for Getting the Character
andlw 0x0F0
movwf TData + 1
swapf TData, w 
andlw 0x00F
iorwf TData + 1
swapf TData, w
andlw 0x0F0
movwf TData

movf NextINS, w ; Get the Current Character
movwf FSR
movf INDF, w
btfsc INDF, 6 ; > 9? ("A" - "F")
addlw 0 - 7
addlw 0 - '0' ; Get Nybble
iorwf TData ; Save it in the Value

incf NextINS, w ; Now, Point to the Next Character
call RXBufReset
movwf NextINS ; Save the Currently Read in Value

subwf CmdReady, w ; Are we at the End?
btfss STATUS, Z
goto HCPLGA_Loop

bcf STATUS, C ; Divide the Address by 2
rrf TData + 1
rrf TData

movf TData + 1, w ; Is Everything Zero (ie at the End of the File?
iorwf TData, w
iorwf LineCount, w
btfsc STATUS, Z
goto HCP_Finished ; Yes, Just have to wait for the Last 0x00A

movf TData + 1, w ; Do we Skip to the Configuration Memory?
xorwf PC + 1, w
andlw 0x020 ; If there's Just 0x020 Left then Yes...
btfsc STATUS, Z
goto HCP_IncCheck ; No, Do the Incrementing Check

movlw 0x020 ; Else, Yes, Move the PC into the Incrementing Area
movwf PC + 1
clrf PC

clrf PData ; Send Nothing to the Configuration Value
clrf PData + 1

movlw 0 ; Move the PIC into the Configuration Memory
call CmdWRITE

HCP_IncCheck ; Do We Have a Valid Difference?

; #### - Put in New Difference Check

movf PC + 1, w ; Do 16 Bit Subtract on the Address
subwf TData + 1, w
movwf CmdReady
movf PC, w
subwf TData, w
btfss STATUS, C
decf CmdReady
addlw 0 - 48 ; Is it == 48 or Greater?
btfss STATUS, C
decf CmdReady
btfsc CmdReady, 7
goto HCP_Inc


; movf PC, w ; Can Just Go With the PCLows
; subwf TData, w
; addlw 0 - 48 ; Up to 48 Possible
; btfss STATUS, C
; goto HCP_Inc ; It's Okay, Increment Away

call DownLoadWait ; Wait for DownLoad to Complete before Sending Message

movlw 1 ; Put in the Error Messages
call DispMSG
movlw 7 
call DispMSG
movlw 6
call DispMSG

goto HCP_End

HCP_Inc ; Now, We Can Just Increment to the appropriate Value

movf TData, w ; Keep Incrementing Until a Match
subwf PC, w
btfsc STATUS, Z
goto HCP_ProgramStart ; Can Start Programming

movlw 6 ; Increment the Address
call CmdSEND

incf PC ; Increment the Program Counter
btfsc STATUS, Z
incf PC + 1

goto HCP_Inc

HCP_ProgramStart ; *Now* we can Start Waiting for the Program...

movlw 6
addwf NextINS, w ; Get the Offset to the End of the Data
call RXBufReset
movwf CmdReady
HCPPS_Wait ; Wait for the Six Characters to be Entered
movf NextRX, w
subwf CmdReady, w
btfss STATUS, Z
goto HCPPS_Wait

movlw 2 ; Move NextINS 2 Up on where we are to skip the "00"s
addwf NextINS, w
call RXBufReset
movwf NextINS

HCP_ProgramLoop ; Loop Back Here After Every Address Programmed

movf NextRX, w ; Save to Where We're Going
movwf CmdReady

movf NextINS, w ; Get the Current four Characters...
movwf FSR

HCPPL_Cycle0 ; Do 4x

swapf TData, w ; Shift the Hex Values Up
andlw 0x0F0 ; NOTE!!! lo and High Are reversed to Get Correct Values
movwf TData
swapf TData + 1, w
andlw 0x00F
iorwf TData
swapf TData + 1, w
andlw 0x0F0
movwf TData + 1

movf INDF, w ; Get the Character Pointed To
btfsc INDF, 6 ; Convert to a Nybble
addlw 0 - 7
addlw 0 - '0' 
iorwf TData + 1 ; Save the Low Value of the Number

incf FSR, w
call RXBufReset
movwf FSR
movwf NextINS

subwf CmdReady, w ; Are we At the End?
btfss STATUS, Z
goto HCPPL_Cycle0

HCPPL_Cycle1Wait ; Now, Wait for Next to go to the Next Cycle
movf CmdReady, w
subwf NextRX, w
btfsc STATUS, Z
goto HCPPL_Cycle1Wait

HCPPL_Cycle1 ; Second Cycle, Send out the Programming info

bcf STATUS, C ; Begin Programming
rlf TData, w ; Put the Program Value in Data for Output
movwf PData
rlf TData + 1, w
movwf PData + 1

btfsc Verify ; Are We Verifying or Programming?
goto HCPPL_VerifySkip ; Verifying, Don't Start Programming

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -