Atmel AVR Microcontroller Tutorial - T. Danko (2004) WW.pdf
(
3292 KB
)
Pobierz
743632257 UNPDF
Todd Danko
January 28, 2004
Atmel AVR Tutorial
Introduction
The purpose of this tutorial is to describe step by step, the process of coding, compiling,
and uploading programs to Atmel AVR microcontrollers.
What is needed?
Before beginning, several items are required:
Description
Part Identifier
Source
Price
Development board
with ATMega32
microcontroller
The MegaAVR-Dev
w/ATMega32
www.prllc.com
$56
Chip Programmer
Software and
Hardware
The CableAVR ISP
Programmer
www.prllc.com
$99
AVR Integrated
Development
Environment
CodeVisionAVR
www.hpinfotech.ro
Free
Evaluation
Serial Cable (RS-
232C)
26-117
www.radioshack.com
$14.49
Power Supply*
273-1776
www.radioshack.com
$16.99
Text Book
Embedded C Programming
and the Atmel AVR
www.prllc.com
$67.95
* The power supply may be purchased, but any AC to DC converter that outputs 8
to 38 Volts DC, and greater than 1 Amp (1000mA) may be salvaged from unused
household appliances (answering machine, modem, etc).
Microcontroller and Development Board Specifications
Page 1 of 11
The ATMega32 AVR microcontroller is a 16 bit RISC processor. When combined with
the development board, many features are offered:
•
4, 8 bit Digital I/O Ports (PORTA, PORTB, PORTC, PORTD)
•
RS232 communications through:
o
9-Pin D-Shell
o
Screw terminals
o
Jumper header
•
32K of In-System Programmable FLASH memory
•
1K of EEPROM
•
1K of Internal RAM
•
8, 10 bit, Analog Inputs
o
Either internal or external reference voltage
•
9 I/O controlled LEDs
o
8 LEDs are jumper selectable.
•
32KHz watch crystal
•
Universal clock socket with 6MHz crystal
•
0.1" centered headers
•
10-pin, polarized, ISP and JTAG connectors
•
Requires an 8-38VDC power supply
System Overview
The overall process to program an AVR microcontroller is as follows:
1.
Define your objective keeping in mind how you will use hardware and software
2.
Decide what hardware will be used, and in what configuration
3.
Write software that manipulates your hardware appropriately
4.
Compile / Assemble software
5.
Connect computer to chip
6.
Program chip
7.
Attach hardware to chip if necessary
8.
Run it!
Where to begin…
We will begin by accomplishing three tasks. The first task will be as simple as possible,
and each subsequent task will add complexity.
1.
Light up an LED on the development board.
2.
Reads in a digital word from an eight dipswitch array, and light up corresponding
LEDs on an eight LED array.
3.
Light up LEDs to count from 0 to 255 in binary, pausing two seconds between
each step.
TASK 1:
For the first task, we will use an LED that is attached to the development board. Set the
jumpers for PORTC so that they connect PORTC to the array of LEDs (Circled in red)
Page 2 of 11
Note the position
of these jumpers.
In this position, the
8 LEDs to the right
are connected to
PORTC
The configuration of the development board is such that +5 volts is connected through a
resistor to one leg of each LED, and the ground for each LED is attached to a pin on
PORTC. This means that when a pin on PORTC is set high (+5 volts), there is no current
flowing through the LED and the LED is off. When a pin on PORTC is set low (ground),
current flows through the LED, and the led is on. So, for this setup, turning a pin off,
turns the LED on.
So, how do we tell the microcontroller to turn a pin of PORTC off (thus turning a single
LED on)? A port can be thought of as an eight bit variable. When you assign a value
between 0 and 255 to this eight bit variable, each pin will be set to either on or off (+5 V
or Ground). The +5V corresponds to a 1 and the ground corresponds to a 0. So, if we
want to make one LED turn on, and the rest stay off, we want to send the number 254 to
PORTC. The number 254 in binary is 01111111, so pin0 on PORTC will be ground, and
pin1 – pin7 will be +5 V. This means that the LED attached to pin0 will be on, and the
rest will be off.
Lets get started:
•
Open up CodeVisionAVR on your PC.
•
Click on the “New Project” icon to create a new project.
Page 3 of 11
•
When the “Create New File” dialog box pops up, click “Project” then “OK.”
New Project
•
A dialog box titled “Confirm” will pop up asking if you would like to use
“CodeWizardAVR.” This is a helpful tool, but it is important to learn to code
with out this wizard first. Click “No.”
•
Save the project to an appropriate file name when prompted
•
Click on the “New Project” icon again
•
This time, check “Source” and then click “OK”
•
Enter your code in the source code window:
/*********************************************
Project : led_on
Comments: This program lights up the LED attached to pin0 or PORTC
*********************************************/
#include <mega32.h>
void
main(
void
)
{
PORTC=
0xFF
;
//Set all pins of PORTC to output (p.87 in textbook)
DDRC=
0xFF
;
//Set initial values for PORTC to high
while
(
1
)
Page 4 of 11
{
PORTC =
254
;
//pin0, PORTC = 0 (LED ON), pin1-7=1 (LEDs OFF)
};
}
•
On the toolbar, click “File” then “Save” to save your source code. Save your
source code to an appropriate file name.
•
The source code must now be associated with the project:
o
Click “Project” then “Configure”
o
Click Add on the “Configure Project” window
o
Select your source code, then click open.
o
Now, click the second tab (C Compiler) of the “Configure Project”
window
o
Select the chip type, and clock speed that is appropriate for your chip.
Click OK
•
Now compile and assemble your code by clicking on the “Assemble” button.
Page 5 of 11
Plik z chomika:
fred1144
Inne pliki z tego folderu:
mikroC_PRO_AVR_2013_Build.6.0.0.exe
(19315 KB)
mikroBasic pro AVR v4.60.rar
(17851 KB)
mikroBasic_pro_AVR_2009_Build.1.50.exe
(12443 KB)
1061-8-atmel-3-1925.pdf
(8331 KB)
atmel.rar
(6585 KB)
Inne foldery tego chomika:
- Разные
! Осциллограф РАДИОПРОГИ РАСЧЁТЫ СПРАВОЧНИКИ
!avr test
!Измерения и константы
# PIC
Zgłoś jeśli
naruszono regulamin