|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2006-4-19 11:34:52
|
显示全部楼层
I FOUND IT:
In every program the CodeVisionAVR C compiler automatically generates a code sequence to make the following initializations immediately after the AVR chip reset:
1. interrupt vector jump table
2. global interrupt disable
3. EEPROM access disable
4. Watchdog Timer disable
5. external SRAM access and wait state enable if necessary
6. clear the R2...R14 registers
7. clear the SRAM
8. initialize the global variables located in SRAM
9. initialize the Data Stack Pointer register Y
10. initialize the Stack Pointer register SP
11. initialize the UBRR register if necessary
The automatic generation of code sequences 2 to 8 can be disabled by checking the Code Generation|Use an External Startup Initialization File check box in the Project|Configure|C Compiler|Code Generation dialog window. The C compiler will then include, in the generated .asm file, the code sequences from an external file that must be named STARTUP.ASM . This file must be located in the directory where your main C source file resides.
You can write your own STARTUP.ASM file to customize or add some features to your program. The code sequences from this file will be immediately executed after the chip reset.
A basic STARTUP.ASM file is supplied with the compiler distribution and is located in the ..\BIN directory.
Here's the content of this file:
;CodeVisionAVR C Compiler
;(C) 1998-2004 Pavel Haiduc, HP InfoTech s.r.l.
;EXAMPLE STARTUP FILE FOR CodeVisionAVR V1.24.1 OR LATER
.EQU __CLEAR_START=0X60 ;START ADDRESS OF SRAM AREA TO CLEAR
;SET THIS ADDRESS TO 0X100 FOR THE
;ATmega128 OR ATmega64 CHIPS
.EQU __CLEAR_SIZE=256 ;SIZE OF SRAM AREA TO CLEAR IN BYTES
CLI ;DISABLE INTERRUPTS
CLR R30
OUT EECR,R30 ;DISABLE EEPROM ACCESS
;DISABLE THE WATCHDOG
LDI R31,0x18
OUT WDTCR,R31
OUT WDTCR,R30
OUT MCUCR,R30 ;MCUCR=0, NO EXTERNAL SRAM ACCESS
;CLEAR R2-R14
LDI R24,13
LDI R26,2
CLR R27
__CLEAR_REG:
ST X+,R30
DEC R24
BRNE __CLEAR_REG
;CLEAR SRAM
LDI R24,LOW(__CLEAR_SIZE)
LDI R25,HIGH(__CLEAR_SIZE)
LDI R26,LOW(__CLEAR_START)
LDI R27,HIGH(__CLEAR_START)
__CLEAR_SRAM:
ST X+,R30
SBIW R24,1
BRNE __CLEAR_SRAM
;GLOBAL VARIABLES INITIALIZATION
LDI R30,LOW(__GLOBAL_INI_TBL*2)
LDI R31,HIGH(__GLOBAL_INI_TBL*2)
__GLOBAL_INI_NEXT:
LPM
ADIW R30,1
MOV R24,R0
LPM
ADIW R30,1
MOV R25,R0
SBIW R24,0
BREQ __GLOBAL_INI_END
LPM
ADIW R30,1
MOV R26,R0
LPM
ADIW R30,1
MOV R27,R0
LPM
ADIW R30,1
MOV R1,R0
LPM
ADIW R30,1
MOV R22,R30
MOV R23,R31
MOV R31,R0
MOV R30,R1
__GLOBAL_INI_LOOP:
LPM
ADIW R30,1
ST X+,R0
SBIW R24,1
BRNE __GLOBAL_INI_LOOP
MOV R30,R22
MOV R31,R23
RJMP __GLOBAL_INI_NEXT
__GLOBAL_INI_END:
The __CLEAR_START and __CLEAR_SIZE constants can be changed to specify which area of SRAM to clear at program initialization.
The __GLOBAL_INI_TBL label must be located at the start of a table containing the information necessary to initialize the global variables located in SRAM. This table is automatically generated by the compiler. |
|