02b_avrassembly
Upcoming SlideShare
Loading in...5
×
 

02b_avrassembly

on

  • 400 views

 

Statistics

Views

Total Views
400
Views on SlideShare
400
Embed Views
0

Actions

Likes
0
Downloads
8
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

02b_avrassembly 02b_avrassembly Presentation Transcript

  • AVR Assembly Language An Introduction Assembly Language Programming University of Akron Dr. Tim Margush
  • Assemblers
    • Translate source code to machine language
    source Assembler include files object file hex file map file list file
  • 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
  • Object File
    • Contains machine program and debugging information used by AVR Studio
  • Hex File
    • Contains data for AVR Processor flash memory
    • This is used by the programmer utility to download to AVR memory
  • Map File
    • A list of labels and symbols used in the program
    • Serves as a reference to locate data in memory
  • Listing File
    • A complete report of the assembly process
      • Includes error messages, address information, bytes generated, and statistics
  • 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
  • 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
  • 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)
  • 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)
  • 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)
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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