Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assembly - Time Delay (Help Please !!! Please !!!)

Status
Not open for further replies.

Sathmaha

Programmer
Aug 4, 2003
8
0
0
GB
Hi Friends !

I'm a new one for assembly , But anyhow I wrote one program which is have to play the melody , But I stucked on the delay matter in assembly. Please you people try to give me the tip for that. (I have to create the Xmas melody) I need the time break/Delay clearly for that .Program I written is follows,

;Stack Setup
.equ RAMEND =$1FF ;Stack Address
.equ SPL =$3D ;Low Byte Stack Pointer
.equ SPH =$3E ;High Byte Stack Pointer

;ports

.equ DDRB =$17 ;Port B Data Direction Register
.equ PORTB =$18 ;Port B Output Address
.equ PINB =$16

;Timer
.equ TCNT0 =$32 ;Count contents
.equ TCCR0 =$33 ;Control Register

;Registers
.equ SREG =$3F

;Register Definitions
.def led =R0 ;Define register 0 as location to put data from table to send to led
.def count =R19 ;Define register 19 as a counter count
.def time =r20 ;Define register 17 as timer pre scale
.def save =r21 ;Define register 18 as save
.def ZL =R30 ;Define low byte of Z
.def ZH =R31 ;Define high byte of Z

;Initialisation of stack address and stack pointer
start: ldi R16,low(RAMEND)
out SPL,R16
ldi R16,high(RAMEND)
out SPH,R16

;Initialisation of output ports
ldi R16,$ff
out DDRB,R16

;main program
reset: ldi ZL,low(table*2) ;Set table pointer
ldi ZH,high(table*2)

clr count ;Clear counter
next: rcall delay ;Call delay subroutine
lpm ;Load R0 with data pointed to by Z
adiw ZL,1 ;Increment Z to point to next location
out PORTB,R0 ;Display to port B
inc count
cpi count,8
brne next
rjmp reset

;delay subroutine
delay: in save,SREG ;Preserve status register
ldi time,$05 ;load pre scalar
out TCCR0,time
ldi time, $00
out TCNT0,time
clock: in time,TCNT0
cpi time,7
breq timeout
rjmp clock
timeout: out SREG,save ;Restore Status Register
ret

table: .DB $D,$6,$6,$E,$E,$E
 
Try using the following. The procedure 'timer' has to be called with cx set to the value in seconds that you want to delay for.
Code:
assume cs:code

code segment
  org 100h
program:
  jmp start

  sec db ?

start:

  mov cx,0030h
  call timer

  mov ax,4c00h
  int 21h


; input: cx is value to delay for.
;        (approximate to seconds).
timer:
  sub bx,bx

  mov al,00h ; seconds address
  out 70h,al ; wake up port
  jmp $+2    ; a short delay
  in al,71h
  mov [sec],al

timer_loop:
  mov al,00h ; seconds address
  out 70h,al ; wake up port
  jmp $+2    ; a short delay
  in al,71h
  cmp al,[sec]
  je timer_loop
  ; second gone by...
  mov [sec],al
  inc bx
  cmp bx,cx
  jne timer_loop
  ret

code ends

end program
Good luck with the xmas tune :)

Adonai


The mind is like a parachute - it works better when open...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top