ATMEL AVR start programming in C.pdf

(108 KB) Pobierz
AVR030: Getting Started with C for AVR Application Note
AVR030: Getting Started with C for AVR
Features
How to Open a New Project
Description of Option Settings
Linker Command File Examples
Writing and Compiling the C Code
How to Load the Executable File Into the
STK200 Starter Kit
Preparations
The IAR compiler is shipped with a hard-
ware lock dongle. This dongle must be
connected to the parallel port. Before the
dongle can be used, a windows driver
must be installed. Please see the
instructions included with the dongle for
how to install the windows driver.
8-bit
Microcontroller
Application
Note
Introduction
The purpose of this application note is to
guide new users through the initial set-
tings of the Embedded Workbench from
IAR and compile a simple C program.
The application note shows how to set
up the compiler to generate an execut-
able hex file and how to download this
file into the device. The example
described in this application note is writ-
ten for the AT90S2313 using the
STK200 starter kit or alternatively an
emulator.
Creating a New Project
When the preparations are ready, open
the IAR Embedded Workbench. To cre-
ate a new project, go to the “File” menu
and select “New” and then “Project . The
dialog box shown in Figure 1 appears. In
this dialog box, first make a folder
“C:\AVR030” and then type “Getting
Started” in the “File name” window. This
project should be created in the in the
“C:\AVR030” folder.
Figure 1. Create the Project File
Rev. 1483A–09/99
1
388319555.011.png 388319555.012.png
 
388319555.013.png 388319555.001.png 388319555.002.png 388319555.003.png
 
Settings in “Project-> Options”
Before any code can be compiled and linked, the options
for the compiler and linker must be set up correctly. By
default, it is possible to select two different targets in the
project window. The two selections are target “Release”,
and target “Debug”. The debug target is normally used
when running the code in a simulator or emulator, while the
release target is normally used when producing a code that
can be executed in a real device. The settings done in the
“Project->Options” menu are individual for both targets.
Thus, it is necessary to set all options twice when using
both targets. The main difference between the two targets
is the format of the output file.
It is also possible to add more targets which options can be
customized to a specific AVR (simulated, emulated or the
real device). Common and different source files may be
included in the different targets. A folder will be created for
each target when linked for the first time.
In this application note, the goal is to make a file that can
run in the AT90S2313 device. To do this, the release target
will be used. Select the “Release” target in the “Getting
started.prj” window as shown in Figure 2. Then select the
“Project->Options” menu. The window shown in Figure 3
will pop up.
Figure 2. Selecting Target Release
General Settings
In the General category in the “Options” dialog box, the
type of processor used is selected. It is necessary to
change two settings, Processor Configuration and “Mem-
ory Model . Please refer to Table 1 for the correct selection
for these choices for different AVR microcontrollers.
“Memory model tiny” uses a one byte data pointer, thus
allowing a maximum of 256 bytes data. “Memory model
small” uses a two byte data pointer, thus allowing up to 64
Kilobytes data. For the -v0 and -v2 “Processor Configura-
tion only the Memory model tiny” may be used.
In our example, the factory settings should be used, as
shown in Figure 3.
2
AVR030
388319555.004.png 388319555.005.png
AVR030
Figure 3. General Options Dialog
Table 1. Device Specific Settings
AVR Device
Processor Configuration
Memory Model
XCL file
AT90S2313
V0 (maximum 256 byte data, 8K code)
Tiny
2F128S.xcl
AT90S2323
V0 (max 256 byte data, 8K code)
Tiny
2F128S.xcl
AT90S2333
V0 (max 256 byte data, 8K code)
Tiny
2F128S.xcl
AT90S2343
V0 (max 256 byte data, 8K code)
Tiny
2F128S.xcl
AT90S4414
V1 (max 64 Kbyte data, 8K code)
Small
4F256S.xcl
4F64KS.xcl
AT90S4433
V0 (max 256 byte data, 8K code)
Tiny
4F128S.xcl
AT90S4434
V1 (max 64K byte data, 8K code)
Small
4F256S.xcl
AT90S8515
V1 (max 64K ‘byte data, 8K code)
Small
8F512S.xcl
8F64KS.xcl
AT90S8534
V1 (max 64K byte data, 8K code)
Small
8K256S.xcl
AT90S8535
V1 (max 64K byte data, 8K code)
Small
8F512S.xcl
3
388319555.006.png 388319555.007.png
Table 1. Device Specific Settings (Continued)
AVR Device
Processor Configuration
Memory Model
XCL file
ATmega103
V3 (max 64K byte data, 128K code)
Small
128F4KS.xcl
128F64KS.xcl
ATmega161
V3 (max 64K byte data, 128K code)
Small
16F1KS.xcl
16F64KS.xcl
ATmega603
V3 (max 64K byte data, 128K code)
Small
64F4KS.xcl
64F64KS.xcl
ICCA90 Settings
To get the dialog options for the specific settings of the
Compiler, click on the “ICCA90” line in the “Category” tab.
When using the memory model tiny , the factory settings are
OK.
If the memory model small is selected, it is necessary to
check the Writable strings, constants” checkbox. If this is
not done, variables defined as const will not be compiled
correctly. Figure 4 describes the settings when the memory
model small is selected.
The compiler may be optimized for code size or execution
speed. The type and level of optimization may be set in the
Optimization group in Figure 4. Only one type of optimiza-
tion may be specified for a single target. Note that if a high
level of optimization is used, the user may not be able to
debug the code. The code will be fully debuggable with
optimization level 3 (default for both types of optimization)
or lower.
Also note that it is strongly recommended that the “Embed
source” code checkbox in the “Debug tab is checked if a
debugging target, i.e. simulation or emulation, is used. This
will let you debug on the assembly level rather than on the
C language level. In AVR Studio you will also be able to
see exactly which assembly code is generated for the indi-
vidual C statements.
On the “List tab, the user is able to determine whether a
listing is generated, and the information included in this list-
ing. The Insert mnemonics option will, if checked, cause
the compiler to include the generated assembly lines in the
listing.
4
AVR030
388319555.008.png
AVR030
Figure 4. ICCA90 Option Settings
AA90 Settings
In the AA90 settings, the options for the assembler can be
changed. Since this application note does not contain any
parts written in assembly, the default settings can be left
unchanged.
XLINK Settings
The linker settings gives the linker instructions for how to
link together the object codes from the different Compiler,
Assembler and Library modules.
The first thing that needs to be selected is the format of the
output-file the linker is to create. In this application note, the
intention is to generate an “Intel Extended HEX” file which
is recognized by the STK200 starter kit.
5
388319555.009.png 388319555.010.png
Zgłoś jeśli naruszono regulamin