just commited to continue work on hackstation ;)
[my-code/atmel.git] / beginners / season_junior.asm
1 ; season - junior
2 ;
3 ; author: hackbard@hackdaworld.dyndns.org
4 ;
5
6
7 ; at90s2313
8 ; setup:
9 ; vcc card --- atmel vcc
10 ; vcc cam  --- 
11 ; rst cam  --- atmel int0 (pd2)
12 ; rst card --- atmel (pb4)
13 ; clk card -\ 
14 ;            -  atmel t1 (pd5)
15 ; clk cam  -/
16 ; gnd card --- gnd cam --- atmel gnd
17 ; i/o card --- atmel icp (pd6)
18 ; i/o cam  --- atmel int1 (pd3)
19
20 .include "../include/2313def.inc"
21
22 ; functions by now:
23 ;
24 ; stupid mode only by now. just see what cam/card do and redirect
25 ; this to card/cam.
26 ;
27 ; next implementation:
28
29 ; try to read one byte of card/cam communication and output via uart.
30 ; output time information in some way.
31 ;
32 ; future:
33 ;
34 ; buffer/parse whole strings and decide whether to send to card or not.
35
36 ;
37 ; interrupt vectors:
38 ;
39
40 ; reset
41 rjmp INIT
42
43 ; int0
44 rjmp RST_CAM
45
46 ; int1
47 rjmp REC_CAM
48
49 ; timer/counter capt 1
50 rjmp REC_CARD
51
52 ; timer/counter compare
53 reti
54
55 ; timer/counter overflow 1
56 rjmp CLK_OVERFLOW
57
58 ; timer/counter overflow 0
59 reti
60
61 ; uart rx complete
62 reti
63
64 ; uart data register empty
65 rjmp UART_OUT
66
67 ; uart tx complete
68 reti
69
70 ; analog comparator
71 reti
72
73 ;
74 ; init routine
75 ;
76
77 MAIN:
78 rjmp MAIN
79
80 INIT:
81
82 ; set stackpointer
83 ldi r16,low(RAMEND)
84 out SPL,r16
85
86 ;
87 ; hier weiter ....
88 ;
89
90 ; enable interrupts int0,int1
91 ldi r16,((1<<INT0)|(1<<INT1))
92 out GIMSK,r16
93 ; int0/1 setup
94 ldi r16,((1<<ISC01)|(1<<ISC00)|(1<<ISC10)|(1<<ISC11))
95 out MCUCR,r16
96 in r16,MCUCR
97 sbic PORTD,PD2
98 cbr r16,ISC00
99 out MCUCR,r16
100 sbic PORTD,PD3
101 cbr r16,ISC10
102 out MCUCR,r16
103
104 ; enable t/c overflow interrupt
105 ldi r16,(1<<TOIE1)
106 out TIMSK,r16
107 ; setup t/c
108 ldi r16,((1<<CS12)|(1<<CS11)|(1<<CS10))
109 out TCCR1B,r16
110
111 ; init bitcounter and overflow counter
112 ldi r20,0 ; bitcounter
113 ldi r21,0 ; register for constructing the byte
114 ldi r22,0 ; overflow counter
115
116 ; constant 1 in r1
117 ldi r16,1
118 mov r1,r16
119
120 ; enable interrupts (global)
121 sei
122
123 ;
124 ; rec_card routines
125 ;
126
127 REC_CARD:
128
129 ; int0 -> input, int1 -> output
130 ldi r16,(1<<DDD3)
131 out DDRD,r16
132
133 ; decide what to do
134 sbic PORTD,PD2
135 rjmp REC_CARD_HIGH
136 rjmp REC_CARD_LOW
137
138 REC_CARD_HIGH:
139
140 ; output high on port to cam
141 ldi r16,(1<<PD3)
142 out PORTD,r16
143
144 ; toggle int0 sense
145 in r16,MCUCR
146 cbr r16,ISC00
147 out MCUCR,r16
148
149 reti
150
151 REC_CARD_LOW:
152
153 ; output low on port to cam
154 ldi r16,0
155 out PORTD,r16
156
157 ; toggle int0 sense
158 in r16,MCUCR
159 cbr r16,ISC00
160 out MCUCR,r16
161
162 reti
163
164 ;
165 ; rec_cam routines
166 ;
167
168 REC_CAM:
169
170 ; int1 -> input, int0 -> output
171 ldi r16,(1<<DDD2)
172 out DDRD,r16
173
174 ; decide what to do
175 sbic PORTD,PD3
176 rjmp REC_CAM_HIGH
177 rjmp REC_CAM_LOW
178
179 REC_CAM_HIGH:
180
181 ; output high on port to card
182 ldi r16,(1<<PD2)
183 out PORTD,r16
184
185 ; toggle int1 sense
186 in r16,MCUCR
187 cbr r16,ISC10
188 out MCUCR,r16
189
190 reti
191
192 REC_CAM_LOW:
193
194 ; output low on port to card
195 ldi r16,0
196 out PORTD,r16
197
198 ; toggle int 1 sense
199 in r16,MCUCR
200 cbr r16,ISC10
201 out MCUCR,r16
202
203 reti
204
205 ;
206 ; t1_overflow routine
207 ;
208
209 T1_OVERFLOW:
210
211 add r22,r1 ; inc counter overflow register
212
213 reti
214