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

.include "C:\VMLAB\include\m8def.inc"

; Define here the variables
;
.def  temp  =r16

; Define here Reset and interrupt vectors, if any
;
reset:
   rjmp start
   reti      ; Addr $01
   reti      ; Addr $02
   reti      ; Addr $03
   reti      ; Addr $04
   rjmp		t1cpt	;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
   reti
   reti

t1cpt:
	in		r20,TCNT1L
	in		r21,TCNT1H
	clr	temp
	out	TCNT1H,temp
	out	TCNT1L,temp
;	cpi	r17,1
;	breq	set_res
	sbr	r17,1
;	rjmp	quit_t1cpt
;set_res:
;	clr	r17
;;	rjmp	quit_t1cpt
quit_t1cpt:			
	reti

; Program starts here after Reset
;
start:
	ldi	temp,low(RAMEND)
	out	SPL,temp
	ldi	temp,high(RAMEND)
	out	SPH,temp
	clr	temp
	out	PORTB,temp
	out	PORTC,temp
	out	PORTD,temp
	ldi	temp,0b11111111
	out	DDRD,temp
	out	DDRC,temp
	ldi	temp,0b11111110
	out	DDRB,temp
	clr	r20
	clr	r21
	clr	r17
   rcall	pusk
	clr	temp
	out	TIFR,temp
	out	TCNT1H,temp
	out	TCNT1L,temp
	ldi	temp,0b00100000
	out	TIMSK,temp
	ldi	temp,0b11000010
	out	TCCR1B,temp
   sei
main:
	cpi	r17,1
	brne	main
	rcall	test_out
rjmp main

test_out:
		clr	temp
		out	PORTD,temp
		out	PORTB,temp
		out	PORTC,temp
		ldi	r24, $98 
		ldi	r25, $3A   
		rcall	sub_DD
		brcs	loc_4C
		sbi	PORTB,1
loc_4C:					; CODE XREF: sub_47+3 j
		ldi	r24, $4C 
		ldi	r25, $1D   
		rcall	sub_DD
		brcs	loc_51
		sbi	PORTD,7
loc_51:					; CODE XREF: sub_47+8 j
		ldi	r24, $88 
		ldi	r25, $13   
		rcall	sub_DD
		brcs	loc_56
		sbi	PORTD,6
loc_56:					; CODE XREF: sub_47+D j
		ldi	r24, $A6 
		ldi	r25, $0E   
		rcall	sub_DD
		brcs	loc_5B
		sbi	PORTD,5
loc_5B:					; CODE XREF: sub_47+12 j
		ldi	r24, $B8 
		ldi	r25, $0B   
		rcall	sub_DD
		brcs	loc_60
		sbi	PORTB,7
loc_60:					; CODE XREF: sub_47+17 j
		ldi	r24, $C4 
		ldi	r25, $09  
		rcall	sub_DD
		brcs	loc_65
		sbi	PORTB,6
loc_65:					; CODE XREF: sub_47+1C j
		ldi	r24, $5E 
		ldi	r25, $08  
		rcall	sub_DD
		brcs	loc_6A
		sbi	PORTD,4
loc_6A:					; CODE XREF: sub_47+21 j
		ldi	r24, $53	
		ldi	r25, $07  
		rcall	sub_DD
		brcs	loc_6F
		sbi	PORTD,3
loc_6F:					; CODE XREF: sub_47+26 j
		ldi	r24, $82 
		ldi	r25, $06  
		rcall	sub_DD
		brcs	loc_74
		sbi	PORTD,2
loc_74:					; CODE XREF: sub_47+2B j
		ldi	r24, $DC 
		ldi	r25, $05 
		rcall	sub_DD
		brcs	loc_79
		sbi	PORTD,1
loc_79:					; CODE XREF: sub_47+30 j
		ldi	r24, $53 
		ldi	r25, $05   
		rcall	sub_DD
		brcs	loc_7E
		sbi	PORTD,0
loc_7E:					; CODE XREF: sub_47+35 j
		ldi	r24, $E2 
		ldi	r25, $04   
		rcall	sub_DD
		brcs	loc_83
		sbi	PORTC,5
loc_83:					; CODE XREF: sub_47+3A j
		ldi	r24, $81 
		ldi	r25, $04   
		rcall	sub_DD
		brcs	loc_88
		sbi	PORTC,4
loc_88:					; CODE XREF: sub_47+3F j
		ldi	r24, $2F 
		ldi	r25, $04  
		rcall	sub_DD
		brcs	loc_8D
		sbi	PORTC,3
loc_8D:					; CODE XREF: sub_47+44 j
		ldi	r24, $E8 
		ldi	r25, $03   
		rcall	sub_DD
		brcs	loc_92
		sbi	PORTC,2
loc_92:					; CODE XREF: sub_47+49 j
		ldi	r24, $A9 
		ldi	r25, $03   
		rcall	sub_DD
		brcs	loc_97
		sbi	PORTC,1
loc_97:					; CODE XREF: sub_47+4E j
		ldi	r24, $72 
		ldi	r25, $03   
		rcall	sub_DD
		brcs	loc_9C
		sbi	PORTC,0
loc_9C:					; CODE XREF: sub_47+53 j
		ldi	r24, $41 
		ldi	r25, $03  
		rcall	sub_DD
		brcs	loc_A1
		sbi	PORTB,5
loc_A1:					; CODE XREF: sub_47+58 j
		ldi	r24, $15 
		ldi	r25, $03   
		rcall	sub_DD
		brcs	loc_A6
		sbi	PORTB,4
loc_A6:					; CODE XREF: sub_47+5D j
		ldi	r24, $EE 
		ldi	r25, $02  
		rcall	sub_DD
		brcs	loc_AB
		sbi	PORTB,3
loc_AB:					; CODE XREF: sub_47+62 j
		ldi	r24, $CA 
		ldi	r25, $02   
		rcall	sub_DD
		brcs	locret_B0
		sbi	PORTB,2
locret_B0:				; CODE XREF: sub_47+67 j
	clr	r17
	ret
	
sub_DD:					; CODE XREF: sub_47+2 p	sub_47+7 p ...
		cp		r24, r20
		cpc	r25, r21
		ret
pusk:
		sbi	portb,1
		rcall	del_64		
		sbi	portd,7
		rcall	del_64		
		sbi	portd,6
		rcall	del_64		
		sbi	portd,5
		rcall	del_64		
		sbi	portb,7
		rcall	del_64		
		sbi	portb,6
		rcall	del_64		
		sbi	portd,4
		rcall	del_64		
		sbi	portd,3
		rcall	del_64		
		sbi	portd,2
		rcall	del_64		
		sbi	portd,1
		rcall	del_64		
		sbi	portd,0
		rcall	del_64		
		sbi	portc,5
		rcall	del_64		
		sbi	portc,4
		rcall	del_64		
		sbi	portc,3
		rcall	del_64		
		sbi	portc,2
		rcall	del_64		
		sbi	portc,1
		rcall	del_64		
		sbi	portc,0
		rcall	del_64		
		sbi	portb,5
		rcall	del_64		
		sbi	portb,4
		rcall	del_64		
		sbi	portb,3
		rcall	del_64		
		sbi	portb,2
		rcall	del_255		
      cbi	portb,2
      rcall	del_128
		cbi	portb,3
		rcall	del_128		
		cbi	portb,4
		rcall	del_128		
		cbi	portb,5
		rcall	del_128		
		cbi	portc,0
		rcall	del_128		
		cbi	portc,1
		rcall	del_128		
		cbi	portc,2
		rcall	del_128		
		cbi	portc,3
		rcall	del_128		
		cbi	portc,4
		rcall	del_128		
		cbi	portc,5
		rcall	del_128		
		cbi	portd,0
		rcall	del_128		
		cbi	portd,1
		rcall	del_128		
		cbi	portd,2
		rcall	del_128		
		cbi	portd,3
		rcall	del_128		
		cbi	portd,4
		rcall	del_128		
		cbi	portb,6
		rcall	del_128		
		cbi	portb,7
		rcall	del_128		
		cbi	portd,5
		rcall	del_128		
		cbi	portd,6
		rcall	del_128		
		cbi	portd,7
		rcall	del_128		
		cbi	portb,1
		ret	
del_64:
		ldi	r18,255
		ldi	r19,24	
cyc_64:
		subi	r18,1
		sbci	r19,0
		brne	cyc_64
		ret
		
del_255:
		ldi	r18,255
		ldi	r19,180	
cyc_255:
		subi	r18,1
		sbci	r19,0
		brne	cyc_255
		ret
		
del_128:
		ldi	r18,255
		ldi	r19,100	
cyc_128:
		subi	r18,1
		sbci	r19,0
		brne	cyc_128
		ret				





