Sign In

Stopping The Program After 60 Seconds

Callum callum.hyland95@hotmail.com Australia

Hardware: ATMEGA32A Running On An OUSB Board Software: Assembly In VMLAB

I have a sound impact sensor and counting the high's read by it. Putting up the number in binary on some LEDS (later on an LCD too). But I want it to stop after 60 seconds and just show whatever the last number was. Any help would be amazing

Images

Program

; ******************************************************
; BASIC .ASM template file for AVR
; ******************************************************

.include "H:UniProgramsVMLABincludem32def.inc"

; Define here the variables
;
.def  Temp  =r16
.def  Beat	=r17
.def	One	=r18
.def	Count	=r24

.CSEG

;--------------- Define here Reset and interrupt vectors, if any --------------------------
;
.ORG  0x00

START:
   rjmp RESET
   reti      ; Addr $01
   reti      ; Addr $02
   reti      ; Addr $03
   reti      ; Addr $04
   reti      ; Addr $05
   reti      ; Addr $06        Use 'rjmp myVector'
   reti      ; Addr $07        to define a interrupt vector
   reti      ; Addr $08
   reti      ; Addr $09
   reti      ; Addr $0A
   reti      ; Addr $0B        This is just an example
   reti      ; Addr $0C        Not all MCUs have the same
   reti      ; Addr $0D        number of interrupt vectors
   reti      ; Addr $0E
   reti      ; Addr $0F
   reti      ; Addr $10


;******************************** Device Initialization ********

.ORG  0x20
reset:
	
	ldi	TEMP, low(RAMEND)
	out	SPL,	TEMP
	ldi	TEMP,	high(RAMEND)
	out	SPH,	TEMP
	
	ldi	TEMP,		$FF
	out	DDRB,		TEMP
	out	PORTB,	TEMP
	ldi	TEMP,		$00
	out	DDRC, 	TEMP
	ldi	one,		$1
	ldi	count,	$0	

	
;******************************** Start Loop **********************
loop:
	call	Read	
	call	Display
	call	Delay
	call 	Delay
	call 	Timer
rjmp	loop

;******************************** Call Timer **********************
Timer:
	cpi	Count,	2000
		BRSH	Finish
	add	Count, one
ret

;******************************** Detect Input from Sensor ********
Read:
	in 	TEMP, PINC	
	nop
	nop
	nop

	cpi	TEMP,	0
	BRNE	Function
ret


;******************************** Increment the Output & Timer ****
Function:
	add	Beat, one	
ret	


;******************************** Output to LEDS ******************
Display:	
	out	PORTB,	Beat	
ret


;******************************** Delay Loop **********************
Delay:
         PUSH R16			; save R16 and 17 as we're going to use them
         PUSH R17       ; as loop counters
         PUSH R0        ; we'll also use R0 as a zero value for compare
         CLR R0
         CLR R16        ; init inner counter
         CLR R17        ; and outer counter
L1:      DEC R16         ; counts down from 0 to FF to 0
			CPSE R16, R0    ; equal to zero?
			RJMP L1			 ; if not, do it again
			CLR R16			 ; reinit inner counter
L2:      DEC R17
         CPSE R17, R0    ; is it zero yet?
         RJMP L1			 ; back to inner counter
;
         POP R0          ; done, clean up and return
         POP R17
         POP R16
ret


;******************************** Finish ****************************
Finish:
	
rjmp	Finish

Post a reply to Callum

Think you can help Callum ? Then post your thoughts that might help Callum. You will earn a lot of reputation in the technical community.

If your program is in multiple files, then ZIP the entire folder and attach below

Images and Screenshots

These helps other better understand your suggestion.