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

📄 bootldr.h

📁 pic单片机例程
💻 H
字号:
#ifndef _BOOTLDR_H_
#define _BOOTLDR_H_

/*
 * 	BOOT LOADER v3.01A Copyright (C) 2008 HI-TECH Software
 *	This software is freely distributable and may be used
 *	for any purpose. No warranty of any kind is provided
 *	and all use is entirely at your own risk.
 *
 *	The boot loader is suitable for use with the following
 *	PICmicro controllers:
 *
 *	16F870, 16F871, 16F873, 16F873A, 16F874,
 *	16F874A, 16F876, 16F876A, 16F877, 16F877A
 *	
 *	BOOTLDR.H
 */
 

/* Time (seconds) to wait for user input. Must be <= 9 */
#define BOOT_TIMEOUT	9

/* Baud rate to use for data transfer/communication */
#ifndef BAUD
 #define BAUD 2400
#endif

// System frequency
#ifndef FOSC
 #define FOSC 4000000L
#endif

// Find out the program memry size of this chip
#ifndef _ROMSIZE
 #error Bootloader does not support the selected processor
#else
 #define FLASH_SIZE	_ROMSIZE	// _ROMSIZE is defined by the compiler
#endif

// Address where boot loader will start
#if VERBOSE == 2
 #define BOOTLOADER_SIZE 0x180
#elif defined(VERBOSE)
 #define BOOTLOADER_SIZE 0x180
#else
 #define BOOTLOADER_SIZE 0x100
#endif

// If this bootloader is being compiled to run on a system that may one day
// be debugged with the ICD2, we need to allow space for that.
#if defined(MPLAB_ICD)
 #define BOOT_START (FLASH_SIZE - BOOTLOADER_SIZE - 0x100)
#else
 #define BOOT_START (FLASH_SIZE - BOOTLOADER_SIZE)
#endif

// Check whether the bootloader supports this processor
#if defined(_16F877) || defined(_16F877A) || defined(_16F876) || defined(_16F876A) || \
	defined(_16F874) || defined(_16F874A) || defined(_16F873) || defined(_16F873A) || \
	defined(_16F871) || defined(_16F870)
 // processor is supported
#else
 #error This bootloader does not support the selected processor
#endif

#if ((BOOT_START & 0xFF) != 0)
#define IRREG_START
#endif

#if (BAUD > 2400)
 #warning File transfer not recommended to exceed 2400 baud
#endif

#define NINE 0     /* Use 9bit communication? FALSE=8bit */

#define DIVIDER ((int)(FOSC/(16UL * BAUD) -1))
#define HIGH_SPEED 1

#if NINE == 1
#define NINE_BITS 0x40
#else
#define NINE_BITS 0
#endif

#if HIGH_SPEED == 1
#define SPEED 0x4
#else
#define SPEED 0
#endif

#define RX_PIN TRISC7
#define TX_PIN TRISC6
	
/* Serial initialization */
#define INIT_COMMS()\
	RX_PIN = 1;	\
	TX_PIN = 1;		  \
	SPBRG = DIVIDER;     	\
	RCSTA = (NINE_BITS|0x90);	\
	TXSTA = (SPEED|NINE_BITS|0x20)

#ifndef NOP()
#define NOP()	asm("nop")
#endif

#ifndef RESET()
#define RESET()	asm("ljmp 0")
#endif

/* expressions used in the code */
#define FLASH EEPGD==1
#define EEPROM EEPGD==0
#ifdef IRREG_START
#define LOADER_SAFE ((EEPROM) || (EEADRH < (BOOT_START >> 8)) || ((EEADRH == (BOOT_START >> 8)) && (EEADR < (BOOT_START & 0xFF))) )
#else
#define LOADER_SAFE ((EEPROM)||(EEADRH < (BOOT_START >> 8)))
#endif

#define OK_BIT 0x80

/* stop & start controls for HyperTerminal */
#define XON	17
#define XOFF	19

#endif

⌨️ 快捷键说明

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