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