TB025 Microchip Technology, TB025 Datasheet - Page 3
![no-image](/images/manufacturer_photos/0/4/439/microchip_technology_sml.jpg)
TB025
Manufacturer Part Number
TB025
Description
Microcontrollers
Manufacturer
Microchip Technology
Datasheet
1.TB025.pdf
(8 pages)
www.DataSheet4U.com
PICmicro Code
The sample downloader code does not specifically use
one of the interface modules on the PIC16F87X device.
Instead, a routine called GetByte retrieves a single
character from the HEX file over the desired interface.
It is up to the engineer to write this routine around the
desired interface. Another routine GetHEX8 calls Get-
Byte twice to form a two digit hexadecimal number.
One issue that arises is how many times to reprogram
a location that does not program correctly. The sample
code provided simply exits the downloader routine and
stores a value of 0xFF in the WREG if a program memory
location does not properly program on the first attempt.
The engineer may optionally add code to loop several
times if this event occurs.
Still another issue that is not specifically addressed in
the sample code is to prevent the downloader from
overwriting its own program memory address locations.
The designer must add an address check to prevent
this situation from happening.
Finally, the designer must account for situations where
the download of new code into the microcontroller is
interrupted by an external event such as power failure
or reset. The system must be able to recover from such
an event. This is not a trivial task, is very system
dependent, and is therefore left up to the designer to
provide the safeguards and recovery mechanisms.
Another error that could happen is a line checksum
error. If the calculated line checksum does not match
the line checksum from the HEX file, a value of 1 is
returned in WREG . The part of the routine that calls the
downloader should check for the errors 0xFF (could not
program a memory location) and 1. If program memory
is programmed correctly and no errors have been
encountered, the downloader routine returns a 0 in
WREG to indicate success to the calling routine. Figure
2 shows the flowchart for the downloader routines.
Listing 2
code.
1998 Microchip Technology Inc.
shows the complete listing for the downloader
The routine ASCII2HEX converts the input character to
a binary number. The routine does not provide any out
of range error checking for incoming characters. Since
the only valid characters in a HEX file are the colon (:),
the numbers 0 through 9 and the letters A through F,
the routine can be highly optimized. It first subtracts 48
from the character value. For the ASCII numbers 0
through 9, this results in a value from 0 to 9. If the char-
acter is A through F, the result is a number greater than
15. The routine checks to see if the upper nibble of the
result is 0. If not 0, then the original value was A
through F and the routine now subtracts an additional
43 from the character resulting in the binary values 10
through 15. The colon is not accounted for in this rou-
tine because the main part of the downloader code
uses it as a line sync.
LISTING 1:
bsfSTATUS,RP1
bcfSTATUS,RP0
movfAddrH,W
movwfEEADRH
movfAddrL,W
movwfEEADR
bsfSTATUS,RP0
bsfEECON1,EEPGD
bsfEECON1,RD
bcfSTATUS,RP0
nop
movfEEDATA,W
…
movfEEDATH,W
…
FLASH WRITE SEQUENCE
; Bank2
; Bank3
; Set for Prog Mem
; read operation
; Bank2
; Load address into
; Data is read
; access memory
; EEADRH:EEADR
; user can now
DS91025A-page 3
TB025