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

📄 avrbootloader.lst

📁 BootLoad_Pei&Ecirc &Ccedil ICC&micro &Auml &Ocirc &acute &acute ú&Acirc &euml &pound &not MegaLoad
💻 LST
📖 第 1 页 / 共 2 页
字号:
__start:
__text_start:
    0E13 E001      LDI	R16,1
    0E14 BF05      OUT	0x35,R16
    0E15 E002      LDI	R16,2
    0E16 BF05      OUT	0x35,R16
    0E17 E5CF      LDI	R28,0x5F
    0E18 E0D4      LDI	R29,4
    0E19 BFCD      OUT	0x3D,R28
    0E1A BFDE      OUT	0x3E,R29
    0E1B 51C0      SUBI	R28,0x10
    0E1C 40D0      SBCI	R29,0
    0E1D EA0A      LDI	R16,0xAA
    0E1E 8308      STD	Y+0,R16
    0E1F 2400      CLR	R0
    0E20 E6E0      LDI	R30,0x60
    0E21 E0F0      LDI	R31,0
    0E22 E010      LDI	R17,0
    0E23 3AE2      CPI	R30,0xA2
    0E24 07F1      CPC	R31,R17
    0E25 F011      BEQ	0x0E28
    0E26 9201      ST	R0,Z+
    0E27 CFFB      RJMP	0x0E23
    0E28 8300      STD	Z+0,R16
    0E29 E2E6      LDI	R30,0x26
    0E2A E1FC      LDI	R31,0x1C
    0E2B E6A0      LDI	R26,0x60
    0E2C E0B0      LDI	R27,0
    0E2D E11C      LDI	R17,0x1C
    0E2E 32E6      CPI	R30,0x26
    0E2F 07F1      CPC	R31,R17
    0E30 F021      BEQ	0x0E35
    0E31 95C8      LPM
    0E32 9631      ADIW	R30,1
    0E33 920D      ST	R0,X+
    0E34 CFF9      RJMP	0x0E2E
    0E35 D0D1      RCALL	_main
_exit:
    0E36 CFFF      RJMP	_exit
FILE: D:\IccAvr\Pei\BootLoad_Pei\main.c
(0001) /******************************************************************************
(0002) Atmega8、16 BootLoad程序  
(0003) 日  期:2004年的最后一天
(0004) 肖  鹏  www.527dz.com  527dz@527dz.com
(0005) 
(0006) /*****************************************************************************/
(0007) 
(0008) //修改pei2005.6.24
(0009) //1.针对W0和W1的硬件进行修改,主要是使用晶振、修改Baud、关无线模块
(0010) //2.增加:用户区无程序时不跳出Boot循环
(0011) //3.修正Bug:原GetPageNumber()由于移位的原因,PageAddress!=0xffff,即FlashLoad()无法退出
(0012) //4.增加:Page地址比较重要,也要效验,添加到GetPage()中
(0013) 
(0014) #include <macros.h>
(0015) #include "assembly.h"
(0016) 
(0017) #define W0
(0018) //×××××××××××××××××××××××××××××××××××××××××××××××××××××××××
(0019) //请根据目标板选择芯片型号
(0020) #ifdef W0
(0021)  #define  ChipType     Atmega8
(0022) #else       
(0023)  #define  ChipType     Atmega16
(0024) #endif       
(0025) //#define  ChipType     Atmega32       
(0026) //#define  ChipType     Atmega64       
(0027) //#define  ChipType     Atmega128       
(0028) //#define  ChipType     Atmega8535       
(0029) //*********************************************************
(0030) //选择BOOT区大小
(0031) //#define  BootSize     'a'    //128   
(0032) //#define  BootSize     'b'    //256
(0033) #define  BootSize       'c'    //512
(0034) //#define  BootSize     'd'    //1024
(0035) //#define  BootSize     'e'    //2048(不知道是否有2048字BOOT空间的芯片)
(0036) //选择BootLoad版本号
(0037) //#define  BootVer        'f'    //1.0版本
(0038) #define  BootVer      'g'    //1.1版本 pei
(0039) //#define  BootVer      'h'    //1.2版本
(0040) //#define  BootVer      'i'    //1.3版本
(0041) //#define  BootVer      'j'    //1.4版本
(0042) //#define  BootVer      'k'    //1.5版本
(0043) //#define  BootVer      'l'    //1.6版本
(0044) //#define  BootVer      'm'    //1.7版本
(0045) //#define  BootVer      'n'    //1.8版本
(0046) //#define  BootVer      'o'    //1.9版本
(0047) //#define  BootVer      'p'    //2.0版本(应该是最终版本了)
(0048) //**********************************************************
(0049) #define  Atmega8        0x30
(0050) #define  Atmega16       0x31
(0051) #define  Atmega32       0x32
(0052) #define  Atmega64       0x33
(0053) #define  Atmega128      0x34
(0054) #define  Atmega8535     0x35
(0055) //*****************************************************************************
(0056) //#define  InteClk                 //是否使用内部时钟
(0057) #define  OscAddress     0x1fff   //时钟校准值存储地址
(0058) //#define  OscAddress     0x3fff   //时钟校准值存储地址
(0059) //*****************************************************************************
(0060) //8时钟下的波特率设置
(0061) //#define  BAU  103    //4800
(0062) //#define  BAU  51       //9600
(0063) //#define  BAU  34     //14400
(0064) //#define  BAU  25     //19200
(0065) //*****************************************************************************
(0066) 
(0067) //11.0592M pei
(0068) #define BAU 35 //pei baud19200
(0069) //#define BAU 17 //pei baud38400
(0070) 
(0071) #if (ChipType == Atmega8)
(0072)   #include  "iom8v.h"
(0073)   #define   PageByte 	 	 64 
(0074)   #define   AddressShift	 6
(0075) #endif
(0076) 
(0077) #if (ChipType == Atmega16)
(0078)   #include  "iom16v.h"
(0079)   #define   PageByte 	 	 128    
(0080)   #define   AddressShift 	 7
(0081) #endif
(0082) 
(0083) void          FlashLoad        (void);
(0084) void          GetPageNumber    (void);
(0085) void          ExecCode         (void);
(0086) char          GetPage          (void);
(0087) void          WriteFlash       (void);
(0088) char          CheckFlash       (void);
(0089) void          SendChar         (unsigned char c);
(0090) void          delay            (void);                 //1ms延时函数
(0091) unsigned char RecChar          (void);
(0092) 
(0093) unsigned char PageBuffer[PageByte];
(0094) unsigned int  PageAddress;
(0095) 
(0096) /*****************************************************************************/
(0097) //Flash编程								                     
(0098) /*****************************************************************************/
(0099) void FlashLoad(void)
(0100)   {unsigned char AddH,AddL;
(0101)     SendChar('!');
_FlashLoad:
  AddL                 --> Y+1
  AddH                 --> Y+1
    0E37 E201      LDI	R16,0x21
    0E38 D0B9      RCALL	_SendChar
    0E39 C018      RJMP	0x0E52
(0102)     while (1)
(0103)       {
(0104) 	//GetPageNumber();//bug!由于移位的原因,PageAddress!=0xffff
(0105) 	//if (PageAddress == 0xffff) return;//退不出了:) 
(0106)         
(0107) 	if (GetPage())
    0E3A D019      RCALL	_GetPage
    0E3B 2300      TST	R16
    0E3C F099      BEQ	0x0E50
(0108) 	  { 
(0109) 	    if (PageAddress == 0xffff) return;//pei Page地址读取和判断加到GetPage()中了
    0E3D 91800060  LDS	R24,PageAddress
    0E3F 91900061  LDS	R25,PageAddress+1
    0E41 3F8F      CPI	R24,0xFF
    0E42 EFEF      LDI	R30,0xFF
    0E43 079E      CPC	R25,R30
    0E44 F409      BNE	0x0E46
    0E45 C00D      RJMP	0x0E53
(0110) 	  
(0111) 	    WriteFlash();
    0E46 D04A      RCALL	_WriteFlash
(0112) 	    if (CheckFlash()) SendChar('!');
    0E47 D076      RCALL	_CheckFlash
    0E48 2300      TST	R16
    0E49 F019      BEQ	0x0E4D
    0E4A E201      LDI	R16,0x21
    0E4B D0A6      RCALL	_SendChar
    0E4C C005      RJMP	0x0E52
(0113) 	    else SendChar('@');
    0E4D E400      LDI	R16,0x40
    0E4E D0A3      RCALL	_SendChar
(0114) 	  }
    0E4F C002      RJMP	0x0E52
(0115) 	else SendChar('@');
    0E50 E400      LDI	R16,0x40
    0E51 D0A0      RCALL	_SendChar
    0E52 CFE7      RJMP	0x0E3A
    0E53 9508      RET
_GetPage:
  CheckSum             --> R20
  AddL                 --> R22
  AddH                 --> R12
  LocalCheckSum        --> R10
  i                    --> R22
    0E54 D12E      RCALL	push_gset4
(0116)       }
(0117)   }
(0118) 
(0119) /****************************************************************************
(0120) void GetPageNumber(void)
(0121)   {
(0122)     unsigned char PageAddressH;
(0123)     unsigned char PageAddressL;
(0124) 
(0125)     PageAddressH = RecChar();
(0126) 
(0127)     PageAddressL = RecChar();
(0128) 	
(0129) 	PageAddress=((int)((PageAddressH << 8) + PageAddressL))<<AddressShift;
(0130)   }
(0131) 
(0132) /*****************************************************************************/
(0133) char GetPage(void)
(0134)   {
(0135)     unsigned char i,AddH,AddL;
(0136)     unsigned char LocalCheckSum = 0;
    0E55 24AA      CLR	R10
(0137)     unsigned char CheckSum = 0;
    0E56 2744      CLR	R20
(0138) 
(0139) 	AddH=RecChar();AddL=RecChar();
    0E57 D096      RCALL	_RecChar
    0E58 2EC0      MOV	R12,R16
    0E59 D094      RCALL	_RecChar
    0E5A 2F60      MOV	R22,R16
(0140) 	PageAddress=(AddH<<8)+AddL;
    0E5B 2C3C      MOV	R3,R12
    0E5C 2E26      MOV	R2,R22
    0E5D 92300061  STS	PageAddress+1,R3
    0E5F 92200060  STS	PageAddress,R2
(0141) 	if (PageAddress==0xffff) return 1;//exit..
    0E61 01C1      MOVW	R24,R2
    0E62 3F8F      CPI	R24,0xFF
    0E63 EFEF      LDI	R30,0xFF
    0E64 079E      CPC	R25,R30
    0E65 F411      BNE	0x0E68
    0E66 E001      LDI	R16,1
    0E67 C027      RJMP	0x0E8F
(0142) 	PageAddress=PageAddress<<AddressShift;
    0E68 E026      LDI	R18,6
    0E69 E030      LDI	R19,0
    0E6A 91000060  LDS	R16,PageAddress
    0E6C 91100061  LDS	R17,PageAddress+1
    0E6E D131      RCALL	lsl16
    0E6F 93100061  STS	PageAddress+1,R17
    0E71 93000060  STS	PageAddress,R16
(0143) 	LocalCheckSum=AddH+AddL;//pei考虑Page的效验
    0E73 2CAC      MOV	R10,R12
    0E74 0EA6      ADD	R10,R22
(0144) 	
(0145)     for (i=0;i<PageByte;i++)
    0E75 2766      CLR	R22
    0E76 C00F      RJMP	0x0E86
(0146) 	{
(0147) 	PageBuffer[i]=RecChar();
    0E77 D076      RCALL	_RecChar
    0E78 E682      LDI	R24,0x62
    0E79 E090      LDI	R25,0
    0E7A 2FE6      MOV	R30,R22
    0E7B 27FF      CLR	R31
    0E7C 0FE8      ADD	R30,R24
    0E7D 1FF9      ADC	R31,R25
    0E7E 8300      STD	Z+0,R16
(0148) 	LocalCheckSum += PageBuffer[i];
    0E7F 2FE6      MOV	R30,R22
    0E80 27FF      CLR	R31
    0E81 0FE8      ADD	R30,R24
    0E82 1FF9      ADC	R31,R25
    0E83 8020      LDD	R2,Z+0
    0E84 0CA2      ADD	R10,R2
    0E85 9563      INC	R22
    0E86 3460      CPI	R22,0x40
    0E87 F378      BCS	0x0E77
(0149)    	}
(0150) 		   
(0151)     CheckSum = RecChar(); 
    0E88 D065      RCALL	_RecChar
    0E89 2F40      MOV	R20,R16
(0152)     if (LocalCheckSum == CheckSum) return 1;
    0E8A 16A0      CP	R10,R16
    0E8B F411      BNE	0x0E8E
    0E8C E001      LDI	R16,1
    0E8D C001      RJMP	0x0E8F
(0153)     else return 0;
    0E8E 2700      CLR	R16
    0E8F D0EF      RCALL	pop_gset4
    0E90 9508      RET
_WriteFlash:
  TempInt              --> R20
  i                    --> R22
    0E91 D0F5      RCALL	push_gset2
(0154)   }
(0155) 
(0156) /*****************************************************************************/
(0157) void WriteFlash(void)
(0158)   {
(0159)     unsigned int i;
(0160)     unsigned int TempInt;
(0161) 
(0162)     for (i=0;i<PageByte;i+=2)
    0E92 2766      CLR	R22
    0E93 2777      CLR	R23
    0E94 C016      RJMP	0x0EAB
(0163)       {
(0164)    	TempInt=PageBuffer[i]+(PageBuffer[i+1]<<8);
    0E95 E682      LDI	R24,0x62
    0E96 E090      LDI	R25,0
    0E97 01FB      MOVW	R30,R22
    0E98 9631      ADIW	R30,1
    0E99 0FE8      ADD	R30,R24
    0E9A 1FF9      ADC	R31,R25
    0E9B 8020      LDD	R2,Z+0
    0E9C 2433      CLR	R3
    0E9D 2C32      MOV	R3,R2
    0E9E 2422      CLR	R2
    0E9F 01FB      MOVW	R30,R22
    0EA0 0FE8      ADD	R30,R24
    0EA1 1FF9      ADC	R31,R25
    0EA2 8140      LDD	R20,Z+0
    0EA3 2755      CLR	R21
    0EA4 0D42      ADD	R20,R2
    0EA5 1D53      ADC	R21,R3
(0165)    	fill_temp_buffer(TempInt,i);    //call asm routine.
    0EA6 019B      MOVW	R18,R22
    0EA7 018A      MOVW	R16,R20
    0EA8 D0B3      RCALL	_fill_temp_buffer
    0EA9 5F6E      SUBI	R22,0xFE
    0EAA 4F7F      SBCI	R23,0xFF
    0EAB 3460      CPI	R22,0x40
    0EAC E0E0      LDI	R30,0
    0EAD 077E      CPC	R23,R30
    0EAE F330      BCS	0x0E95
(0166)       }
(0167) 	
(0168)     write_page(PageAddress,0x03);       //擦除页
    0EAF E023      LDI	R18,3
    0EB0 91000060  LDS	R16,PageAddress
    0EB2 91100061  LDS	R17,PageAddress+1
    0EB4 D0A1      RCALL	_write_page
(0169)     write_page(PageAddress,0x05);       //写页数据
    0EB5 E025      LDI	R18,5
    0EB6 91000060  LDS	R16,PageAddress
    0EB8 91100061  LDS	R17,PageAddress+1
    0EBA D09B      RCALL	_write_page
(0170)    
(0171)     enableRWW();
    0EBB D0B4      RCALL	_enableRWW
    0EBC D0BE      RCALL	pop_gset2
    0EBD 9508      RET
_CheckFlash:
  TempInt2             --> R20
  TempInt              --> R22
  i                    --> R10
    0EBE D0C6      RCALL	push_gset3
(0172)   }
(0173) 
(0174) /*****************************************************************************/
(0175) 
(0176) char CheckFlash(void)
(0177)   {
(0178)     unsigned char i;							
(0179)     unsigned int TempInt;
(0180)     unsigned int TempInt2;
(0181) 
(0182)     for (i=0;i<PageByte;i+=2)
    0EBF 24AA      CLR	R10
    0EC0 C027      RJMP	0x0EE8
(0183)       {
(0184) 	TempInt = read_program_memory(PageAddress + i,0x00);
    0EC1 2722      CLR	R18
    0EC2 2C2A      MOV	R2,R10
    0EC3 2433      CLR	R3
    0EC4 91000060  LDS	R16,PageAddress
    0EC6 91100061  LDS	R17,PageAddress+1
    0EC8 0D02      ADD	R16,R2
    0EC9 1D13      ADC	R17,R3
    0ECA D09E      RCALL	_read_program_memory
    0ECB 01B8      MOVW	R22,R16
(0185) 	TempInt2 = PageBuffer[i] +(PageBuffer[i+1]<<8);
    0ECC E683      LDI	R24,0x63
    0ECD E090      LDI	R25,0
    0ECE 2DEA      MOV	R30,R10
    0ECF 27FF      CLR	R31
    0ED0 0FE8      ADD	R30,R24
    0ED1 1FF9      ADC	R31,R25
    0ED2 8020      LDD	R2,Z+0
    0ED3 2433      CLR	R3
    0ED4 2C32      MOV	R3,R2
    0ED5 2422      CLR	R2

⌨️ 快捷键说明

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