AVR tutorial

April 28, 2018 | Author: radiatar_M | Category: Computer Program, Microcontroller, Office Equipment, Computer Programming, Computing
Share Embed Donate


Short Description

how to use AVR studio to burn programm to microcontroller...

Description

How to Start with AVR Series Microcontrollers Atmel currently provides AVR microcontrollers in many shapes and sizes, ranging from small 8-pin tinys to 100-pin xmegas. Flash memory sizes for program code range from 1 kilobyte to 256 kilobytes. You can find more information and a list of devices on the Atmel Website For this basic tutorial tutorial on how to get started started with AVR-microcontrollers we are using an ATmega16 (full datasheet can be found on Atmel Website), which has 16 kilobytes of flash and lots of general input/outputpins. Every pin can be programmed individually as an input (digital or analog) or output (digital only) pin. We will go step by step on what hardware and software do you need and after that some example programs. The hardware part will include using any ATmeg16 Development board and the programming cable, which is needed to get the compiled program from the computer to the chip. The software part then guides you what you need in order to make your program code and to transfer the ready compiled binary code to your board. You will need some basic knowledge about electronics (how to connect leds etc) and it is good to read some basic Electronics tutorials if all of this is new to you. There are example programs written in C later in the article so some knowledge in programming isn't bad either. 

What you need (software) In order to be able to get your AVR circuit to do something, you'll need a couple of programs to your computer. We will look at the installing of programs on windows and below are the links to all we need. If  you are using Linux, you can check out our "AVR Programming in Linux Environment Tutorial". For Windows download the following programs and install them o

o

o



WinAVR - A software package that includes avr-gcc that makes it possible to write the programs in C language and compile them for the AVR. Atmel's AVR Studio - Integrated Development Environment (IDE) for AVR microcontrollers helps you to manage your projects etc. Downloading requires FREE registration. PonyProg - Simple yet powerful programmer that we need to get the compiled program to the AVR chip through the parallel/serial programming cable as there isn't straight support for it in the AVR Studio.

Installation First one is WinAVR, the installation is quite straight forward, just read what it says and click next. The best option is to leave everything to their defaults. Next install AVR Studio, again leave everything to their defaults and everything should go well. Nothing special with PonyProg either, just unzip the package and run setup.exe and follow the instructions. You now have all the necessary programs installed and you'll find them from your program menu. Continue to the next step.



Coding and Compiling After you've installed all the programs successfully, start AVR Studio and you should see a welcome screen. There is a button "New Project", click it. New project can be started from the Project menu too.

AVR Studio welcome screen You should now see a window with a "Project type" area and there should be "AVR GCC" (if not then there is something wrong with your WinAVR installation), choose it. Fill in the project name and choose a location where you want your projects to be saved. Click on the "Create folder" too so your projects are well organized under their own folders. Click Finish now, not Next.

AVR Studio, project window 

After clicking Finish, you should see the following fo llowing view:

AVR Studio ready to be used 

In the following pages on this article you'll find some example codes that you can use to test your circuit. Let's copy & paste the first example code into the middle window.

AVR Studio, code pasted 

Now navigate into the Project menu (up left) and from there goto "Configuration Options" and you'll see the following screen. Select the right device for the project, atmega16 in this case (or what you are using). Fill in the frequency in Hz, which is 1000000 Hz (1 MHz) for the atmega16 with factory settings. Click OK.

AVR Studio, project settings

Remember to save your project now. Navigate to Build menu and click Build (or hit F7 on your keyboard) and if all goes well, no errors should be there and you'll see a text like this in the message window.

AVR Studio, project compiled 

As you can see, the led flashing program doesn't take much space from the chip. After this is done you are ready to continue to the programming of the chip. 

Getting the code to the chip Programming As we are using the parallel port programming cable, we'll need to use external programming software to get the code to the chip. Now start the PonyProg program. – 

PonyProg

Select File -> Open device file (or click the yellow folder icon). Navigate to your project directory and there you'll find a directory named "default". From there choose the "project_name.hex", in this case "test_project.hex". "test_project.hex". This file contains the compiled program in a form the chip understands.

PonyProg, hex file loaded 

You can see two drop down boxes, find "AVR micro" to the first one and "AVR Auto" or "ATmega16" to the second one. Now navigate to Setup -> Interface Setup... and choose "Parallel" and "Avr ISP I/O" from the dropdown menu below it. Click OK. Go to Setup -> Calibration and click Yes. After this, connect your programming cable to your computer and the chip if you haven't already done this and give some power to the chip too.

PonyProg, hex file loaded 

Click on the yellow arrow on the second line of icons, this will start the programming cycle. Let the program do its work and if you've done everything right you should get the following message that the programming has succeeded and the led should be flashing happily on the board. If there are some errors, check and double check all your connections!

PonyProg, program succesful 

Basics of C The mandatory part in C program is main function. This function must be included in every program because this is a first function which is run after execution of program. Let’s take an example:

/**************** #include int main(void) {  printf(“Hello world! \n”); return 0; }  /**************** This is a very basic C program, but it contains all necessary elements of it. Let’s examine a little bit what we have written here... #include - is a preprocessor command. All preprocessor commands are identified by # sign at the beginning of the line. #include command tells preprocessor to open file stdio.h and from it necessary stored parts while compiling program. The file n ame is surrounded by brackets “”. Bracket marks“” tels the preprocessor to search for the file in the region defined by Operating System variables (for instance “path” variabel in Environment variables). If double quotes are used instead of bracket marks then file searching is done only in default directory of project.

Next line is int main(void). It is always necessary to define the type of function return type and of course function has arguments. The type int  is showing that main function returns an integer and no arguments to the function is needed. Opening brace “{” indicates the beginning of the block of sentences. One of those sentences is printf(). This function is taken from stdio.h library and writes a message to computer terminal (this case screen). Return 0 is returning parameter to the function. And every function should end with closing brace “}”.

“/*” is commenting the line. This means that line marked with “/*”is not included in compilation.

Block Diagram of CC2500 Module Before we start you have to remember that this module will give you RS output and not TTL output. The RF module contains on board TTL to RS Level converter so that you can easily interface your module to your PC through serial port. Here is a block diagram of module

As you can see from block diagram RF module has 1 micro controller, which is actually working of the heart of module. This micro controller will read the user settings and transmit or receive data according to settings. RF module has on board EEPROM which actually stores user settings that is channel number, device ID and baud rate etc. CC2500 Module is wireless transceiver with antenna. Mode selectional module is combination of jumpers and LED, which helps users to set the mode of module. And last but not least, RS to TTL and TTL to RS level converter which will allow your module to directly interfaced with PC. Remember 1 thing this module gives you RS output

Nexus Nexus is the first step to enter the World Challenge. With a win in this competition, you get a direct entry to the Indian Leg finals of the Mars Manoeuvre. Here, the best of India will compete to become the National Champions who will then fight with the International winners for the glory of being crowned as "World Champions: The Ultimate Conquerors" in iNexus. This year Nexus will be held at five strategic centres, spanning throughout the country's length and breadth. Central Zone: Medi-Caps Institute of Technology and Management, Indore (26th September, September, 2010) South Zone: Model Engineering College, Kochi (26th September, 2010) North Zone: Thapar University, Patiala (3rd October, 2010) East Zone: Kalinga Institute of Industrial Technology, Bhubaneswar (3rd October, 2010) West Zone: Indian Institute of Technology Bombay, Mumbai (10th October, 2010) Prizes worth INR 75,000 Problem Statement for Navigate: Make an autonomous bot that traverses a grid to find a specific block and brings it back to the top of a ramp. Click Here to read more about Navigate Register for Navigate

Mars Manoeuvre Prizes worth INR 1,15,000 Problem Statement for Navigate: Build manual and autonomous machines which cooperate and collaborate to bring back blocks placed randomly on a grid. Click Here to read more about Mars Manoeuvre Register for Mars Manoeuvre

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF