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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

X'mas Melody Program - Need Help

Status
Not open for further replies.

Sathmaha

Programmer
Aug 4, 2003
8
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) How can i make that ? Please anybody who's having genrous and good heart please help me to come out...I'm struggling here !!!!!!!! and If anybody know where I can find the source code please let me know.

.Program I written is follows, (Using the ATML AVR processror - AT90S85151SP ) , I dont know whether its correct.

;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
 
Look at your other thread.
You shouldn't create a new thread for the same problem.


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

Part and Inventory Search

Sponsor

Back
Top