[CODE] [ASM] Long delay generation interrupt driven

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Freaks...

I used this code to generate long delay, i.e. 1 hour at 11,0592 MHz XTAL, using Timer0 interrupt.
This routine assign the AVR to toggle the LED when reach timeout.

include "m8535def.inc"

.def smtr = r16
.def menuju1dtk = r17
.def cacahdtk = r18
.def cacahmnt = r19

.cseg
.org 0
rjmp main
.org 0x009
rjmp melimpah

;------------------------ISR-------------------------------
melimpah:
		inc menuju1dtk
		cpi menuju1dtk, 43
		in smtr, SREG
		sbrc smtr, 1
		rcall sdh1dtk
		
		reti

;---------------------------------
sdh1dtk:
		clr menuju1dtk
		inc cacahdtk
		cpi cacahdtk, 60
		in smtr, SREG
		sbrc smtr, 1
		rcall sdh1mnt
		ret

;---------------------------------
sdh1mnt:
		clr cacahdtk
		inc cacahmnt
		cpi cacahmnt, 60
		in smtr, SREG
		sbrc smtr, 1
		rcall timeout
		ret

;----------------------------------
timeout:
		clr cacahdtk                     ;the delay reach timeout
		clr cacahmnt                    ; you can assign other
		in smtr, PORTD
		com smtr
		out PORTD, smtr
		ret

;-----------------------------------------------------------------------

main:
		ldi smtr, high(RAMEND)
		out SPH, smtr
		ldi smtr, low(RAMEND)
		out SPL, smtr

;aktifkan timer
		clr menuju1dtk
		clr cacahdtk
		clr cacahmnt
		ldi smtr, 0b00000101
		out TCCR0, smtr

		ldi smtr, 1
		out TIMSK, smtr
		;ldi smtr, 250
		;out TCNT0, smtr
		sei
		
		ser smtr                
		out DDRD, smtr
		ldi smtr, 0xF0
		out PORTD, smtr

loop:
		rjmp loop       ;this is your main routine

;----------------------------------------end of code-----------------------------------

The important values are :

43 in cpi menuju1dtk, 43 -> obtained by calculate 1 second / tme needed to overflow of Timer0

60 in cpi cacahdtk, 60 -> to obtain 1 minute delay (60 seconds)

60 in cpi cacahmnt, 60 -> to obtain 1 hour delay (60 seconds)

The delay can be longer if you change the above values with the higher number. :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just one question,

Can you hightlight the text of the code and then hit the code button. For me, anyway, it makes the code much easer to read due to the additional formating.

Thanks.

You can avoid reality, for a while.  But you can't avoid the consequences of reality! - C.W. Livingston

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks Carl,

Quote:

Can you hightlight the text of the code and then hit the code button.

What did you mean?
I don't understand

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Already did it for you this morning :).

What Carl means is when you post code, use the "Code" tags so that the forum software formats your code so that it remains readable (see your original post to see how the code tag formats your code differently. You should encase your code in [ code ] and [ /code ] tags (no spaces).

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oh I see

Thans Dean. The Code Tags, .... yes I see it.
Maybe next time when I post something, I'll remember it.