Docsity

AVR Assembly Program for Racing Lights: Init and Start - Prof. Stephen Kuyath, Study Guides, Projects, Research of Microprocessors

Toggle sidebar
bg1
Introduction to Microprocessors
Topic 6
Example 1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f

Partial preview of the text

Download AVR Assembly Program for Racing Lights: Init and Start - Prof. Stephen Kuyath and more Study Guides, Projects, Research Microprocessors in PDF only on Docsity!

Introduction to Microprocessors

Topic 6

Example 1

Objectives

  • Review and follow the development process to
    • Write a simple assembly language program
    • Assemble the program
    • Simulate the program

Development Process

  1. Simulate the program in the IDS
    1. Remove all logic errors
    2. Go to step 4 and repeat 4 & 5 until all logic errors are removed

7. Program the AVR

1. Remove errors:

1. Example: Target range of addresses could be incorrect
2. Example: Expected support ICs may be missing
3. Go to step 4 and repeat 4, 5, & 6 until all errors are removed

8. Test the program on the hardware

1. Remove errors:

1. Example: I/O port addresses may be incorrect
2. Example: Logic for interfaced hardware may be incorrect
3. Example: Timing may be incorrect
4. Go to step 4 and repeat 4, 5, 6, & 7 until all errors are removed
* The various books for this class have slightly different steps

Development Process

  • So, we have to find out what to do ….. (step 1)

Lights

  • The LEDs should appear as shown:

and then repeat

Development Process

1. Gather and verify all project requirements and specifications

2. Layout a plan for your program

1. Pseudo-code, algorithm, or flowchart (maybe all 3)

3. Choose a target processor or controller

4. Write the program using a text editor or an Integrated

Development System (IDS)

5. Assemble the program

1. Remove syntax errors and re-assemble until all errors are removed

Continued……

Enter Program

1. Gather and verify all project requirements and specifications

2. Layout a plan for your program

1. Pseudo-code, algorithm, or flowchart (maybe all 3)

3. Choose a target processor or controller (we’ll use the ATmega128)

4. Write the program using a text editor or an Integrated

Development System (IDS)

5. Assemble the program

1. Remove syntax errors and re-assemble until all errors are removed

Continued……

Enter Program

  • We can use AVR Studio or a text editor
    • I’ll choose AVR Studio
  • Load the template developed in Topic 5

Enter Program

  • Remove any lines that are

not necessary

;Racing Lights ;Written by: Cosmo Kramer ;Date: 1/23/ ;ver: 1. ;file: C:\Documents and Settings\Cosmo\My Documents\Project2\Rlights.asm ;Device: ATMega ;======================================================== .nolist .include "C:\Program Files\Atmel\AVR Tools\AvrAssembler2\Appnotes\m128def.inc" .list ;=========================== ; Declarations .device xxxxxxx .def temp =r16 ;name register 16 ;=========================== Init: ldi temp,0bxxxxxxxx ;setup inputs and outputs for PortB out DDRB,temp ldi temp,0bxxxxxxxx ;sets pull up resistors for Port B out PortB,temp ; and initial values for outputs ;============================ ;Start Program Start: Your program goes here rjmp Start ;=================================

We only need one register

We are only using one port (I

chose port B)

Enter Program

  • Name the device
  • Name the register (optional)

;Racing Lights ;Written by: Cosmo Kramer ;Date: 1/23/ ;ver: 1. ;file: C:\Documents and Settings\Cosmo\My Documents\Project2\Rlights.asm ;Device: ATMega ;======================================================== .nolist .include "C:\Program Files\Atmel\AVR Tools\AvrAssembler2\Appnotes\m128def.inc" .list ;=========================== ; Declarations .device ATmega .def lights =r16 ;name register 16 ;=========================== Init: ldi temp,0bxxxxxxxx ;setup inputs and outputs for PortB out DDRB,temp ldi temp,0bxxxxxxxx ;sets pull up resistors for Port B out PortB,temp ; and initial values for outputs ;============================ ;Start Program Start: Your program goes here rjmp Start ;=================================

Enter Program

  • We are now ready to write

the program

  • Look at the algorithm

;Racing Lights ;Written by: Cosmo Kramer ;Date: 1/23/ ;ver: 1. ;file: C:\Documents and Settings\Cosmo\My Documents\Project2\Rlights.asm ;Device: ATMega ;======================================================== .nolist .include "C:\Program Files\Atmel\AVR Tools\AvrAssembler2\Appnotes\m128def.inc" .list ;=========================== ; Declarations .device ATmega .def lights =r16 ;name register 16 ;=========================== Init: ldi lights,0b11111111 ;setup inputs and outputs for PortB out DDRB,lights ldi lights,0b100000000 ;set initial values for outputs out PortB,lights ;============================ ;Start Program Start: Your program goes here rjmp Start ;=================================

Algorithm

  • Algorithm: Step-by-step procedure for solving this “problem”

1. Initialize the AVR

  1. May want to name a “working” register
  2. Make all pins on a port outputs
1. I’ll choose Port B
  1. Load a register with the initial output data
1. Could be 10000000 or 00000001 depending on which end you want to start on

2. Send data to the output port

3. Shift data once to the right

4. Go back to 2

Algorithm

  • Algorithm: Step-by-step procedure for solving this “problem”

1. Initialize the AVR

  1. May want to name a “working” register
  2. Make all pins on a port outputs
1. I’ll choose Port B
  1. Load a register with the initial output data
1. Could be 10000000 or 00000001 depending on which end you want to start on

2. Send data to the output port

3. Shift data once to the right

4. Go back to 2

Enter Program

  • Output data to the output

port (we need it here again

for our loop)

  • Use the out command
    • Look up out in documentation
    • Do this for every command
until you are familiar with
them

;Racing Lights ;Written by: Cosmo Kramer ;Date: 1/23/ ;ver: 1. ;file: C:\Documents and Settings\Cosmo\My Documents\Project2\Rlights.asm ;Device: ATMega ;======================================================== .nolist .include "C:\Program Files\Atmel\AVR Tools\AvrAssembler2\Appnotes\m128def.inc" .list ;=========================== ; Declarations .device ATmega .def lights =r16 ;name register 16 ;=========================== Init: ldi lights,0b11111111 ;setup inputs and outputs for PortB out DDRB,lights ldi lights,0b100000000 ;set initial values for outputs out PortB,lights ;============================ ;Start Program Start: out PortB,lights ; sends data to Port B (1 lights LED) rjmp Start ;=================================