ВУЗ: Не указан

Категория: Не указан

Дисциплина: Не указана

Добавлен: 13.06.2025

Просмотров: 2235

Скачиваний: 0

ВНИМАНИЕ! Если данный файл нарушает Ваши авторские права, то обязательно сообщите нам.

CodeVisionAVR

3.19 Creating Libraries

In order to create your own libraries, the following steps must be followed:

1. Create a header .h file with the prototypes of the library functions. Select the File|New menu command or press the New toolbar button. The following dialog window will open:

Select Source and press the OK button.

A new editor window will be opened for the untitled.c source file.

Type in the prototype for your function. Example:

//this #pragma directive will prevent the compiler

//from generating a warning that the function was

//declared, but not used in the program

#pragma used+

//library function prototypes int sum(int a, int b);

int mul(int a, int b); #pragma used-

//this #pragma directive will tell the compiler to

//compile/link the functions from the mylib.lib library #pragma library mylib.lib

Save the file, under a new name, in the ..\INC directory using the File|Save As menu command, for example mylib.h :

© 1998-2007 HP InfoTech S.R.L.

Page 105

CodeVisionAVR

2. Create the library file.

Select the File|New menu command or press the New toolbar button. The following dialog window will open:

Select Source and press the OK button.

A new editor window will be opened for the untitled.c source file.

Type in the definitions for your functions.

Example:

int sum(int a, int b) { return a+b;

}

int mul(int a, int b) { return a*b;

}

Save the file, under a new name, for example mylib.c , in any directory using the File|Save As menu command:

© 1998-2007 HP InfoTech S.R.L.

Page 106

CodeVisionAVR

Finally use the File|Convert to Library menu command, to save the currently opened file under the name mylib.lib in the ..\LIB directory:

In order to use the newly created mylib.lib library, just #include the mylib.h header file in the beginning of your program.

Example:

#include <mylib.h>

Library files usually reside in the ..\LIB directory, but paths to additional directories can be added in the Project|Configure|C Compiler|Paths|Library paths menu.

© 1998-2007 HP InfoTech S.R.L.

Page 107


CodeVisionAVR

3.20 Using the AVR Studio Debugger

CodeVisionAVR is designed to work in conjunction with the Atmel AVR Studio debugger version 3 and 4.06 (or later).

For the AVR Studio debugger version 4.06 (or later) the compiler will generate an extended COFF object file that allows watching structures and unions. So it is highly recommended to use AVR Studio version 4.06 (or later) instead of version 3, which doesn’t support this feature. AVR Studio 4 prior to version 4.06 does not support the extended COFF object file format, so it can’t be used with CodeVisionAVR.

In order to be able to do C source level debugging using AVR Studio, you must select the COFF output file format in the Project|Configure|C Compiler|Code Generation menu option.

The AVR Studio Debugger is invoked using the Tools|Debugger menu command or the Debugger toolbar button.

3.20.1 Using the AVR Studio Debugger version 3

The COFF object file created by the compiler will be automatically loaded after AVR Studio is invoked using the CodeVisionAVR IDE Tools|Debugger menu command or the Debugger toolbar button.

Once the program is loaded, it can be launched in execution using the Debug|Go menu command, by pressing the F5 key or by pressing the Execute program toolbar button.

Program execution can be stopped at any time using the Debug|Break menu command, by pressing Ctrl+F5 keys or by pressing the Break toolbar button.

To single step the program, the Debug|Trace Into (F11 key), Debug|Step (F10 key), Debug|Step Out menu commands or the corresponding toolbar buttons should be used.

In order to stop the program execution at a specific source line, the Breakpoints|Toggle Breakpoint menu command, the F9 key or the corresponding toolbar button should be used.

In order to watch program variables, the user must select Watch|Add Watch menu command or press the Add Watch toolbar button, and specify the name of the variable in the Watch column.

The AVR chip registers can be viewed using the View|Registers menu command or by pressing the

Alt+0 keys.

The AVR chip PC, SP, X, Y, Z registers and status flags can be viewed using the View|Processor menu command or by pressing the Alt+3 keys.

The contents of the FLASH, SRAM and EEPROM memories can be viewed using the View|New Memory View menu command or by pressing the Alt+4 keys.

The I/O registers can be viewed using the View|New IO View menu command or by pressing the

Alt+5 keys.

In order to use the Terminal I/O window, invoked with the View|Terminal I/O menu command, for communication with the simulated AVR chip’s UART, the COFF file format must be selected and the

Use the Terminal I/O in AVR Studio check box must be checked in the Project|Configure|C Compiler|Code Generation dialog.

To obtain more information about using AVR Studio please consult it’s Help system.

© 1998-2007 HP InfoTech S.R.L.

Page 108


CodeVisionAVR

3.20.2 Using the AVR Studio Debugger version 4.06 or later

The user must first select File|Open File (Ctr+O keys) in order to load the COFF file to be debugged. After the COFF file is loaded, and no AVR Studio project file exists for this COFF file, the debugger will open a Select device and debug platform dialog window.

In this window the user must specify the Debug Platform: ICE or AVR Simulator and the AVR Device type.

Pressing the Finish button will create a new AVR Studio project associated with the COFF file.

If an AVR Studio project associated with the COFF file already exists, the user will be asked if the debugger may load it.

Once the program is loaded, it can be launched in execution using the Debug|Run menu command, by pressing the F5 key or by pressing the Run toolbar button.

Program execution can be stopped at any time using the Debug|Break menu command, by pressing Ctrl+F5 keys or by pressing the Break toolbar button.

To single step the program, the Debug|Step Into (F11 key), Debug|Step Over (F10 key), Debug|Step Out (Shift+F11 keys) menu commands or the corresponding toolbar buttons should be used.

In order to stop the program execution at a specific source line, the Debug|Toggle Breakpoint menu command, the F9 key or the corresponding toolbar button should be used.

In order to watch program variables, the user must select Debug|Quickwatch (Shift+F9 keys) menu command or press the Quickwatch toolbar button, and specify the name of the variable in the QuickWatch window in the Name column.

The AVR chip registers can be viewed using the View|Register menu command or by pressing the Alt+0 keys. The registers can be also viewed in the Workspace|I/O window in the Register 0-15 and

Register 16-31 tree branches.

The AVR chip PC, SP, X, Y, Z registers and status flags can be viewed in the Workspace|I/O window in the Processor tree branch.

The contents of the FLASH, SRAM and EEPROM memories can be viewed using the View|Memory menu command or by pressing the Alt+4 keys.

The I/O registers can be viewed in the Workspace|I/O window in the I/O branch.

To obtain more information about using AVR Studio please consult it’s Help system.

© 1998-2007 HP InfoTech S.R.L.

Page 109


CodeVisionAVR

3.21 Hints

In order to decrease code size and improve the execution speed, you must apply the following rules:

If possible use unsigned variables;

Use the smallest data type possible, i.e. bit and unsigned char;

The size of the bit variables, allocated to the program in the Project|Configure|C Compiler|Code Generation|Bit Variables Size list box, should be as low as possible, in order to free registers for allocation to other global variables;

If possible use the TINY memory model;

Always store constant strings in FLASH by using the flash keyword;

After finishing debugging your program, compile it again with the Stack End Markers option disabled.

3.22 Limitations

This version of the CodeVisionAVR C compiler has the following limitations:

arrays of structures or unions can have only one dimension

for the EVALUATION version the size of the compiled code is limited;

the Philips PCF8563, Philips PCF8583, Maxim/Dallas Semiconductor DS1302, DS1307, 4x40 character LCD functions are not available in the EVALUATION version.

© 1998-2007 HP InfoTech S.R.L.

Page 110