DatasheetQ Logo
Electronic component search and free download site. Transistors,MosFET ,Diode,Integrated circuits

AN247 View Datasheet(PDF) - Microchip Technology

Part Name
Description
Manufacturer
AN247 Datasheet PDF : 32 Pages
1 2 3 4 5 6 7 8 9 10 Next Last
AN247
It is also important to note some configuration bits are
single direction bits in Normal mode; they can only be
changed to one state, and cannot be changed back.
The code protection bits in Configuration registers 5L
and 5H are a good example. If any type of code protec-
tion is enabled for a block, it cannot be disabled without
a device programmer. Essentially, the bootloader
cannot reverse code protection.
The Device ID (addresses 3FFFFEh and 3FFFFFh) is
also considered Program Memory. While they can be
accessed, however, they are read only and cannot be
altered.
Write Latency
When writing data, there is a specific time that the pro-
gramming source must wait for to complete the pro-
gramming operation. Fortunately, the CAN module
actually buffers received data; therefore, receiving can
actually overlap memory write operations (Figure 6). In
general, it takes about 2 ms for Program Memory write
operations, while EEDATA takes about 4 ms. Not all
PIC18F devices have the same time specifications, so
it is important to verify the write times for the specific
device to be used.
FIGURE 6:
CAN RECEIVE VS.
MEMORY WRITE
CAN
Message
Receive
Memory
Write
CAN
Msg
WRITING CODE
The bootloader operates as a separate entity, which
means that an application can be developed with very
little concern about what the bootloader is doing. This
is as it should be; the bootloader should be dormant
code until an event initiates a boot operation. Under
ideal circumstances, bootloader code should never be
running during an application’s intended normal
operation.
When developing an application with a resident
bootloader, some basic principles must be kept in mind.
Writing in Assembly
When writing in assembly, the boot block and new vec-
tors must be considered. For modular code, this is gen-
erally just a matter of changing the linker script file for
the project. An example is given in Appendix C. If an
absolute address is assigned to a code section, the
address must point somewhere above the boot block.
For those who write absolute assembly, all that is nec-
essary to remember is that the new RESET vector is at
200h, and the interrupt vectors are at 208h and 218h.
No code except the bootloader should reside in the
boot block.
Writing in C
When using the MPLAB® C18 C compiler to develop
PIC18F firmware for an application, the standard
start-up object (c018.o or c018i.o) must be rebuilt
with the new RESET vector. Like modular assembly,
the linker file must be changed to incorporate the pro-
tected boot block and new vectors. Appendix C shows
an example linker file.
Users of other compilers should check with the com-
piler’s software user guide to determine how to change
the start-up code and vectors.
Bootloader Re-Entry
If the need exists to re-enter Boot mode from the appli-
cation (and it usually does), the last location of the data
EEPROM must be set to FFh. The code in Example 1
demonstrates how this might be done in an application.
Since the bootloader assumes RESET conditions, a
RESET instruction should be initiated after setting the
last location.
EXAMPLE 1:
SETTING THE LAST
LOCATION OF THE
DATA MEMORY
SETF
SETF
SETF
MOVLW
MOVWF
MOVLW
MOVWF
MOVLW
MOVWF
BSF
NOP
BTFSC
BRA
RESET
EEADR
; Point to the last byte
EEADRH
EEDATA
; Bootmode control byte
b'00000100 ; Setup for EEData
EECON1
0x55
; Unlock
EECON2
0xAA
EECON2
EECON1, WR ; Start the write
EECON1, WR ; Wait
$-2
DS00247A-page 6
2003 Microchip Technology Inc.

Share Link: 

datasheetq.com  [ Privacy Policy ]Request Datasheet ] [ Contact Us ]