AVR Assembly Language An Introduction - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

AVR Assembly Language An Introduction

Description:

Any line can have a comment. 9/7/09. Dr. Tim Margush - Assembly ... Comments. Single ... Block comments. Begin with /*, end with */, and may span several ... – PowerPoint PPT presentation

Number of Views:328
Avg rating:3.0/5.0
Slides: 21
Provided by: timma87
Category:

less

Transcript and Presenter's Notes

Title: AVR Assembly Language An Introduction


1
AVR Assembly LanguageAn Introduction
  • Assembly Language Programming
  • University of Akron
  • Dr. Tim Margush

2
Assemblers
objectfile
  • Translate source code to machine language

source
Assembler
hexfile
include files
mapfile
listfile
3
Source Files
  • Usually a text file containing assembly language
    statements
  • Include directives are used to insert text from
    other files as part of the source

4
Object File
  • Contains machine program and debugging
    information used by AVR Studio

5
Hex File
  • Contains data for AVR Processor flash memory
  • This is used by the programmer utility to
    download to AVR memory

6
Map File
  • A list of labels and symbols used in the program
  • Serves as a reference to locate data in memory

7
Listing File
  • A complete report of the assembly process
  • Includes error messages, address information,
    bytes generated, and statistics

8
Syntax
  • There are 3 valid formats for AVR assembly
    language statements
  • label directive operands comment
  • label instruction operands comment
  • label comment
  • .. indicates optional stuff
  • Each line is a directive, an instruction
    (machine), a label, or is blank
  • Any line can have a comment

9
Comments
  • Single line comments
  • Begin with a semi-colon or double slash and
    extend to the end of the line
  • Block comments
  • Begin with /, end with /, and may span several
    lines

10
Segment Directives
  • The assembler generates bytes for flash and
    EEPROM and reserves addresses in SRAM
  • Segment directives set the active memory for
    subsequent commands
  • .cseg code segment (flash)
  • This is the default segment if none is specified
  • .eseg EEPROM
  • .dseg data segment (SRAM)

11
Origin Directive
  • The assembler maintains a location counter for
    each segment
  • .org value
  • sets the location counter of the current segment
    to the specified value
  • The default origin for the code segment and
    EEPROM is 0000
  • The location counter for the data segment is the
    first address following the I/O registers (0060)

12
LED Flasher Program
  • A simple AVR example to illustrate output to a
    port.
  • Designed to be executed in a simulator under
    debug control
  • This program counts from 0 to 255 (and repeats)
    outputting
  • the current counter value to PORTB.
  • .cseg select current segment as code
  • .org 0 begin assembling at address 0
  • .def count r16 Reg 16 will hold counter
    value
  • .def temp r17 used as a temporary register
  • .equ PORTB 0x18 Port B's output register
  • .equ DDRB 0x17 Port B's Data Direction
    Register
  • ldi temp,0xFF configure PORTB as output
  • out DDRB,temp
  • ldi count,0x00 Initialize count at 0
  • lp
  • out PORTB,count Put counter value on PORT B
  • inc count increment counter
  • rjmp lp repeat (forever)

13
Assembling the Program
  • After creating a new project and entering the
    source code, the program is assembled using the
    Build command.
  • The option to create a listing file must be
    selected under Assembler Options under the
    Project menu
  • If errors occur, correct them and reassemble

14
Simulating the Program
  • Start debugging (Debug menu)
  • Select the I/O View and be sure that Register 16,
    the Processor, and PORT B are visible
  • Single step, observing changes in the I/O View
  • Use Auto-step to run the simulator while
    observing changes at each step

15
Using the STK-500
  • Setup the STK-500 as described in the included
    documentation
  • Connect the STK-500 to your computer's serial
    port and turn on the STK-500
  • Activate the AVR Programmer
  • Tools menu Program AVR Connect
  • Usually the Auto detect finds the board

16
Program Flash from HEX
  • On the Program Tab, you can accept defaults for
    everything but the input file under Flash
  • Use the browse () button to locate the HEX file
    with the same name as your project
  • It will be in the project folder
  • Click Program when ready

17
Internal Clock Speed
  • This program runs too fast under the default
    processor settings (4MHz internal oscillator)
  • The LEDs appear to all stay illuminated
  • Under the Fuses tab, select the Ext. Clock
  • Click Program to send the options to the processor

18
External Clock
  • Under the Board tab, set the STK500 Osc to 1024Hz
    and click Write
  • The processor should run slow enough to observe
    the leading bit cycling once per second
  • Note that the dialog indicates the clock will be
    set to the attainable frequency of 1019 Hz
  • Not all frequencies can be produced exactly

19
Backwards Counter
  • You should notice that the counter appears to run
    backwards
  • The circuit used to control the LEDs causes the
    LED to emit light when the port output is 0
  • 00000000
  • 00000001
  • etc appears to be counting backwards

20
External Oscillator
  • Be sure to set the STK500 Osc back to a larger
    value (4 MHz is fine) before downloading other
    programs
  • You must click Write to send the setting to the
    processor
  • If this value is too slow, the programmer cannot
    download code to flash
Write a Comment
User Comments (0)
About PowerShow.com