just commited to continue work on hackstation ;)
[my-code/atmel.git] / beginners / season_junior.asm
index 94ba21c..540c152 100644 (file)
@@ -6,15 +6,32 @@
 
 ; at90s2313
 ; setup:
-; vcc card --- vcc cam
-; rst card --- rst cam --- atmel t0 (pd4)
-; clk card --- clk cam --- atmel t1 (pd5)
+; vcc card --- atmel vcc
+; vcc cam  --- 
+; rst cam  --- atmel int0 (pd2)
+; rst card --- atmel (pb4)
+; clk card -\ 
+;            -  atmel t1 (pd5)
+; clk cam  -/
 ; gnd card --- gnd cam --- atmel gnd
-; i/o card --- atmel int0 (pd2)
+; i/o card --- atmel icp (pd6)
 ; i/o cam  --- atmel int1 (pd3)
 
-include "../include/2313def.inc"
+.include "../include/2313def.inc"
 
+; functions by now:
+;
+; stupid mode only by now. just see what cam/card do and redirect
+; this to card/cam.
+;
+; next implementation:
+; 
+; try to read one byte of card/cam communication and output via uart.
+; output time information in some way.
+;
+; future:
+;
+; buffer/parse whole strings and decide whether to send to card or not.
 
 ;
 ; interrupt vectors:
@@ -24,19 +41,19 @@ include "../include/2313def.inc"
 rjmp INIT
 
 ; int0
-rjmp REC_CARD
+rjmp RST_CAM
 
 ; int1
 rjmp REC_CAM
 
 ; timer/counter capt 1
-reti
+rjmp REC_CARD
 
 ; timer/counter compare
 reti
 
 ; timer/counter overflow 1
-rjmp T1_OVERFLOW
+rjmp CLK_OVERFLOW
 
 ; timer/counter overflow 0
 reti
@@ -45,7 +62,7 @@ reti
 reti
 
 ; uart data register empty
-reti
+rjmp UART_OUT
 
 ; uart tx complete
 reti
@@ -57,37 +74,141 @@ reti
 ; init routine
 ;
 
+MAIN:
+rjmp MAIN
+
 INIT:
 
 ; set stackpointer
 ldi r16,low(RAMEND)
 out SPL,r16
 
+;
+; hier weiter ....
+;
+
 ; enable interrupts int0,int1
 ldi r16,((1<<INT0)|(1<<INT1))
 out GIMSK,r16
 ; int0/1 setup
-ldi r16,((1<<ISC01)|(1<<ISC00)|(1<<ISC11)|(1<<ISC10))
+ldi r16,((1<<ISC01)|(1<<ISC00)|(1<<ISC10)|(1<<ISC11))
+out MCUCR,r16
+in r16,MCUCR
+sbic PORTD,PD2
+cbr r16,ISC00
+out MCUCR,r16
+sbic PORTD,PD3
+cbr r16,ISC10
 out MCUCR,r16
-sbis PORTD,PORTD2
-cbi MCUCR,ISC00
-sbis PORTD,PORTD3
-cbi MCUCR,ISC10
 
 ; enable t/c overflow interrupt
-sbi TIMSK,TOIE1
+ldi r16,(1<<TOIE1)
+out TIMSK,r16
 ; setup t/c
 ldi r16,((1<<CS12)|(1<<CS11)|(1<<CS10))
 out TCCR1B,r16
 
+; init bitcounter and overflow counter
+ldi r20,0 ; bitcounter
+ldi r21,0 ; register for constructing the byte
+ldi r22,0 ; overflow counter
+
+; constant 1 in r1
+ldi r16,1
+mov r1,r16
+
 ; enable interrupts (global)
 sei
 
 ;
-; rec_card routine
+; rec_card routines
 ;
 
 REC_CARD:
 
-; get port status
-in .... continue here .. :)
+; int0 -> input, int1 -> output
+ldi r16,(1<<DDD3)
+out DDRD,r16
+
+; decide what to do
+sbic PORTD,PD2
+rjmp REC_CARD_HIGH
+rjmp REC_CARD_LOW
+
+REC_CARD_HIGH:
+
+; output high on port to cam
+ldi r16,(1<<PD3)
+out PORTD,r16
+
+; toggle int0 sense
+in r16,MCUCR
+cbr r16,ISC00
+out MCUCR,r16
+
+reti
+
+REC_CARD_LOW:
+
+; output low on port to cam
+ldi r16,0
+out PORTD,r16
+
+; toggle int0 sense
+in r16,MCUCR
+cbr r16,ISC00
+out MCUCR,r16
+
+reti
+
+;
+; rec_cam routines
+;
+
+REC_CAM:
+
+; int1 -> input, int0 -> output
+ldi r16,(1<<DDD2)
+out DDRD,r16
+
+; decide what to do
+sbic PORTD,PD3
+rjmp REC_CAM_HIGH
+rjmp REC_CAM_LOW
+
+REC_CAM_HIGH:
+
+; output high on port to card
+ldi r16,(1<<PD2)
+out PORTD,r16
+
+; toggle int1 sense
+in r16,MCUCR
+cbr r16,ISC10
+out MCUCR,r16
+
+reti
+
+REC_CAM_LOW:
+
+; output low on port to card
+ldi r16,0
+out PORTD,r16
+
+; toggle int 1 sense
+in r16,MCUCR
+cbr r16,ISC10
+out MCUCR,r16
+
+reti
+
+;
+; t1_overflow routine
+;
+
+T1_OVERFLOW:
+
+add r22,r1 ; inc counter overflow register
+
+reti
+