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

📄 main.s

📁 ATmal mega88 芯片的bootload源程序
💻 S
📖 第 1 页 / 共 2 页
字号:
	.module main.c
	.area text(rom, con, rel)
	.dbfile F:\程序\新建文~1\BootLoad_88可用\main.c
	.dbfunc e FlashLoad _FlashLoad fV
;           AddL -> <dead>
;           AddH -> <dead>
	.even
_FlashLoad::
	.dbline -1
	.dbline 100
; /******************************************************************************
; Atmega8、16 BootLoad程序  
; 日  期:2004年的最后一天
; 肖  鹏  www.527dz.com  527dz@527dz.com
; 
; /*****************************************************************************/
; 
; //修改pei2005.6.24
; //1.针对W0和W1的硬件进行修改,主要是使用晶振、修改Baud、关无线模块
; //2.增加:用户区无程序时不跳出Boot循环
; //3.修正Bug:原GetPageNumber()由于移位的原因,PageAddress!=0xffff,即FlashLoad()无法退出
; //4.增加:Page地址比较重要,也要效验,添加到GetPage()中
; 
; #include <macros.h>
; #include "assembly.h"
; 
; //#define W0
; //×××××××××××××××××××××××××××××××××××××××××××××××××××××××××
; //请根据目标板选择芯片型号
; #ifdef W0
;  #define  ChipType     Atmega8
; #else       
;  #define  ChipType     Atmega16
; #endif       
; //#define  ChipType     Atmega32       
; //#define  ChipType     Atmega64       
; //#define  ChipType     Atmega128       
; //#define  ChipType     Atmega8535       
; //*********************************************************
; //选择BOOT区大小
; //#define  BootSize     'a'    //128   
; //#define  BootSize     'b'    //256
; #define  BootSize       'c'    //512
; //#define  BootSize     'd'    //1024
; //#define  BootSize     'e'    //2048(不知道是否有2048字BOOT空间的芯片)
; //选择BootLoad版本号
; //#define  BootVer        'f'    //1.0版本
; #define  BootVer      'g'    //1.1版本 pei
; //#define  BootVer      'h'    //1.2版本
; //#define  BootVer      'i'    //1.3版本
; //#define  BootVer      'j'    //1.4版本
; //#define  BootVer      'k'    //1.5版本
; //#define  BootVer      'l'    //1.6版本
; //#define  BootVer      'm'    //1.7版本
; //#define  BootVer      'n'    //1.8版本
; //#define  BootVer      'o'    //1.9版本
; //#define  BootVer      'p'    //2.0版本(应该是最终版本了)
; //**********************************************************
; #define  Atmega8        0x30
; #define  Atmega16       0x31
; #define  Atmega32       0x32
; #define  Atmega64       0x33
; #define  Atmega128      0x34
; #define  Atmega8535     0x35
; //*****************************************************************************
; //#define  InteClk                 //是否使用内部时钟
; #define  OscAddress     0x1fff   //时钟校准值存储地址
; //#define  OscAddress     0x3fff   //时钟校准值存储地址
; //*****************************************************************************
; //8时钟下的波特率设置
; //#define  BAU  103    //4800
; #define  BAU  51       //9600
; //#define  BAU  34     //14400
; //#define  BAU  25     //19200
; //*****************************************************************************
; 
; //11.0592M pei
; //#define BAU 35 //pei baud19200
; //#define BAU 17 //pei baud38400
; 
; #if (ChipType == Atmega8)
;   #include  "iom88v.h"
;   #define   PageByte 	 	 64 
;   #define   AddressShift	 6
; #endif
; 
; #if (ChipType == Atmega16)
;   #include  "iom168v.h"
;   #define   PageByte 	 	 128    
;   #define   AddressShift 	 7
; #endif
; 
; void          FlashLoad        (void);
; void          GetPageNumber    (void);
; void          ExecCode         (void);
; char          GetPage          (void);
; void          WriteFlash       (void);
; char          CheckFlash       (void);
; void          SendChar         (unsigned char c);
; void          delay            (void);                 //1ms延时函数
; unsigned char RecChar          (void);
; 
; unsigned char PageBuffer[PageByte];
; unsigned int  PageAddress;
; 
; /*****************************************************************************/
; //Flash编程								                     
; /*****************************************************************************/
; void FlashLoad(void)
;   {unsigned char AddH,AddL;
	.dbline 101
;     SendChar('!');
	ldi R16,33
	xcall _SendChar
	xjmp L3
L2:
	.dbline 103
;     while (1)
;       {
	.dbline 107
; 	//GetPageNumber();//bug!由于移位的原因,PageAddress!=0xffff
; 	//if (PageAddress == 0xffff) return;//退不出了:) 
;         
; 	if (GetPage())
	xcall _GetPage
	tst R16
	breq L5
X0:
	.dbline 108
; 	  { 
	.dbline 109
; 	    if (PageAddress == 0xffff) return;//pei Page地址读取和判断加到GetPage()中了
	lds R24,_PageAddress
	lds R25,_PageAddress+1
	cpi R24,255
	ldi R30,255
	cpc R25,R30
	brne L7
X1:
	.dbline 109
	xjmp L1
L7:
	.dbline 111
; 	  
; 	    WriteFlash();
	xcall _WriteFlash
	.dbline 112
; 	    if (CheckFlash()) SendChar('!');
	xcall _CheckFlash
	tst R16
	breq L9
X2:
	.dbline 112
	ldi R16,33
	xcall _SendChar
	xjmp L6
L9:
	.dbline 113
; 	    else SendChar('@');
	ldi R16,64
	xcall _SendChar
	.dbline 114
; 	  }
	xjmp L6
L5:
	.dbline 115
; 	else SendChar('@');
	ldi R16,64
	xcall _SendChar
L6:
	.dbline 116
;       }
L3:
	.dbline 102
	xjmp L2
X3:
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbsym l AddL 1 c
	.dbsym l AddH 1 c
	.dbend
	.dbfunc e GetPage _GetPage fc
;           AddL -> R20
;           AddH -> R14
;       CheckSum -> R12
;  LocalCheckSum -> R10
;              i -> R20
	.even
_GetPage::
	xcall push_xgset30FC
	.dbline -1
	.dbline 134
;   }
; 
; /****************************************************************************
; void GetPageNumber(void)
;   {
;     unsigned char PageAddressH;
;     unsigned char PageAddressL;
; 
;     PageAddressH = RecChar();
; 
;     PageAddressL = RecChar();
; 	
; 	PageAddress=((int)((PageAddressH << 8) + PageAddressL))<<AddressShift;
;   }
; 
; /*****************************************************************************/
; char GetPage(void)
;   {
	.dbline 136
;     unsigned char i,AddH,AddL;
;     unsigned char LocalCheckSum = 0;
	clr R10
	.dbline 137
;     unsigned char CheckSum = 0;
	clr R12
	.dbline 139
; 
; 	AddH=RecChar();AddL=RecChar();
	xcall _RecChar
	mov R14,R16
	.dbline 139
	xcall _RecChar
	mov R20,R16
	.dbline 140
; 	PageAddress=(AddH<<8)+AddL;
	mov R3,R14
	mov R2,R20
	sts _PageAddress+1,R3
	sts _PageAddress,R2
	.dbline 141
; 	if (PageAddress==0xffff) return 1;//exit..
	movw R24,R2
	cpi R24,255
	ldi R30,255
	cpc R25,R30
	brne L12
X4:
	.dbline 141
	ldi R16,1
	xjmp L11
L12:
	.dbline 142
; 	PageAddress=PageAddress<<AddressShift;
	ldi R18,7
	ldi R19,0
	lds R16,_PageAddress
	lds R17,_PageAddress+1
	xcall lsl16
	sts _PageAddress+1,R17
	sts _PageAddress,R16
	.dbline 145
; //	LocalCheckSum=AddH+AddL;//pei考虑Page的效验
; 	
;     for (i=0;i<PageByte;i++)
	clr R20
	xjmp L17
L14:
	.dbline 146
; 	{
	.dbline 147
; 	PageBuffer[i]=RecChar();
	xcall _RecChar
	mov R14,R16
	ldi R24,<_PageBuffer
	ldi R25,>_PageBuffer
	mov R30,R20
	clr R31
	add R30,R24
	adc R31,R25
	std z+0,R14
	.dbline 148
; 	LocalCheckSum += PageBuffer[i];
	mov R30,R20
	clr R31
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	add R10,R2
	.dbline 149
;    	}
L15:
	.dbline 145
	inc R20
L17:
	.dbline 145
	cpi R20,128
	brlo L14
X5:
	.dbline 151
; 		   
;     CheckSum = RecChar(); 
	xcall _RecChar
	mov R14,R16
	mov R12,R14
	.dbline 152
;     if (LocalCheckSum == CheckSum) return 1;
	cp R10,R16
	brne L18
X6:
	.dbline 152
	ldi R16,1
	xjmp L11
L18:
	.dbline 153
;     else return 0;
	clr R16
	.dbline -2
L11:
	.dbline 0 ; func end
	xjmp pop_xgset30FC
	.dbsym r AddL 20 c
	.dbsym r AddH 14 c
	.dbsym r CheckSum 12 c
	.dbsym r LocalCheckSum 10 c
	.dbsym r i 20 c
	.dbend
	.dbfunc e WriteFlash _WriteFlash fV
;        TempInt -> R10,R11
;              i -> R20,R21
	.even
_WriteFlash::
	xcall push_xgset300C
	.dbline -1
	.dbline 158
;   }
; 
; /*****************************************************************************/
; void WriteFlash(void)
;   {
	.dbline 162
;     unsigned int i;
;     unsigned int TempInt;
; 
;     for (i=0;i<PageByte;i+=2)
	clr R20
	clr R21
	xjmp L24
L21:
	.dbline 163
;       {
	.dbline 164
;    	TempInt=PageBuffer[i]+(PageBuffer[i+1]<<8);
	ldi R24,<_PageBuffer
	ldi R25,>_PageBuffer
	movw R30,R20
	adiw R30,1
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	clr R3
	mov R3,R2
	clr R2
	movw R30,R20
	add R30,R24
	adc R31,R25
	ldd R10,z+0
	clr R11
	add R10,R2
	adc R11,R3
	.dbline 165
;    	fill_temp_buffer(TempInt,i);    //call asm routine.
	movw R18,R20
	movw R16,R10
	xcall _fill_temp_buffer
	.dbline 166
;       }
L22:
	.dbline 162
	subi R20,254  ; offset = 2
	sbci R21,255
L24:
	.dbline 162
	cpi R20,128
	ldi R30,0
	cpc R21,R30
	brlo L21
X7:
	.dbline 168
; 	
;     write_page(PageAddress,0x03);       //擦除页
	ldi R18,3
	lds R16,_PageAddress
	lds R17,_PageAddress+1
	xcall _write_page
	.dbline 169
;     write_page(PageAddress,0x05);       //写页数据
	ldi R18,5
	lds R16,_PageAddress
	lds R17,_PageAddress+1
	xcall _write_page
	.dbline 171
;    
;     enableRWW();
	xcall _enableRWW
	.dbline -2
L20:
	.dbline 0 ; func end
	xjmp pop_xgset300C
	.dbsym r TempInt 10 i
	.dbsym r i 20 i
	.dbend
	.dbfunc e CheckFlash _CheckFlash fc
;       TempInt2 -> R12,R13
;        TempInt -> R10,R11
;              i -> R20
	.even

⌨️ 快捷键说明

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