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

📄 bootldr.txt

📁 picc_18v 8.35pl35 PIC18系列单片机开发C编译器
💻 TXT
字号:
PIC18Fxxx BOOT LOADER/DOWNLOADER Copyright (C)2002 HI-TECH Software.
Freely distributable.

Included in this package is an implementation of a boot loader for
the PIC18 flash devices.

Introduction
############

The Microchip PIC18Fxxx processors are able to write to their own program 
memory while executing from it. By taking advantage of this fact, a 
bootloader program can be designed to accept new code via the serial 
port (or other method) and re-program itself.

On startup the bootloader code is the first to execute. The bootloader will
transmit a count-down on the serial port. At this time the bootloader is
awaiting to recieve a byte on the serial port. Sending a character to the 
serial port, during the count-down will indicate to the device that the user
intends to download a new program into the device. A prompt will be displayed,
and the file may now be transferred to the device via the serial connection.

If the user does not respond to the processor before the count-down expires,
the processor will begin execution of the program previously installed.

How it Works
############

So as to maximize the amount of available program memory, the bootloader 
has been designed to occupy less than 200H bytes. Another reason for doing 
this is because the address range 0-1FFH has special write-protection features.

The bootloader code executes before any user program. If it is given a program to
download during its execution, it will write the program code to the device's flash
memory. It is assumed that the program code being downloaded is an INTEL hex file
which avoids the address range 0-200H.

The hex file is read by the bootloader program and stores the data in the according
memory region. These regions can include; program memory, EEPROM data memory,
device configuration registers and user ID locations.


Microchip PIC18Fxxx memory map with the bootloader installed

     Address
        0       |--------------------------|
               	|  Interrupt redirection   |	<--- Interrupts redirected to
        0020    |--------------------------| 	     user's interrupt routine
               	|      Bootloader code     |	<--- Bootloader program
               	|                          |
        01FF    |--------------------------|
               	|                          |
               	|                          |
               	|                          |
               	|                          |
               	|      Program space       |
               	|      available for       |	<--- Available space for user programs
               	|   downloaded programs    |
               	|                          |
               	|                          |
               	|                          |
               	|                          |
               	|                          |
               	|                          |
        Flash   |                          |
        TOP     |--------------------------|	<--- Top of flash memory is device specific
               	~                          ~
        200000  |--------------------------|
	        |     ID locations         |	<--- User's IDLOC data
        200008  |--------------------------|
               	~                          ~
        300000  |--------------------------|
               	|   Configuration words    |	<--- Device's configuration settings
        3FFFFF  |--------------------------|


        0       |--------------------------|
               	|                          |	
               	|       Data EEPROM        |	<--- Data EEPROM size is device specific
        EEPROM  |                          |
        TOP     |--------------------------|



Any program locatations of the downloaded program that correspond to locations
in the bootloader, will be ignored. This ensures that program data being 
received cannot overwrite any bootloader code.

Compiling the Bootloader
#######################

The source code for the bootloader must be compiled prior to download into the
target device. A typical command line used to compile the bootloader is:

picc18 -18f452 bootldr.c -o -zg -noerrata
or
picc18 -18f458 bootldr.c -o -zg -DVERBOSE -ICD -MPLAB
to put the bootloader in verbose mode and compile for Microchip ICD2.

Verbose mode:
The bootloader can be put into a mode that is more verbose, if the symbol VERBOSE
is defined when compiling the bootloader source code. However Using the
bootloader in this mode will consume more program memory.

Note: If compiling the bootloader for the PIC18Fxx2 family of devices, you
should also add the -noerrata option. The bootloader code is not susceptible
to the hardware bugs listed in the errata document for this family of devices,
and therefore the compiler should be told not to add any errata specific fixes
into the code. Failure to add the -noerrata option will result in an error.

Compiling Programs for Download
############################### 

Except for the fact that there are 200H bytes less space available, nothing 
special has to be done in the design of downloadable programs. The only thing
that must be done is to make sure the program doesn't use any program space 
where the bootloader resides. By default, the bootloader occupies the program
space from 0-0x01FF. To avoid these locations use the compiler switch -A200.

If the program to be downloaded is to begin at an address other than 0x0200,
the -A option will be adjusted accordingly. So too, the definition of PROG_START
will need to be adjusted in bootldr.h.

If the bootloader is compiled for verbose mode, this requires more resources
so the program memory range (0-2FF) must be avaoided. A program to be
downloaded using the verbose bootloader will need to use a -A300 option.

Downloading Programs
####################

Once the bootloader itself has been downloaded into the processor, there is no
special program required to operate this bootloader. Any basic serial
communications program (such as HyperTerminal) will be sufficient.

By default the data trasfer rate is 9600 Bits per second. This again can be
changed, by modifying the BAUD definition in bootldr.h.

Once the connection has been established with the microcontroller (containing
bootloader), the connection can be verified by running the bootloader program.
A countdown should appear in the communication terminal window.

To commence a download, the countdown needs to be interrupted with a keypress,
before the it expires. The bootloader will acknoledge this by printing
a colon, which indicates it is now ready to recieve the compiled hex file of
the download application. If using HyperTerminal, choose Transfer > "Send Text
File..." then set "Files of type" to [All files (*.*)] and choose your .hex
file.

⌨️ 快捷键说明

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