Author: Not specified Language: asm
Description: Not specified Timestamp: 2017-09-18 15:36:13 +0000
View raw paste Reply
  1. .include "m328def.inc"; include library for the AVR ATmega328 microcontroller
  2. .org 0x0000
  3.         RJMP begin; jump to 'begin'
  4. .org 0x0034; sets initial program address at 0x0034  
  5. begin:  CLI; disables interrupt bit
  6.                 LDI    R16,low(RAMEND); loads the low value of RAMEND into a register
  7.         OUT    SPL,R16; sets stack pointer SPL
  8.         LDI    R16,high(RAMEND); loads the high value of RAMEND into a register
  9.         OUT    SPH, R16; sets stack pointer SPH
  10.                 LDI    R16,0xFF
  11.         OUT    DDRD, R16; sets DDRD as 0xFF to set all pins of PORTD to output
  12. looper: LDI    R16,0xFF; defines the starting of an infinite loop
  13.         OUT    PORTD, R16; sets all pins of PORTD to high
  14.         RCALL  Delay; calls a subroutine starting at 'Delay' to create a delay of a
  15.                         second while the LED is on
  16.         LDI    R16,0x00
  17.         OUT    PORTD, R16; sets all pins of PORTD to low
  18.                 RCALL  Delay; calls a subroutine starting at 'Delay' to create a delay of a
  19.                         second while the LED is on
  20.                 RJMP   looper; jumps back to 'looper' to the next iteration of the loop
  21.  
  22. Delay:  LDI    R17, 0x99; defines the starting of the subroutine loop with the looping
  23.                                 variable at 0x99 (=153)
  24. loop:   RCALL  Delay2; calls a nested subroutine 'Delay2'
  25.                 DEC    R17; decreases the looping value stored in the register
  26.         BRNE   loop; if value at R17 is not zero, jumps back to 'loop' else continues
  27.         RET; returns to address where subroutine was called from
  28. Delay2: LDI    R18, 0xFF; defines the starting of the subroutine loop with the looping
  29.                                 variable at 0xFF (=255)
  30. loop2:  RCALL  Delay3; calls a nested subroutine 'Delay3'
  31.                 DEC    R18; decreases the looping value stored in the register
  32.         BRNE   loop2; if value at R18 is not zero, jumps back to 'loop2' else continues
  33.         RET; returns to address where subroutine was called from
  34. Delay3: LDI    R19, 0xFF; defines the starting of the subroutine loop with the looping
  35.                                 variable at 0xFF (=255)
  36. loop3:  DEC    R19; decreases the looping value stored in the register
  37.                 BRNE   loop3; if value at R19 is not zero, jumps back to 'loop3' else continues
  38.         RET; returns to address where subroutine was called from
View raw paste Reply