Avr031: Getting Started With Imagecraft C For Avr: 8-Bit Microcontroller Application Note
Avr031: Getting Started With Imagecraft C For Avr: 8-Bit Microcontroller Application Note
AVR
8-bit
Features
How to Open a New Project
Microcontroller
Description of Option Settings
Writing and Compiling the C Code
How to Load the Executable File into the STK200 Starter Kit
Application
Introduction Note
The purpose of this application note is to guide new users through the initial settings
of the ImageCraft IDE and compile a simple C program. The application note shows
how to set up the compiler to generate an executable hex file and how to download
this file into the device. The example described in this application note is written for
the AT90S2313 using the STK200 starter kit, or alternatively, an emulator.
Preparations
You may download and install the full-featured 30-day demo program from the Image-
Craft web site (http://www.imagecraft.com), or install the product directly from the
ImageCraft product CD. To turn the demo program into a licensed program, all you
need is an unlock disk or unlock code from ImageCraft. In this document, we will
assume that you install the toolset into the default directory c:\icc. Once installed, a
program shortcut ICC AVR is placed into the start menu program group ImageCraft
Development Tools.
Rev. 1630BAVR05/02
1
Figure 1. The IDE
Editors Project
File
Status
To create a new test project, select Project->New. The dialog box shown in Figure 2
appears. In this dialog box, first create a folder called c:\icctest and then type exam-
ple in the File name window. The name of your project is now example and
c:\icctest\example is your project directory.
2 AVR031
1630BAVR05/02
AVR031
Settings in Project Before any code can be compiled and linked, you must set up the options for the com-
piler correctly. You select Project->Options to display a dialog box to change the
->Options
settings. Each project can have its own settings and you can store a particular group of
settings as your default settings. Default settings can be loaded into a project. There are
three pages in the Project Options dialog box. For this document, we will only look at
options that are relevant to our example.
Paths In the Paths page of the dialog box, you specify the directory paths to the header files,
the libraries, and the output directory. The include paths and library path should be auto-
matically set up to c:\icc\include and c:\icc\lib respectively.
The output directory is where the compiler should put the output and project related
files. This path will be relative to your project directory unless you specify an absolute
directory. Enter objs in the edit box. The IDE will use c:\icctest\example\objs as the
output directory.
3
1630BAVR05/02
Compiler In the Compiler page of the dialog box, you specify options that affect the compiler
operations. For this example, go to the Output Format list box and select Intel HEX.
Also check the option Accept C++ Comments.
Target In the Target page of the dialog box, you specify options that pertain to your target. For
this example, go to the Device Configuration list box and select 2313. Unlike some
other compilers, the ImageCraft IDE specifies the exact options needed by the entire
compiler toolchain (including the compiler, assembler and linker), making the IDE very
simple to use.
4 AVR031
1630BAVR05/02
AVR031
Writing the Source When the project options are properly configured, the next step is to write the source
code. This application note uses a simple program that increments PORTB on which the
File
eight LEDs are attached. An 8-bit timer is used to generate a delay between increments,
making it possible to see the LEDs flashing.
To create a new source file, select File->New or click on the New icon in the toolbar.
In the new window that appears, type in the text below, and save it as avr031.c by
selecting File->SaveAs. Although it is not required, you should save the file in the
project folder, e.g. c:\icctest\example.
void initialization(void)
{
DDRB = 0xff;// set PORTB as output
TCCR0 = 0x05;// Count clock/1024
}
The program is divided into three parts: initialization, delay and main-loop. In the initial-
ization section, PORTB is set as output and TIMER0 starts to count the main clock
divided by 1024.
In the delay subroutine, the controller waits for the TIMER0 Overflow Flag to be set then
clears the flag and exits.
In the main-loop, the content in PORTB is incremented and a delay is called to make the
change on PORTB visible.
5
1630BAVR05/02
Including the Source When the source code is written, it has to be included in the project.
File in the Project Select the Project->Add File(s) menu. The dialog box shown in Figure 6 appears.
Open the c:\icctest\example folder, select the file avr031.c by clicking on it, and click
OK. You can also invoke this dialog box by right-clicking on the Project List window
(the window pane on the right side of the IDE display) and selecting Add Files on the
popup menu.
Compiling the Code To compile the code, Select Project->Make Project or click on the Build Project icon
on the toolbar. If everything is done correctly, the code compiles and links with no errors
and an executable hex code is placed in the file c:\icctest\example\objs\example.hex.
Loading the File into To run the code, the file has to be programmed into an AT90S2313. This application
note describes how to load it to an AT90S2313 in the STK200 starter kit.
the STK200 Starter
Kit The software used by the STK200 is called AVR ISP. The STK200 dongle must be
mounted on the parallel port. When this is done, a new project can be opened.
A new project is opened by selecting Project->New Project in AVR ISP. Highlight the
AT90S2313 from the device selection menu and click OK.
In the Project Manager window information about the project can be typed in, and
Fuse and Lock bit options can be set. This is not necessary for this project.
The next step is to load the hex-file into the Program Memory window. To do this, acti-
vate this window by clicking on the title frame of the window. Now go to the File menu
and select Load. In the dialog box that appears, open the c:\icctest\example\objs
folder, and select the example.hex file.
To load the program into the AT90S2313 on the starter kit, select the Program->Auto-
Program option. In the Auto-Program dialog box, tag Reload Files, Erase device
and Program device. Now click OK. The LEDs on the starter kit should be counting.
6 AVR031
1630BAVR05/02
AVR031
Short Reference
7
1630BAVR05/02
Atmel Headquarters Atmel Operations
Corporate Headquarters Memory RF/Automotive
2325 Orchard Parkway 2325 Orchard Parkway Theresienstrasse 2
San Jose, CA 95131 San Jose, CA 95131 Postfach 3535
TEL 1(408) 441-0311 TEL 1(408) 441-0311 74025 Heilbronn, Germany
FAX 1(408) 487-2600 FAX 1(408) 436-4314 TEL (49) 71-31-67-0
FAX (49) 71-31-67-2340
Europe Microcontrollers
Atmel Sarl 2325 Orchard Parkway 1150 East Cheyenne Mtn. Blvd.
Route des Arsenaux 41 San Jose, CA 95131 Colorado Springs, CO 80906
Case Postale 80 TEL 1(408) 441-0311 TEL 1(719) 576-3300
CH-1705 Fribourg FAX 1(408) 436-4314 FAX 1(719) 540-1759
Switzerland
TEL (41) 26-426-5555 La Chantrerie Biometrics/Imaging/Hi-Rel MPU/
FAX (41) 26-426-5500 BP 70602 High Speed Converters/RF Datacom
44306 Nantes Cedex 3, France Avenue de Rochepleine
Asia TEL (33) 2-40-18-18-18 BP 123
Room 1219 FAX (33) 2-40-18-19-60 38521 Saint-Egreve Cedex, France
Chinachem Golden Plaza TEL (33) 4-76-58-30-00
77 Mody Road Tsimhatsui ASIC/ASSP/Smart Cards FAX (33) 4-76-58-34-80
East Kowloon Zone Industrielle
Hong Kong 13106 Rousset Cedex, France
TEL (852) 2721-9778 TEL (33) 4-42-53-60-00
FAX (852) 2722-1369 FAX (33) 4-42-53-60-01
e-mail
[email protected]
Web Site
http://www.atmel.com
1630BAVR05/02 0M