Atmel AVR030 Service Manual

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 Execu table F ile Into the

Introduction

The purpose of this applic at ion note is to guide new users through the initial set­tings of the Embedded Workbench from IAR and compile a simple C progr am. The application note sho ws how t o set up the compiler to generate an execut­able hex file and how t o downlo ad this file into the device. The example described in this application note is writ­ten for the AT90S2313 using the STK200 starter kit or alternati vely an emulator.
Figure 1. Create the Project File

Preparations

The IAR compiler is shipped with a hard­ware lock dongle. This dongle must b e 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.

Creating a New Project

When the preparatio ns are ready , open the IAR Embedded Workbench. To cre­ate a new project, go to the “File” men u 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.
8-bit Microcontroller
Application Note
Rev. 1483A–09/99
1

Settings in “Project-> Options”

Before any cod e can be comp iled and li nked, the opt ions 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 “D ebug”. 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 necess ary to set al l options twice when usin g both targets. The main difference between the two targets is the format of the output file.
Figure 2. Selecting Target Release
It is also possible to add more targets which options can be customized to a specific A VR (simulated, emu lated or the real device). Common and different source files may be included in the diffe rent targets . A fold er wil l be create d for each target when linked for the first time.
In this application note, the goal i s 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. T hen select the Project->Options menu. The window shown in Figure 3 will pop up.

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 byt e data pointe r, thus allowing a maximum of 256 bytes data. Memory model
2
AVR030
small uses a two byte data pointer, thus allowing up to 64 Kilobytes data. For the -v0 and -v2 Proce ssor Configura­tion only the Memory model tiny may be used.
In our example, the factory settings should be used, as shown in Figure 3.
Figure 3. General Options Dialog
AVR030
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)
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)
AT90S8534 V1 (max 64K byte data, 8K code) Small 8K256S.xcl AT90S8535 V1 (max 64K byte data, 8K code) Small 8F512S.xcl
Small
Small
4F256S.xcl 4F64KS.xcl
8F512S.xcl 8F64KS.xcl
3
Table 1. Device Specific Settings (Continued)
AVR Device Processor Configuration Memory Model XCL file
ATmega103 V3 (max 64K byte data, 128K code)
ATmega161 V3 (max 64K byte data, 128K code)
ATmega603 V3 (max 64K byte data, 128K code)

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, vari ables def ined as c onst will not be com piled 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 speci fied fo r a single target . Note t hat if a hig h level of optimization is used, the user may not be able to debug the code. The code will be fully debuggable with
Small
Small
Small
128F4KS.xcl 128F64KS.xcl
16F1KS.xcl 16F64KS.xcl
64F4KS.xcl 64F64KS.xcl
optimization level 3 (default for both types of optimization) or lower.
Also note that it i s strong ly reco mmende d that the “Embed source code chec kbox in the Debu g tab is checked if a debugging target, i.e. simulation or emulation, is used. This will let you debug on the assembly level rath er than on th e C language level. In AVR Studio you wil l also be able to see exactly which assem bly code is gen erated 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, i f checked, cause the compiler to inc lud e th e ge ner ate d as sembly lines in the listing.
4
AVR030
Loading...
+ 7 hidden pages