CodeVisionAVR is a C cross-compiler, Integrated Development Environment and Automatic Program
Generator designed for the Atmel AVR family of microcontrollers.
The program is a native 32bit application that runs under the Windows 95, 98, NT 4, 2000 and XP
operating systems.
The C cross-compiler implements nearly all the elements of the ANSI C language, as allowed by the
AVR architecture, with some features added to take advantage of specificity of the AVR architecture
and the embedded system needs.
The compiled COFF object files can be C source level debugged, with variable watching, using the
Atmel AVR Studio debugger.
The Integrated Development Environment (IDE) has built-in AVR Chip In-System Programmer
software that enables the automatical transfer of the program to the microcontroller chip after
successful compilation/assembly. The In-System Programmer software is designed to work in
conjunction with the Atmel STK500/AVRISP/AVRProg (AVR910 application note), Kanda Systems
STK200+/300, Dontronics DT006, Vogel Elektronik VTEC-ISP, Futurlec JRAVR and MicroTronics'
ATCPU/Mega2000 development boards.
For debugging embedded systems, which employ serial communication, the IDE has a built-in
Terminal.
Besides the standard C libraries, the CodeVisionAVR C compiler has dedicated libraries for:
• Alphanumeric LCD modules
• Philips I2C bus
• National Semiconductor LM75 Temperature Sensor
• Philips PCF8563, PCF8583, Dallas Semiconductor DS1302 and DS1307 Real Time Clocks
• Dallas Semiconductor 1 Wire protocol
• Dallas Semiconductor DS1820/DS18S20 Temperature Sensors
CodeVisionAVR also contains the CodeWizardAVR Automatic Program Generator, that allows you to
write, in a matter of minutes, all the code needed for implementing the following functions:
• External memory access setup
• Chip reset source identification
• Input/Output Port initialization
• External Interrupts initialization
• Timers/Counters initialization
• Watchdog Timer initialization
• UART initialization and interrupt driven buffered serial communication
• Analog Comparator initialization
• ADC initialization
• SPI Interface initialization
2
C Bus, LM75 Temperature Sensor, DS1621 Thermometer/Thermostat and PCF8563, PCF8583,
• I
DS1302, DS1307 Real Time Clocks initialization
• 1 Wire Bus and DS1820/DS18S20 Temperature Sensors initialization
2. CodeVisionAVR Integrated Development Environment
2.1 Working with Files
Using the CodeVisionAVR IDE you can view and edit any text file used or produced by the C compiler
or assembler.
2.1.1 Creating a New File
You can create a new source file using the File|New menu command or by pressing the Create new
file button on the toolbar.
A dialog box appears, in which you must select File Type|Source and press the Ok button.
A new editor window appears for the newly created file.
The new file has the name untitled.c. You can save this file under a new name using the File|Save
You can open an existing file using the File|Open menu command or by pressing the Open file button
on the toolbar.
An Open dialog window appears.
You must select the name and type of file you wish to open.
By pressing the Open button you will open the file in a new editor window.
2.1.3 Files History
The CodeVisionAVR IDE keeps a history of the opened files.
The most recent eight files that where used can be reopened using the File|Reopen menu command.
A previously opened or a newly created file can be edited in the editor window by using the Tab,
Arrows, Backspace and Delete keys.
Pressing the Home key moves the cursor to the start of the current text line.
Pressing the End key moves the cursor to the end of the current text line.
Pressing the Ctrl+Home keys moves the cursor to the start of the file.
Pressing the Ctrl+End keys moves the cursor to the end of the file.
Portions of text can be selected by dragging with the mouse.
You can copy the selected text to the clipboard by using the Edit|Copy menu command, by pressing
the Ctrl+C keys or by pressing the Copy button on the toolbar.
By using the Edit|Cut menu command, by pressing the Ctrl+X keys or by pressing the Cut button on
the toolbar, you can copy the selected text to the clipboard and then delete it from the file.
Text previously saved in the clipboard can be placed at the current cursor position by using the
Edit|Paste menu command, by pressing the Ctrl+V keys or pressing the Paste button on the toolbar.
Clicking in the right margin of the editor window allows selection of a whole line of text.
Selected text can be deleted using the Edit|Delete menu command or pressing the Ctrl+Delete keys.
The Edit|Print Selection menu command allows the printing of the selected text.
Dragging and dropping with the mouse can move portions of text.
Pressing the Ctrl+Y keys deletes the text line where the caret is currently positioned.
Selected portions of text can be indented, respectively unindented, using the Edit|Indent Block,
respectively Edit|Unindent Block, menu commands or by pressing the Ctrl+I, respectively Ctrl+U
keys.
You can find, respectively replace, portions of text in the edited file by using the Edit|Find,
respectively Edit|Replace, menu commands, by pressing the Ctrl+F, respectively Ctrl+R keys, or by
pressing the Find, respectively Replace buttons on the toolbar.
Changes in the edited text can be undone, respectively redone, by using the Edit|Undo, respectively
Edit|Redo, menu commands, by pressing the Ctrl+Z, respectively Shift+Ctrl+Z keys, or by pressing
the Undo, respectively Redo buttons on the toolbar.
You can go to a specific line number in the edited file, by using the Edit|Goto Line menu command or
by pressing the Alt+G keys.
Bookmarks can be inserted or removed, at the line where the cursor is positioned, by using the
Edit|Toggle Bookmark menu command or by pressing the Shift+Ctrl+0...9 keys.
The Edit|Jump to Bookmark menu command or the Ctrl+0...9 keys will position the cursor at the
start of the corresponding bookmarked text line.
If the cursor is positioned on an opening, respectively closing, brace then the Edit|Match Braces
menu command or the Ctrl+M key will highlight, the portion of text until the corresponding matching
closing, respectively opening brace. Pressing any key or clicking the mouse will hide the highlighting.
Clicking with the mouse right button opens a pop-up menu that also gives the user access to the
above mentioned functions.
The currently edited file can be saved by using the File|Save menu command, by pressing the Ctrl+S
keys or by pressing the Save button on the toolbar.
When saving, the Editor will create a backup file with an ~ character appended to the extension.
All currently opened files can be saved using the File|Save All menu command.
2.1.6 Renaming a File
The currently edited file can be saved under a new name by using the File|Save As menu command.
A Save dialog window will open.
You will have the possibility to specify the new name and type of the file, and eventually its new
location.
You can print the current file using the File|Print menu command or by pressing the Print button on
the toolbar.
The contents of the file will be printed to the Windows default printer.
The paper margins used when printing can be set using the File|Page Setup menu command, which
opens the Page Setup dialog window.
The units used when setting the paper margins are specified using the Units list box.
The printer can be configured by pressing the Printer button in this dialog window.
Changes can be saved, respectively canceled, using the OK, respectively Cancel buttons.
You can quit editing the current file by using the File|Close menu command.
If the file was modified, and wasn’t saved yet, you will be prompted if you want to do that.
Pressing Yes will save changes and close the file.
Pressing No will close the file without saving the changes.
Pressing Cancel will disable the file closing process.
All currently opened files can be closed using the File|Close All menu command.
The Navigator window allows easy displaying or opening of source files.
By clicking on the file name the appropriate file is maximized or opened.
After a Compile or Make process there is also displayed a list of #include –ed files, global variables
and functions declared in each compiled C source file.
By clicking on the variable’s, respective function’s, name the variable, respective function, declaration
is highlighted in the appropriate C source file.
If during compilation there are errors or warnings, these are also displayed in the Navigator window.
By clicking on the error or warning, the corresponding source line is highlighted in the appropriate file.
The Navigator tree branches can be expanded, respectively collapsed, by clicking on the +,
respectively -, buttons.
By right clicking in the Navigator window you can open a pop-up menu with the following choices:
• Open a file
• Save the currently edited file
• Save All opened files
• Close Current File
• Close Project
• Close All opened files
• Toggle on or off expanding the file branches
• Toggle on or off expanding the Errors and Warnings branches for the file whose Editor window
The Project groups the source file(s) and compiler settings that you use for building a particular
program.
2.2.1 Creating a New Project
You can create a new Project using the File|New menu command or by pressing the Create new file
button on the toolbar.
A dialog box appears, in which you must select File Type|Project and press the OK button.
A dialog will open asking you to confirm if you would like to use the CodeWizardAVR to create the new
project.
If you select No then the Create New Project dialog window will open.
You can open an existing Project file using the File|Open menu command or by pressing the Open
file button on the toolbar.
An Open dialog window appears.
You must select the file name of the Project you wish to open.
By pressing the Open button you will open the Project file and its source file(s).
You can configure the Project by using the Project|Configure menu command.
With every Project the CodeVisionAVR IDE creates a text file where you can place notes and
comments.
You can access this file using the Project|Notes or Windows menu commands.
This file can be edited using the standard Editor commands.
The file is automatically saved when you Close the Project or Quit the CodeVisionAVR program.
The Project can be configured using the Project|Configure menu command or the Project Configure
toolbar button.
2.2.4.1 Adding or removing a File from the Project
To add or remove a file from the currently opened project you must use the Project|Configure menu
command.
A Configure Project tabbed dialog window will open. You must select the Files tab.
By pressing the Add button you can add a source file to the project.
The first file added to the project is the main project file.
This file will always be Make -ed.
The rest of the files added to the project will be automatically linked to the main project file on Make.
Multiple files can be added by holding the Ctrl key when selecting in the Add File to Project dialog.
When the project is Open-ed all project files will be opened in the editor.
By clicking on a file, and then pressing the Remove button, you will remove this file from the project.
Changes can be saved, respectively canceled, using the OK, respectively Cancel buttons.
When creating a project with multiple files the following rules must be preserved:
• only .C files must be added to the project's Files list
• there's no need to #include the .C files from the Files list as they will be automatically linked
• data type definitions and function declarations must be placed in header .H files, that will be
#include -ed as necessary in the .C files
• global variables declarations must be placed in the .C files where necessary
• there's no need to declare global variables, that are not static, in header .H files, because if these
files will be #include -ed more than once, the compiler will issue errors about variable redeclarations.
To set the C compiler options for the currently opened project you must use the Project|Configure
menu command.
A Configure Project tabbed dialog window will open. You must select the C Compiler and Code Generation tabs.
You can select the target AVR microcontroller chip by using the Chip combo box.
You must also specify the CPU Clock Frequency in MHz, which is needed by the Delay Functions, 1
Wire Protocol Functions and Dallas Semiconductor DS1820/DS18S20 Temperature Sensors
Functions.
The required memory model can be selected by using the Memory Model radio group box.
The compiled program can be optimized for minimum size, respectively maximum execution speed,
using the Optimize for|Size, respectively Optimize for|Speed, settings.
For devices that allow self-programming the Program Type can be selected as:
• Application
• Boot Loader
If the Boot Loader program type was selected, a supplementary Boot Loader Debugging in AVR
Studio option is available.
If this option is enabled, the compiler will generate supplementary code that allows the Boot Loader to
be source level debugged in the AVR Studio simulator/emulator.
When programming the chip with the final Boot Loader code, the Boot Loader Debugging option must
be disabled.
The (s)printf features option allows to select which versions of the printf and sprintf Standard C Input/Oputput Functions will be linked in your project:
• int - the following conversion type characters are supported: 'c', 's', 'p', 'i', 'd', 'u', 'x', 'X', '%', no
width or precision specifiers are supported, only the '+' and ' ' flags are supported, no input size
modifiers are supported
• int, width - the following conversion type characters are supported: 'c', 's', 'p', 'i', 'd', 'u', 'x', 'X', '%',
the width specifier is supported, the precision specifier is not supported, only the '+', '-', '0' and ' ' flags
are supported, no input size modifiers are supported
• long, width - the following conversion type characters are supported: 'c', 's', 'p', 'i', 'd', 'u', 'x', 'X',
'%' the width specifier is supported, the precision specifier is not supported, only the '+', '-', '0' and ' '
flags are supported, only the 'l' input size modifier is supported
• long, width, precision - the following conversion type characters are supported: 'c', 's', 'p', 'i', 'd',
'u', 'x', 'X', '%', the width and precision specifiers are supported, only the '+', '-', '0' and ' ' flags are
supported, only the 'l' input size modifier is supported
• float, width, precision - the following conversion type characters are supported: 'c', 's', 'p', 'i', 'd',
'u', 'e', 'E', 'f', 'x', 'X', '%', the width and precision specifiers are supported, only the '+', '-', '0' and ' ' flags
are supported, only the 'l' input size modifier is supported.
The more features are selected, the larger is the code size generated for the printf and sprintf
functions.
The (s)scanf features option allows to select which versions of the scanf and sscanf Standard C Input/Oputput Functions will be linked in your project:
• int, width - the following conversion type characters are supported: 'c', 's', 'i', 'd', 'u', 'x', '%', the
width specifier is supported, no input size modifiers are supported
• long, width - the following conversion type characters are supported: 'c', 's', 'i', 'd', 'u', 'x', '%' the
width specifier is supported, only the 'l' input size modifier is supported.
The more features are selected, the larger is the code size generated for the printf and sprintf
functions.
The Data Stack Size must be also specified.
Eventually you may also specify the External SRAM Size (in case the microcontroller have external
SRAM memory connected).
The External SRAM Wait State option enables the insertion of wait states during access to the
external SRAM. This is useful when using slow memory devices.
If an Atmel AT94K05, AT94K10, AT94K20 or AT94K40 FPSLIC device will be used, than there will be
the possibility to specify the Program SRAM size in Kwords.
The size of the bit variables, which are placed in registers R2 to R14, can be specified using the Bit Variables size list box.
Checking the Promote char to int check box enables the ANSI promotion of char operands to int.
This option can also be specified using the #pragma promotechar compiler directive.
Promoting char to int leads to increased code size and lower speed for an 8 bit chip microcontroller
like the AVR.
If the char is unsigned check box is checked, the compiler treats by default the char data type as an
unsigned 8 bit in the range 0…255.
If the check box is not checked the char data type is by default a signed 8 bit in the range –128…127.
This option can also be specified using the #pragma uchar compiler directive.
Treating char as unsigned leads to better code size and speed.
If the 8 bit enums check box is checked, the compiler treats the enumerations as being of 8 bit char
data type, leading to improved code size and execution speed of the compiled program. If the check
box is not checked the enumerations are considered as 16 bit int data type as required by ANSI.
The Enhanced Instructions check box allows enabling or disabling the generation of Enhanced Core
instructions for the ATmega128, ATmega16, ATmega161, ATmega162, ATmega163, ATmega32,
ATmega323, ATmega64, ATmega8 and AT94K FPSLIC devices.
The rest of the registers in the range R2 to R14, not used for bit variables, can be automatically
allocated to char and int global variables by checking the Compilation|Automatic Register Allocation check box.
An external startup file can be used by checking the Compilation|Use an External Startup File
check box.
The generation of warning messages during compilation can be enabled or disabled by using the
Compilation|Enable Warnings check box.
For debugging purposes you have the option Stack End Markers. If you select it, the compiler will
place the strings DSTACKEND, respectively HSTACKEND, at the end of the Data Stack, respectively
Hardware Stack areas.
When you debug the program with the AVR Studio debugger you may see if these strings are
overwritten, and consequently modify the Data Stack Size.
When your program runs correctly you may disable the placement of the strings in order to reduce
code size.
Using the File Output Format(s) list box you can select the following formats for the files generated
by the compiler:
• COFF (required by the Atmel AVR Studio debugger), ROM, Intel HEX and EEP (required by the
In-System Programmer) ;
• Atmel generic OBJ, ROM, Intel HEX and EEP (required by the In-System Programmer).
If the COFF file format is selected and the Use the Terminal I/O in AVR Studio check box is
checked, special debugging information is generated in order to use the AVR Studio 3 Terminal I/O
window for communication with the simulated AVR chip’s UART.
The Use the Terminal I/O in AVR Studio check box must not be checked
does not support this feature.
If the Use the Terminal I/O in AVR Studio option is enabled, the UART or USART code will not run
correctly on the real AVR chip. This option is only for debugging purposes.
The Paths tabs allows to specify additional paths for #include and library files.
These paths must be entered one per line in the appropriate edit controls.
Changes can be saved, respectively canceled, using the OK, respectively Cancel buttons.
2.2.4.3 Transferring the Compiled Program to the AVR Chip after
Make
This option is available if you select the After Make tab in the Project Configure window.
If you check the Program the Chip option, then after successful compilation/assembly your program
will be automatically transferred to the AVR chip using the built-in Programmer software.
The following steps are executed automatically:
• Chip erasure
• FLASH and EEPROM blank check
• FLASH programming and verification
• EEPROM programming and verification
• Fuse and Lock Bits programming
The Merge data from a .ROM File for FLASH Programming option, if checked, will merge in the
FLASH programming buffer the contents of the .ROM file, created by the compiler after Make, with the
data from the .ROM file specified in .ROM File Path.
This is useful, for example, when adding a boot loader executable compiled in another project, to an
application program that will be programmed in the FLASH memory.
You can select the type of the chip you wish to program using the Chip combo box.
If the chip you have selected has Fuse Bit(s) that may be programmed, then a supplementary Fuse Bit(s) check box will appear. Using this check box you can set various chip options, which are
described in the Atmel data sheets.
If a Fuse Bit(s) check box is checked
considered as programmed (as per the convention from the Atmel data sheets).
If a Fuse Bits(s) check box is not checked, then the corresponding fuse bit will be set to 1, the fuse
being considered as not programmed.
If you wish to protect your program from copying, you must select the corresponding option using the
FLASH Lock Bits radio box.
If you wish to check the chip's signature before programming you must use the Check Signature
option.
To speed up the programming process you can uncheck the Check Erasure check box.
In this case there will be no verification of the correctness of the FLASH erasure.
The Preserve EEPROM checkbox allows preserving the contents of the EEPROM during chip
erasure.
To speed up the programming process you can uncheck the Verify check box.
In this case there will be no verification of the correctness of the FLASH and EEPROM programming.
Changes can be saved, respectively canceled, using the OK, respectively Cancel buttons.
, then the corresponding fuse bit will be set to 0, the fuse being