📄 main.lst
字号:
##############################################################################
# #
# IAR Atmel AVR C/C++ Compiler V4.11A/W32 17/Jan/2006 19:30:54 #
# Copyright 1996-2005 IAR Systems. All rights reserved. #
# #
# Source file = C:\Documents and Settings\andeaper\My #
# Documents\QVCS\Appnotes\AVR109 Self Programming\Source #
# Code\IAR\ATmega2560\main.c #
# Command line = "C:\Documents and Settings\andeaper\My #
# Documents\QVCS\Appnotes\AVR109 Self Programming\Source #
# Code\IAR\ATmega2560\main.c" --cpu=m2560 -ms -o #
# "C:\Documents and Settings\andeaper\My #
# Documents\QVCS\Appnotes\AVR109 Self Programming\Source #
# Code\IAR\ATmega2560\Debug\Obj\" -lCN "C:\Documents and #
# Settings\andeaper\My Documents\QVCS\Appnotes\AVR109 #
# Self Programming\Source Code\IAR\ATmega2560\Debug\List\ #
# " -y --initializers_in_flash -z2 --no_cse --no_inline #
# --no_code_motion --no_cross_call --no_clustering #
# --no_tbaa --cross_call_passes=4 --debug #
# -DENABLE_BIT_DEFINITIONS --do_cross_call -e -I #
# "C:\Program Files\IAR Systems\Embedded Workbench #
# 4.0\avr\INC\" -I "C:\Program Files\IAR #
# Systems\Embedded Workbench 4.0\avr\INC\CLIB\" #
# --eeprom_size 4096 #
# List file = C:\Documents and Settings\andeaper\My #
# Documents\QVCS\Appnotes\AVR109 Self Programming\Source #
# Code\IAR\ATmega2560\Debug\List\main.lst #
# Object file = C:\Documents and Settings\andeaper\My #
# Documents\QVCS\Appnotes\AVR109 Self Programming\Source #
# Code\IAR\ATmega2560\Debug\Obj\main.r90 #
# #
# #
##############################################################################
C:\Documents and Settings\andeaper\My Documents\QVCS\Appnotes\AVR109 Self Programming\Source Code\IAR\ATmega2560\main.c
1 /*****************************************************************************
2 *
3 * Atmel Corporation
4 *
5 * File : main.c
6 * Compiler : IAR C 3.10C Kickstart
7 * Revision : $Revision: 2.0 $
8 * Date : $Date: Tuesday, November 29, $
9 * Updated by : $Author: raapeland $
10 *
11 * Support mail : avr@atmel.com
12 *
13 * Target platform : All AVRs with bootloader support
14 *
15 * AppNote : AVR109 - Self-programming
16 *
17 * Description : This Program allows an AVR with bootloader capabilities to
18 * Read/write its own Flash/EEprom. To enter Programming mode
19 * an input pin is checked. If this pin is pulled low, programming mode
20 * is entered. If not, normal execution is done from $0000
21 * "reset" vector in Application area.
22 *
23 * Preparations : Use the preprocessor.xls file for obtaining a customized
24 * defines.h file and linker-file code-segment definition for
25 * the device you are compiling for.
26 ****************************************************************************/
27 #include <inavr.h>
28 #include "defines.h"
\ In segment ABSOLUTE, at 0x57
\ union <unnamed> volatile __io _A_SPMCSR
\ _A_SPMCSR:
\ 00000000 DS 1
\ In segment ABSOLUTE, at 0x41
\ union <unnamed> volatile __io _A_EEAR
\ _A_EEAR:
\ 00000000 DS 2
\ In segment ABSOLUTE, at 0x40
\ union <unnamed> volatile __io _A_EEDR
\ _A_EEDR:
\ 00000000 DS 1
\ In segment ABSOLUTE, at 0x3f
\ union <unnamed> volatile __io _A_EECR
\ _A_EECR:
\ 00000000 DS 1
\ In segment ABSOLUTE, at 0x2b
\ union <unnamed> volatile __io _A_PORTD
\ _A_PORTD:
\ 00000000 DS 1
\ In segment ABSOLUTE, at 0x29
\ union <unnamed> volatile __io _A_PIND
\ _A_PIND:
\ 00000000 DS 1
29 #include "serial.h"
30 #include "flash.h"
31
32
33 #ifndef EEWE
34 #define EEWE EEPE
35 #endif
36 #ifndef EEMWE
37 #define EEMWE EEMPE
38 #endif
39
40 /*** WARNING: The AVRprog application in AVR Studio does not support block mode,
41 but it will try to use it anyway. Therefore, block mode must be disabled below
42 if AVRprog is going to be used. ***/
43
44
45 /* Uncomment the following to save code space */
46 #define REMOVE_AVRPROG_SUPPORT
47 //#define REMOVE_FUSE_AND_LOCK_BIT_SUPPORT
48 //#define REMOVE_BLOCK_SUPPORT
49 //#define REMOVE_EEPROM_BYTE_SUPPORT
50 //#define REMOVE_FLASH_BYTE_SUPPORT
51
52
53
54 #ifndef REMOVE_BLOCK_SUPPORT
55 unsigned char BlockLoad(unsigned int size, unsigned char mem, long *address);
56 void BlockRead(unsigned int size, unsigned char mem, long *address);
57
58 /* BLOCKSIZE should be chosen so that the following holds: BLOCKSIZE*n = PAGESIZE, where n=1,2,3... */
59 #define BLOCKSIZE PAGESIZE
60
61 #endif
62
63
64
\ In segment FARCODE, align 2, keep-with-next
65 __C_task void main(void)
\ main:
66 {
\ 00000000 9724 SBIW R29:R28, 4
67 long address;
68 unsigned int temp_int;
69 unsigned char val;
70
71
72 /* Initialization */
73 void (*funcptr)( void ) = 0x0000; // Set up function pointer to RESET vector.
\ 00000002 E000 LDI R16, 0
\ 00000004 E010 LDI R17, 0
\ 00000006 E020 LDI R18, 0
\ 00000008 0128 MOVW R5:R4, R17:R16
\ 0000000A 2E62 MOV R6, R18
74 PROGPORT |= (1<<PROG_NO); // Enable pull-up on PROG_NO line on PROGPORT.
\ 0000000C 9A5C SBI 0x0B, 0x04
75 initbootuart(); // Initialize UART.
\ 0000000E ........ CALL initbootuart
76
77 /* Branch to bootloader or application code? */
78 if( !(PROGPIN & (1<<PROG_NO)) ) // If PROGPIN is pulled low, enter programmingmode.
\ 00000012 994C SBIC 0x09, 0x04
\ 00000014 C1E5 RJMP ??main_0
79 {
80 /* Main loop */
81 for(;;)
82 {
83 val=recchar(); // Wait for command character.
\ ??main_1:
\ 00000016 ........ CALL recchar
\ 0000001A 2FA0 MOV R26, R16
84
85 // Check autoincrement status.
86 if(val=='a')
\ 0000001C 36A1 CPI R26, 97
\ 0000001E F421 BRNE ??main_2
87 {
88 sendchar('Y'); // Yes, we do autoincrement.
\ 00000020 E509 LDI R16, 89
\ 00000022 ........ CALL sendchar
\ 00000026 CFF7 RJMP ??main_1
89 }
90
91
92 // Set address.
93 else if(val=='A') // Set address...
\ ??main_2:
\ 00000028 34A1 CPI R26, 65
\ 0000002A F491 BRNE ??main_3
94 { // NOTE: Flash addresses are given in words, not bytes.
95 unsigned char high = recchar();
\ 0000002C ........ CALL recchar
\ 00000030 2E70 MOV R7, R16
96 unsigned char low = recchar();
\ 00000032 ........ CALL recchar
\ 00000036 2FB0 MOV R27, R16
97 address = ((long)high<<8) | (long)low;
\ 00000038 2F0B MOV R16, R27
\ 0000003A 2D17 MOV R17, R7
\ 0000003C E020 LDI R18, 0
\ 0000003E E030 LDI R19, 0
\ 00000040 8308 ST Y, R16
\ 00000042 8319 STD Y+1, R17
\ 00000044 832A STD Y+2, R18
\ 00000046 833B STD Y+3, R19
98 sendchar('\r'); // Send OK back.
\ 00000048 E00D LDI R16, 13
\ 0000004A ........ CALL sendchar
\ 0000004E CFE3 RJMP ??main_1
99 }
100
101 // Set 24-bit address.
102 else if(val=='H')
\ ??main_3:
\ 00000050 34A8 CPI R26, 72
\ 00000052 F4A9 BRNE ??main_4
103 { // NOTE: Flash addresses are given in words, not bytes.
104 unsigned char highest = recchar();
\ 00000054 ........ CALL recchar
\ 00000058 2FB0 MOV R27, R16
105 unsigned char high = recchar();
\ 0000005A ........ CALL recchar
\ 0000005E 2E70 MOV R7, R16
106 unsigned char low = recchar();
\ 00000060 ........ CALL recchar
\ 00000064 2E80 MOV R8, R16
107 address = ((long)highest << 16) | ((long)high << 8) | (long)low;
\ 00000066 2D08 MOV R16, R8
\ 00000068 2D17 MOV R17, R7
\ 0000006A 2F2B MOV R18, R27
\ 0000006C E030 LDI R19, 0
\ 0000006E 8308 ST Y, R16
\ 00000070 8319 STD Y+1, R17
\ 00000072 832A STD Y+2, R18
\ 00000074 833B STD Y+3, R19
108 sendchar('\r'); // Send OK back.
\ 00000076 E00D LDI R16, 13
\ 00000078 ........ CALL sendchar
\ 0000007C CFCC RJMP ??main_1
109 }
110
111 // Chip erase.
112 else if(val=='e')
\ ??main_4:
\ 0000007E 36A5 CPI R26, 101
\ 00000080 F591 BRNE ??main_5
113 {
114 for(address = 0; address < APP_END;address += PAGESIZE)
\ 00000082 E000 LDI R16, 0
\ 00000084 E010 LDI R17, 0
\ 00000086 E020 LDI R18, 0
\ 00000088 E030 LDI R19, 0
\ 0000008A 8308 ST Y, R16
\ 0000008C 8319 STD Y+1, R17
\ 0000008E 832A STD Y+2, R18
\ 00000090 833B STD Y+3, R19
\ ??main_6:
\ 00000092 8108 LD R16, Y
\ 00000094 8119 LDD R17, Y+1
\ 00000096 812A LDD R18, Y+2
\ 00000098 813B LDD R19, Y+3
\ 0000009A 3000 CPI R16, 0
\ 0000009C EF40 LDI R20, 240
\ 0000009E 0714 CPC R17, R20
\ 000000A0 E043 LDI R20, 3
\ 000000A2 0724 CPC R18, R20
\ 000000A4 E040 LDI R20, 0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -