📄 bootloader.lst
字号:
__start:
__text_start:
1C2A E001 LDI R16,1
1C2B BF05 OUT 0x35,R16
1C2C E002 LDI R16,2
1C2D BF05 OUT 0x35,R16
1C2E E5CF LDI R28,0x5F
1C2F E0D4 LDI R29,4
1C30 BFCD OUT 0x3D,R28
1C31 BFDE OUT 0x3E,R29
1C32 51C0 SUBI R28,0x10
1C33 40D0 SBCI R29,0
1C34 EA0A LDI R16,0xAA
1C35 8308 STD Y+0,R16
1C36 2400 CLR R0
1C37 E6E0 LDI R30,0x60
1C38 E0F0 LDI R31,0
1C39 E010 LDI R17,0
1C3A 3EE4 CPI R30,0xE4
1C3B 07F1 CPC R31,R17
1C3C F011 BEQ 0x1C3F
1C3D 9201 ST R0,Z+
1C3E CFFB RJMP 0x1C3A
1C3F 8300 STD Z+0,R16
1C40 E5E4 LDI R30,0x54
1C41 E3F8 LDI R31,0x38
1C42 E6A0 LDI R26,0x60
1C43 E0B0 LDI R27,0
1C44 E318 LDI R17,0x38
1C45 35E4 CPI R30,0x54
1C46 07F1 CPC R31,R17
1C47 F021 BEQ 0x1C4C
1C48 95C8 LPM
1C49 9631 ADIW R30,1
1C4A 920D ST R0,X+
1C4B CFF9 RJMP 0x1C45
1C4C D11D RCALL _main
_exit:
1C4D CFFF RJMP _exit
FILE: D:\桌面\AVR_BO~1.2\bootloader\assembly.s
(0001) .text
(0002)
(0003) ;*********************************************************
(0004) ;*********************************************************
(0005) ;*********************************************************
(0006) ;*********************************************************
(0007) ; DO NOT CHANGE ANYTHING BELOW THIS LINE !!!!!!!
(0008) ;*********************************************************
(0009) ;*********************************************************
(0010) ;*********************************************************
(0011) ;*********************************************************
(0012)
(0013)
(0014) SPMCR = 0x57
(0015)
(0016)
(0017) ;-----------------------------------------
(0018)
(0019) ; void write_page (unsigned int adr, unsigned char function);
(0020) ; bits 8:15 adr addresses the page...(must setup RAMPZ beforehand!!!)
(0021) _write_page::
(0022) XCALL __WAIT_SPMEN__
_write_page:
1C4E D01F RCALL 0x1C6E
(0023) movw r30, r16 ;move address to z pointer (R31 = ZH, R30 = ZL)
1C4F 01F8 MOVW R30,R16
(0024) STS SPMCR, R18 ;argument 2 decides function
1C50 93200057 STS 0x57,R18
(0025) SPM ;perform pagewrite
1C52 95E8 SPM
(0026) RET
1C53 9508 RET
(0027)
(0028) ;-----------------------------------------
(0029)
(0030) ; void fill_temp_buffer (unsigned int data, unsigned int adr);
(0031) ; bits 7:1 in adr addresses the word in the page... (2=first word, 4=second word etc..)
(0032) _fill_temp_buffer::
(0033) XCALL __WAIT_SPMEN__
_fill_temp_buffer:
1C54 D019 RCALL 0x1C6E
(0034) movw r30, r18 ;move adress to z pointer (R31=ZH R30=ZL)
1C55 01F9 MOVW R30,R18
(0035) movw r0, r16 ;move data to reg 0 and 1
1C56 0108 MOVW R0,R16
(0036) LDI R19, 0x01
1C57 E031 LDI R19,1
(0037) STS SPMCR, R19
1C58 93300057 STS 0x57,R19
(0038) SPM ;Store program memory
1C5A 95E8 SPM
(0039) RET
1C5B 9508 RET
(0040)
(0041) ;-----------------------------------------
(0042)
(0043) ;unsigned char read_flash(unsigned int add);
(0044) _read_flash::
(0045) mov r31,r17
_read_flash:
1C5C 2FF1 MOV R31,R17
(0046) mov r30,r16
1C5D 2FE0 MOV R30,R16
(0047) lpm r16,z
1C5E 9104 LPM R16,0(Z)
(0048) clr r17
1C5F 2711 CLR R17
(0049) ret
1C60 9508 RET
(0050)
(0051) ;unsigned int read_program_memory (unsigned int adr ,unsigned char cmd);
(0052) _read_program_memory::
(0053) movw r30, r16 ;move adress to z pointer
_read_program_memory:
1C61 01F8 MOVW R30,R16
(0054) SBRC R18, 0 ;read lockbits? (second argument = 0x09)
1C62 FD20 SBRC R18,0
(0055) STS SPMCR, R18 ;if so, place second argument in SPMEN register
1C63 93200057 STS 0x57,R18
(0056) LPM r16, Z+
1C65 9105 LPM R16,Z+
(0057) LPM r17, Z
1C66 9114 LPM R17,0(Z)
(0058) RET
1C67 9508 RET
(0059)
(0060) ;-----------------------------------------
(0061)
(0062) _enableRWW::
(0063) XCALL __WAIT_SPMEN__
_enableRWW:
1C68 D005 RCALL 0x1C6E
(0064) LDI R27,0x11
1C69 E1B1 LDI R27,0x11
(0065) STS SPMCR,R27
1C6A 93B00057 STS 0x57,R27
(0066) SPM
1C6C 95E8 SPM
(0067) RET
1C6D 9508 RET
(0068)
(0069) ;-----------------------------------------
(0070)
(0071) __WAIT_SPMEN__:
(0072) LDS R27,SPMCR ; load SPMCR to R27
1C6E 91B00057 LDS R27,0x57
(0073) SBRC R27,0 ; check SPMEN flag
1C70 FDB0 SBRC R27,0
(0074) RJMP __WAIT_SPMEN__ ; wait for SPMEN flag cleared
1C71 CFFC RJMP 0x1C6E
(0075) RET
1C72 9508 RET
FILE: D:\桌面\AVR_BO~1.2\bootloader\main.c
(0001) /******************************************************************************
(0002) Atmega系列单片机 BootLoader程序
(0003) 日 期:2007年4月
(0004) 作 者:likeeavr
(0005) 版权所有:avrvi论坛
(0006)
(0007) 说明:当前版本只针对本论坛M16开发板
(0008)
(0009) 上位机借用了冯建辉的程序。
(0010)
(0011) /*****************************************************************************/
(0012) #include <macros.h>
(0013) #include "assembly.h"
(0014)
(0015) #define ChipType Atmega16
(0016)
(0017) //*********************************************************
(0018) //选择BOOT区大小 此必须与ICC options中的选项相对应
(0019) //#define BootSize 'a' //128
(0020) //#define BootSize 'b' //256
(0021) //#define BootSize 'c' //512
(0022) #define BootSize 'd' //1024
(0023) //选择BootLoad版本号
(0024) #define BootVer 'f' //1.0版本
(0025)
(0026) //**********************************************************
(0027)
(0028) #define Atmega16 0x31
(0029)
(0030) //*****************************************************************************
(0031) #define InteClk //是否使用内部时钟
(0032) #define OscAddress 0x1fff //时钟校准值存储地址
(0033)
(0034) //*****************************************************************************
(0035) //7.3728M时钟下的波特率为19200的设置,此设置可根据ICC生成,选对芯片,时钟,波特率既可
(0036) //由此语句调用UBRR = BAU;
(0037) #define BAU 23 // 7.3728M 19200
(0038) //#define BAU 191 // 7.3728M 2400
(0039) //#define BAU 95 // 7.3728M 4800
(0040) //#define BAU 47 // 7.3728M 9600
(0041) //#define BAU 31 // 7.3728M 14400
(0042) //#define BAU 23 // 7.3728M 19200
(0043) //#define BAU 15 // 7.3728M 28800
(0044)
(0045) //#define BAU 38 // 12M 19200
(0046)
(0047) //*****************************************************************************
(0048)
(0049) #include <iom16v.h>
(0050) #define PageByte 128
(0051) #define AddressShift 7
(0052) #define INTVECREG GICR
(0053)
(0054)
(0055) void FlashLoad (void);
(0056) void GetPageNumber (void);
(0057) void ExecCode (void);
(0058) char GetPage (void);
(0059) void WriteFlash (void);
(0060) char CheckFlash (void);
(0061) unsigned char IsChar (void);
(0062) void SendChar (unsigned char c);
(0063) void delay (void); //1ms延时函数
(0064) unsigned char RecChar (void);
(0065)
(0066) unsigned char PageBuffer[PageByte];
(0067) unsigned int RealPageAddress;
(0068) unsigned int PageAddress;
(0069)
(0070) /*****************************************************************************/
(0071) //Flash编程
(0072) /*****************************************************************************/
(0073) void FlashLoad(void)
(0074) {
(0075) SendChar('!');
_FlashLoad:
1C73 E201 LDI R16,0x21
1C74 D0E0 RCALL _SendChar
1C75 C019 RJMP 0x1C8F
(0076) while (1)
(0077) {
(0078) GetPageNumber();
1C76 D01A RCALL _GetPageNumber
(0079)
(0080) if (RealPageAddress == 0xffff)
1C77 91800062 LDS R24,RealPageAddress
1C79 91900063 LDS R25,RealPageAddress+1
1C7B 3F8F CPI R24,0xFF
1C7C EFEF LDI R30,0xFF
1C7D 079E CPC R25,R30
1C7E F409 BNE 0x1C80
(0081) return;
1C7F C010 RJMP 0x1C90
(0082)
(0083) if (GetPage())
1C80 D028 RCALL _GetPage
1C81 2300 TST R16
1C82 F051 BEQ 0x1C8D
(0084) {
(0085) WriteFlash();
1C83 D061 RCALL _WriteFlash
(0086) if (CheckFlash())
1C84 D093 RCALL _CheckFlash
1C85 2300 TST R16
1C86 F019 BEQ 0x1C8A
(0087) SendChar('!');
1C87 E201 LDI R16,0x21
1C88 D0CC RCALL _SendChar
1C89 C005 RJMP 0x1C8F
(0088) else
(0089) SendChar('@');
1C8A E400 LDI R16,0x40
1C8B D0C9 RCALL _SendChar
(0090) }
1C8C C002 RJMP 0x1C8F
(0091) else
(0092) SendChar('@');
1C8D E400 LDI R16,0x40
1C8E D0C6 RCALL _SendChar
1C8F CFE6 RJMP 0x1C76
1C90 9508 RET
_GetPageNumber:
PageAddressL --> R20
PageAddressH --> R22
1C91 940E1DBC CALL push_gset2
(0093) }
(0094) }
(0095)
(0096) /*****************************************************************************/
(0097) void GetPageNumber(void)
(0098) {
(0099) unsigned char PageAddressH;
(0100) unsigned char PageAddressL;
(0101)
(0102) PageAddressH = RecChar();
1C93 D0BD RCALL _RecChar
1C94 2F60 MOV R22,R16
(0103)
(0104) PageAddressL = RecChar();
1C95 D0BB RCALL _RecChar
1C96 2F40 MOV R20,R16
(0105)
(0106) RealPageAddress=(int)((PageAddressH << 8) + PageAddressL);
1C97 2E36 MOV R3,R22
1C98 2E24 MOV R2,R20
1C99 92300063 STS RealPageAddress+1,R3
1C9B 92200062 STS RealPageAddress,R2
(0107) PageAddress=RealPageAddress<<AddressShift;
1C9D E027 LDI R18,7
1C9E E030 LDI R19,0
1C9F 0181 MOVW R16,R2
1CA0 940E1DD5 CALL lsl16
1CA2 93100061 STS PageAddress+1,R17
1CA4 93000060 STS PageAddress,R16
1CA6 940E1DB0 CALL pop_gset2
1CA8 9508 RET
_GetPage:
CheckSum --> R20
LocalCheckSum --> R22
i --> R10
1CA9 940E1DBA CALL push_gset3
(0108) #ifdef RAMPZ_FLAG
(0109) if (PageAddressH)
(0110) RAMPZ = 1;
(0111) else
(0112) RAMPZ = 0;
(0113) #endif
(0114) }
(0115)
(0116) /*****************************************************************************/
(0117) char GetPage(void)
(0118) {
(0119) unsigned char i;
(0120) unsigned char LocalCheckSum = 0;
1CAB 2766 CLR R22
(0121) unsigned char CheckSum = 0;
1CAC 2744 CLR R20
(0122)
(0123) for (i=0;i<PageByte/2;i++)
1CAD 24AA CLR R10
1CAE C012 RJMP 0x1CC1
(0124) {
(0125) while(!IsChar());
1CAF D09B RCALL _IsChar
1CB0 2300 TST R16
1CB1 F3E9 BEQ 0x1CAF
(0126) PageBuffer[i]=RecChar();
1CB2 D09E RCALL _RecChar
1CB3 E684 LDI R24,0x64
1CB4 E090 LDI R25,0
1CB5 2DEA MOV R30,R10
1CB6 27FF CLR R31
1CB7 0FE8 ADD R30,R24
1CB8 1FF9 ADC R31,R25
1CB9 8300 STD Z+0,R16
(0127) LocalCheckSum ^= PageBuffer[i];
1CBA 2DEA MOV R30,R10
1CBB 27FF CLR R31
1CBC 0FE8 ADD R30,R24
1CBD 1FF9 ADC R31,R25
1CBE 8020 LDD R2,Z+0
1CBF 2562 EOR R22,R2
1CC0 94A3 INC R10
1CC1 2D8A MOV R24,R10
1CC2 3480 CPI R24,0x40
1CC3 F358 BCS 0x1CAF
(0128) }
(0129) for (i=0;i<PageByte/2;i++)
1CC4 24AA CLR R10
1CC5 C012 RJMP 0x1CD8
(0130) {
(0131) while(!IsChar());
1CC6 D084 RCALL _IsChar
1CC7 2300 TST R16
1CC8 F3E9 BEQ 0x1CC6
(0132) PageBuffer[i+PageByte/2]=RecChar();
1CC9 D087 RCALL _RecChar
1CCA EA84 LDI R24,0xA4
1CCB E090 LDI R25,0
1CCC 2DEA MOV R30,R10
1CCD 27FF CLR R31
1CCE 0FE8 ADD R30,R24
1CCF 1FF9 ADC R31,R25
1CD0 8300 STD Z+0,R16
(0133) LocalCheckSum ^= PageBuffer[i+PageByte/2];
1CD1 2DEA MOV R30,R10
1CD2 27FF CLR R31
1CD3 0FE8 ADD R30,R24
1CD4 1FF9 ADC R31,R25
1CD5 8020 LDD R2,Z+0
1CD6 2562 EOR R22,R2
1CD7 94A3 INC R10
1CD8 2D8A MOV R24,R10
1CD9 3480 CPI R24,0x40
1CDA F358 BCS 0x1CC6
(0134) }
(0135) CheckSum = RecChar();
1CDB D075 RCALL _RecChar
1CDC 2F40 MOV R20,R16
(0136)
(0137) if (LocalCheckSum == CheckSum)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -