本帖最后由 457878 于 2012-5-9 15:27 编辑
按这个思路,芯片不用复位,即可实现BootLoader下载,欢迎砸砖:
/***********************************************************
芯片:PIC16F721
0010 main()
0100 DoUpdate()
0800 DoApp()
只要 “应用工程” 的Main函数指定在0x0800,即可实现BootLoader下载。
***********************************************************/
#include <pic.h>
typedef bit BOOL;
__CONFIG(0x3FB4); //normal configuration
__CONFIG(0x3FFD); //boot code protection
//__IDLOC(1234);
BOOL bUpdate = 0;
BOOL DoUpdate(void) @ 0x0100;
void DoApp(void) @ 0x0800;
void main(void) @ 0x0010
{
RESET:
NOP();
NOP();
if(!bUpdate)
{ goto NORMAL;
}
while(1)
{ if(DoUpdate() ==1)
{ bUpdate = 0;
break;
}
}
NORMAL:
while(1)
{ NOP();
DoApp();
if(bUpdate)
{ NOP();
goto RESET;
}
}
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++ bootloader
BOOL DoUpdate(void) @ 0x0100
{ return(1);
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++ application
void DoApp(void) @ 0x0800
{ //Dosomething..
bUpdate = 1;
}
|