;
; buffer/parse whole strings and decide whether to send to card or not.
+; some defines
+; ------------
+
+; baudrate = clock freq / etu
+; std smartcard etu: 372
+; other smartcards: 625
+.define clock 8000000
+.define clk_h 4000000
+.define etu 625
+.define etu_h 312
+.define baudrate 5 ; UBRR value for 76800 bits/s (8mhz clock)
+
+; names for registers
+.define tmp r16
+.define bitcount r17
+.define tmp1 r18
+.define tmp2 r19
+.define byte r20
+.define overflow_counter r21
+.define one r1
+.define zero r0
+
+
+;
+; programm code
+; -------------
+
;
; interrupt vectors:
;
; init routine
;
-MAIN:
-rjmp MAIN
-
INIT:
; set stackpointer
-ldi r16,low(RAMEND)
-out SPL,r16
+ldi tmp,low(RAMEND)
+out SPL,tmp
; enable interrupts int0,int1
-ldi r16,((1<<INT0)|(1<<INT1))
-out GIMSK,r16
+ldi tmp,((1<<INT0)|(1<<INT1))
+out GIMSK,tmp
; int0/1 setup
-ldi r16,((1<<ISC01)|(1<<ISC00)|(1<<ISC10)|(1<<ISC11))
-out MCUCR,r16
+ldi tmp,((1<<ISC01)|(0<<ISC00)|(1<<ISC11)|(0<<ISC10))
+out MCUCR,tmp
; enable t/c overflow interrupt and icp
-ldi r16,((1<<TOIE1)|(1<<TICIE1))
-out TIMSK,r16
+ldi tmp,((1<<TOIE1)|(1<<TICIE1))
+out TIMSK,tmp
; setup t/c and icp
-ldi r16,((1<<CS12)|(1<<CS11)|(1<<CS10)|(1<<ICNC1))
-out TCCR1B,r16
+ldi tmp,((1<<CS12)|(1<<CS11)|(1<<CS10)|(1<<ICNC1)|(1<<ICES1))
+out TCCR1B,tmp
; configure uart - interrupt enabled when i/o
-ldi r16,3
-out UBRR,r16
+ldi tmp,baudrate
+out UBRR,tmp
sbi UCR,TXEN
-; init bitcounter and overflow counter
-ldi r20,0 ; bitcounter
-ldi r21,0 ; register for constructing the byte
-ldi r22,0 ; overflow counter
-ldi r23,0 ; temp reg
-
-; constant 1 in r1
-ldi r16,1
-mov r1,r16
+; init registers
+ldi bitcounter,0
+ldi byte,0
+ldi overflow_counter,0
+ldi tmp1,0
+ldi tmp2,0
+ldi tmp,1
+mov one,tmp
+ldi tmp,0
+mov zero,tmp
; enable interrupts (global)
sei