Become familiar with creating C language programs for the ATmega32 using AVRStudio.
In this lab, you will create a C-language application to download to your ATmega32 board.
Make sure you have the latest version of WinAVR (December 5/6, 2008) installed (see install instructions). This is important because this is the version we will be using in this course and it differs from previous versions.
Next, download the file libsunromlcd.zip and unzip it someplace on your local file system.
Next, start AVR Studio and create a GNU GCC (not an AVR Assembler) project called HelloWorld. In the HelloWorld.c file, insert the following code:
// File: HelloWorld.c // A simple C program that makes use of some predefined C-language LCD functions. // LCD must be connected to PORTC #include <avr/io.h> // Contains port name definitions, etc. #include <avr/interrupt.h> // Contains declaration for sei() #include <inttypes.h> // Contains C99 data types #include <lcd.h> // Contains many lcd functions #include <delay.h> int main() // every C program needs a "main" { sei(); // Sets Global Interrupt Flag so ATmon will work lcd_init(); // Initialize LCD lcd_clear(); // Clear LCD panel lcd_home(); // Move LCD cursor to home position while(1) { lcd_clear(); lcd_goto_xy(5,0); // Move LCD cursor location lcd_print_string("Hello"); delay_ms(1000); lcd_goto_xy(0,1); // Move LCD cursor location lcd_print_string("Welcome to 2810"); delay_ms(1000); } }
Before compiling, you need to configure the project settings appropriately. There are several steps to configuring the settings for a C-language project. The example screens below used a project named HelloWorld.
From the Project menu of AVRStudio, select Configuration Options and make the selections exactly as shown below on the General page of the dialog:
These settings cause the compiler to not optimize the generated assembly code and generate .map and .lss (equivalent to .lst with the Atmel assembler) files.
Next, select the Include Directories page within this dialog, and Add the file path to the location where you unzipped LCDlibrary.zip:
This tells the linker to look in the LCD library directory when linking.
Next, select the Libraries page. Add the file path to the location where you unzipped LCDLibrary.zip. Next, select libsunromLCD.a and libm.a from the Available Link Objects pane and use the Add Library button to add these files to the Link with These Objects pane. Use the Move up button to move the libsunromLCD.a file to the top of the list; if you don't do this, you'll get build errors later on.
This makes the standard math library and LCD library available to your project.
Finally, select the Custom Options page. Select [Linker Options] in the Custom Compilation Options and add the -Wl,-defsym=__stack=0x80083F (lowercase L after the -W) as shown:
This initializes the stack pointer to 0x083F.
When you get to this point, your configuration is complete. Build the project and download it to your ATmega32 board. The HelloWorld.hex file is placed in the projects default folder.
In addition, you should complete the ATmon activity (step 3)
You are required to demonstrate your program to your instructor.
You should indicate how much time (in minutes) you spend on this assignment in the FAST database. You are encouraged to log your activity as you work on the project. At a minimum, you should log all of the time spent on this assignment before the due date given above. All time spent on this assignment should be entered into the week 1 column.
No additional items need to be submitted. This assignment is required but is worth 0% of your lab grade for the quarter.
If you have any questions, consult your instructor.