0 Replies - 9480 Views - Last Post: 25 November 2011 - 04:07 PM

#1 codebuzz   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 75
  • Joined: 07-October 10

Program in Assembly that creates a Ring Counter

Posted 25 November 2011 - 04:07 PM

Hello guys,

I was stucked in this program and I will like if anyone here could help me. I have to write an Assembly language program that creates a Ring Counter. This is the details and the code snippet I have already written.

Write a program in Assembly language that creates a Ring Counter. The values should be displayed with the LEDs. Use shift instructions, LSL or LSR. Make a delay of approximately 0.5 sec in between each count. Write the delay as a
subroutine. For using the subroutine, you must initialize the Stack Pointer, SP. Include the
following instructions in beginning of your program:

ldi r20, HIGH(0x45F) ;R20 = high part of RAMEND address
out 0x3E,R20 ;SPH = high part of RAMEND address
ldi R20, low(0x45F) ;R20 = low part of RAMEND address
out 0x3D,R20 ;SPL = low part of RAMEND address
Function, the 8 LEDs:
(0000 0001, 0000 0010, 0000 0100, 0000 1000, 0001 0000, 0010 0000, 0100 0000,
1000 0000)

.include "m2560def.inc"

.CSEG

.ORG 0x10
Start:

ldi r20, HIGH(0x45F) ; R20 = high part of RAMEND address
out 0x3E,R20         ; SPH = high part of RAMEND address
ldi R20, low(0x45F)  ; R20 = low part of RAMEND address
out 0x3D,R20         ; SPL = low part of RAMEND address


loop_1:
ldi r16, 0xFF           ; r16 = limit value
out 0x17, r16           ; r17 = lopp counter
ldi r16, 0b00000001
com r16
out 0x18, r16
com r16

rcall loop_1


delay
push r24
push r25

ldi r24, 0xFF
ldi r25, 0xFF

brne wait_2
sbiw r25:r24,1

brne wait_2
pop r25
pop r24
ret


 


Is This A Good Question/Topic? 0
  • +

Page 1 of 1