Welcome stranger

stopky.txt

; definice pro nas typ procesoru
.include "m169def.inc"
; podprogramy pro praci s displejem
.org 0x1000
.include "print.inc"

.cseg

; Zacatek programu - po resetu
.org 0x0000
	jmp start

.org 0x000A
	jmp int_T2

; Zacatek programu - hlavni program
.org 0x100
start:
    ; Inicializace zasobniku
	ldi r16, 0xFF			;proc ne 0x00 ??
	out SPL, r16
	ldi r16, 0x04
	out SPH, r16

    ; Inicializace displeje
	call init_disp

	; nastaveni pro port E
	in r17, DDRE
	andi r17, 0b11110011
	in r16, PORTE
	ori r16, 0b00001100
	out DDRE, r17
	out PORTE, r16
	ldi r16, 0b00000000
	sts DIDR1, r16

	; nastaveni pro port B
	in r17, DDRB
	andi r17, 0b00101111
	in r16, PORTB
	ori r16, 0b11010000
	out DDRB, r17
	out PORTB, r16
;************************************************************
	call reset	;reset cisel na 0
	call print1	;vypise nuly
	jmp controls
;************************************************************
init:		;INIT preruseni
	cli 	;globalni zakazani preruseni

	ldi r16, 0b00001000
	sts ASSR,r16	;vyber krystaloveho oscilator 32768 Hz

	ldi r16, 0b00000001
	sts TIMSK2, r16	;povoleni preruseni od casovace 2

	ldi r16, 0b00000111
	sts TCCR2A, r16	;spusteni citace s delicim pomerem 128

	clr r16			
	out EIMSK, r16	;zakaz preruseni od joysticku

	sei				;globalni povoleni preruseni

	jmp countdown

	int_T2: 		;obsluha preruseni
		clr r22
		incrDesLoop:
			call print1	; vypise cilsa
			call controls2	; ovladani za behu -> STOP
			
			clr r24		; TODO : spomalovaci smicka pro desetinky
			i:
				inc r24
				cpi r24,5; TODO
				brne i

			inc r22
			cpi r22,9
		brne incrDesLoop
		
		call inc_sec1 ;zvisi sekundu		
	reti
;************************************************************
countdown: ;jenom odpocitavani bez presnosti
	call int_T2
jmp countdown
;************************************************************
controls:	;	ovladani joysticku kdyz nepocitame
			; 	preskoc instrukci, pokud 4. bit v registru PINB ==1
	;sbis PINB,4 	;	mid   -  stop
	;jmp	controls

	sbis PINE,2 	;	left  -  reset
to_reset:
	call reset

	sbis PINE,3 	;	right -  start
	;jmp countdown
	jmp init
	 
jmp controls
;************************************************************
controls2:	;	kdyz je pustene odpocitavani
	sbis PINB,4 	;	mid   -  stop
	jmp	controls

	sbis PINE,2 	;	left  -  reset
	jmp to_reset
ret
;************************************************************
print1:		;vypis cisla
	clr r17
	ldi r17,2	
	mov r16, r18
	subi r16,-'0'
	call show_char
	
	inc r17	
	mov r16, r19
	subi r16,-'0'
	call show_char
	
	inc r17	
	mov r16, r20
	subi r16,-'0'
	call show_char
		
	inc r17	
	mov r16, r21
	subi r16,-'0'
	call show_char
		
	inc r17	
	mov r16, r22
	subi r16,-'0'
	call show_char		
ret
;************************************************************

inc_sec1: 
	ldi r22,0
	inc r21
	cpi r21,10	;	MM:S10:D
	breq inc_sec2
;jmp countdown
ret
inc_sec2:
	ldi r21,0
	inc r20
	cpi r20, 6	;	MM:6S:D
	breq inc_min1
;jmp countdown
ret
inc_min1:
	ldi r20,0
	inc r19
	cpi r19, 10	;	M10:SS:D
	breq inc_min2
;jmp countdown
ret
inc_min2:
	ldi r19,0
	inc r18
	cpi r18,10	;	10M:SS:D
	breq reset
;jmp countdown
ret
;************************************************************
reset:			;vynuluj cisla
	ldi r18,0	; M
	ldi r19,0	; M
	ldi r20,0	; S
	ldi r21,0	; S
	ldi r22,0	; DS
ret
;************************************************************
; Zastavime program - nekonecna smycka
rjmp PC