debug messages + slee
[my-code/atmel.git] / beginners / season_junior.asm
index 35d51d1..9171e7c 100644 (file)
@@ -30,7 +30,7 @@
 ; other smartcards: 625
 .equ etu = 625
 .equ etu_h = 312
-.equ baudrate = 5 ; UBRR value for 76800 bits/s (8mhz clock)
+.equ baudrate = 8 ; UBRR value for 57600 bits/s (8mhz clock)
 
 ; sizes
 .equ uart_data_len = 4
 .equ GODLIKE_F = 4
 .equ INCREDIBLE_HACK = (1<<4) ; destroy all your hardware
 .equ INCREDIBLE_HACK_F = 5 
+; leds
+.equ LED_CARD = PB0
+.equ LED_CAM = PB1
+.equ LED_FWD_TO_CAM = PB2
+.equ LED_FWD_TO_CARD = PB3
+.equ LED_OVERFLOW = PB4
 
 ; but there is only stupid and cool mode right now %)
 
@@ -127,11 +133,11 @@ cbi PORTD,PD4
 ldi tmp,low(RAMEND)
 out SPL,tmp
 
-; enable interrupts int0,int1
+; enable interrupts int0,int1,sleep
 ldi tmp,((1<<INT0)|(1<<INT1))
 out GIMSK,tmp
 ; int0/1 setup
-ldi tmp,((1<<ISC01)|(0<<ISC00)|(1<<ISC11)|(0<<ISC10))
+ldi tmp,((1<<ISC01)|(0<<ISC00)|(1<<ISC11)|(0<<ISC10)|(1<<SE))
 out MCUCR,tmp
 
 ; enable t/c overflow interrupt and icp
@@ -145,10 +151,20 @@ out TCCR1B,tmp
 ldi tmp,baudrate
 out UBRR,tmp
 sbi UCR,TXEN
+; debug
+.ifdef DEBUG
+ldi tmp,0x49
+out UDR,tmp
+.endif
 
 ; enable pullups on int0, int1, clk, icp io ports
 ldi tmp,((1<<PD2)|(1<<PD3)|(1<<PD5)|(1<<PD6))
 
+; pb 0-4 output high
+ldi tmp,((1<<PB0)|(1<<PB1)|(1<<PB2)|(1<<PB3)|(1<<PB4))
+out DDRB,tmp
+out PORTB,tmp
+
 ; init registers
 ldi bitcount,0 
 ldi byte,0
@@ -179,7 +195,16 @@ rjmp MAIN
 
 MAIN:
 
-; loop and wait for interrupts
+; debug
+.ifdef DEBUG
+ldi tmp,0x4d
+out UDR,tmp
+.endif
+
+; sleep/wait for next interrupt
+sleep
+
+; go to sleep again
 rjmp MAIN
 
 ; ----------------
@@ -188,10 +213,19 @@ rjmp MAIN
 
 REC_CARD:
 
+.ifdef DEBUG
+ldi tmp,0x52
+out UDR,tmp
+.endif
+
 ; input & pullup
 cbi DDRD,DDD6
 sbi PORTD,PD6
 
+; activate led
+sbi PORTB,LED_CAM
+cbi PORTB,LED_CARD
+
 ; toggle state
 eor state,state_m
 
@@ -219,6 +253,11 @@ reti
 
 CALC_DELTA_CLOCK:
 
+.ifdef DEBUG
+ldi tmp,0x63
+out UDR,tmp
+.endif
+
 ; store counters
 mov counter_l_tmp,counter_l
 mov counter_h_tmp,counter_h
@@ -238,6 +277,11 @@ ret
 
 TOGGLE_ICP_SENSE:
 
+.ifdef DEBUG
+ldi tmp,0x54
+out UDR,tmp
+.endif
+
 ; toggle according to state
 in tmp,TCCR1B
 cbr tmp,ICES1
@@ -254,6 +298,15 @@ ret
 
 FWD_TO_CAM:
 
+.ifdef DEBUG
+ldi tmp,0x66
+out UDR,tmp
+.endif
+
+; activate led
+sbi PORTB,LED_FWD_TO_CARD
+cbi PORTB,LED_FWD_TO_CAM
+
 ; disable external interrupt 1 while toggling edge
 in tmp,GIMSK
 cbr tmp,INT1
@@ -282,6 +335,11 @@ ret
 
 PREPARE_UART:
 
+.ifdef DEBUG
+ldi tmp,0x50
+out UDR,tmp
+.endif
+
 ; write transfer data to sram
 ldi ZL,0x60
 st Z+,counter_l
@@ -302,10 +360,19 @@ ret
 
 REC_CAM:
 
+.ifdef DEBUG
+ldi tmp,0x72
+out UDR,tmp
+.endif
+
 ; first thing - pullup on
 cbi DDRD,DDD3
 sbi DDRD,PD3
 
+; activate led
+sbi PORTB,LED_CARD
+cbi PORTB,LED_CAM
+
 ; toggle state
 eor state,state_m
 
@@ -329,6 +396,11 @@ reti
 
 TOGGLE_INT_SENSE:
 
+.ifdef DEBUG
+ldi tmp,0x73
+out UDR,tmp
+.endif
+
 in tmp,MCUCR
 cbr tmp,ISC10
 sbrs state,HIGH_F
@@ -344,6 +416,15 @@ ret
 
 FWD_TO_CARD:
 
+.ifdef DEBUG
+ldi tmp,0x46
+out UDR,tmp
+.endif
+
+; activate led
+sbi PORTB,LED_FWD_TO_CAM
+cbi PORTB,LED_FWD_TO_CARD
+
 ; disable icp interrupt while toggling edge
 in tmp,TIMSK
 cbr tmp,TICIE
@@ -372,9 +453,21 @@ ret
 
 T1_OVERFLOW:
 
+.ifdef DEBUG
+ldi tmp,0x74
+out UDR,tmp
+.endif
+
 ; increment counter overflow
 add overflow_counter,one
 
+; toggle led status
+mov tmp,overflow_counter
+and tmp,one
+sbi PORTB,LED_OVERFLOW
+sbrs tmp,1
+cbi PORTB,LED_OVERFLOW
+
 ; return
 reti
 
@@ -384,6 +477,11 @@ reti
 
 RST_CAM:
 
+.ifdef DEBUG
+ldi tmp,0x69
+out UDR,tmp
+.endif
+
 ; by now just jump to init
 rjmp INIT