• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

およそ20年前に、68HC05 の開発の練習に書いた車のブレイクライト・方向指示器コントローラです。


コミットメタ情報

リビジョンa89723ba66842646d5e548b0e4af9af878bb64c0 (tree)
日時2013-07-08 22:34:06
作者Joel Matthew Rees <reiisi@user...>
コミッターJoel Matthew Rees

ログメッセージ

Adding the assembler output files to the source tree, for reference.

変更サマリ

差分

--- /dev/null
+++ b/TURNSIG.LST
@@ -0,0 +1,1282 @@
1+
2+TURNSIG.asm Assembled with IASM 11/19/1993 00:26 PAGE 1
3+Turn Signal Switch by Joel Matthew Rees
4+
5+
6+ 0200 1 PAGEWIDTH 128
7+ 0200 2 HEADER 'Turn Signal Switch by Joel Matthew Rees'
8+ 3
9+ 4 * Electronic Turn Signal and Emergency Flasher Switch/Timer
10+ 5 * Version 1.00
11+ 6 * Implemented on the 68HC705K1
12+ 7 * Assembled and tested on the M68HC705KICS
13+ 8 *
14+ 9 * Copyright 1993 Joel Matthew Rees
15+ 10 *
16+ 11 * Permission granted in advance for strictly non-profit
17+ 12 * educational use. All other rights retained by the author.
18+ 13
19+ 14 * Authored by Joel Matthew Rees, June to November 1993
20+ 15 * of also of
21+ 16 * South Salt Lake City Amagasaki
22+ 17 * Utah Japan
23+ 18 *
24+ 19
25+ 20
26+ 21
27+ 0200 22 SUBHEADER 'Purpose, Description, and Design'
28+
29+
30+TURNSIG.asm Assembled with IASM 11/19/1993 00:26 PAGE 2
31+Turn Signal Switch by Joel Matthew Rees
32+Purpose, Description, and Design
33+
34+ 0200 22 PAGE
35+ 23 * Design:
36+ 24
37+ 25 * When the turn signal and emergency flasher switch assembly on my
38+ 26 * parents' 1971 Colt fell apart some years back, rather than go to the
39+ 27 * nearest Dodge dealer in the next city to order the part, I designed a
40+ 28 * substitute switch using a pair of double-pole, double-throw relays in
41+ 29 * set-reset latch configuration. Momentary-closed pushbuttons (mounted
42+ 30 * to the steering column cover) set the turn signals, and a momentary
43+ 31 * open pushbutton (mounted between the set buttons) or reed switch
44+ 32 * (mounted inside the cover housing so a magnet mounted to the steering
45+ 33 * column would actuate it) shut them off. I usurped the emergency
46+ 34 * flasher unit and took power from the battery lead on the ignition
47+ 35 * switch, so when I needed emergency flashers, I could just turn both
48+ 36 * turn signals on. Mom had trouble getting used to this arrangement, but
49+ 37 * it passed Texas inspection in the seventies.
50+ 38
51+ 39 * Examining the 68HC05K series MCUs brought that turn signal
52+ 40 * switch back to mind. I thought ten bits of I/O, internal timers,
53+ 41 * and the STOP mode would be sufficient to replicate the logic of that
54+ 42 * switch assembly, adding directional turn signal return switches and
55+ 43 * flasher and turn sgnal return logic as well. It turned out to be a
56+ 44 * tight squeeze.
57+ 45
58+ 46 * The intent of this document is to focus on the problems of
59+ 47 * decoding inputs, directionalizing the turn signal return, eliminating
60+ 48 * the flasher units, and minimizing power consumption using the STOP
61+ 49 * mode and interrupts. Hardware issues such as power supply design,
62+ 50 * electro-static discharge protection (very important in automotive
63+ 51 * applications), and details of lamp driver circuits are mostly set
64+ 52 * aside. The logic has been tested with the M68HC705KICS simulator
65+ 53 * program, but has not been tested in a physical mock up or real
66+ 54 * vehicle. (I ran out of time for this project.)
67+ 55
68+ 56 ******* Potential problems: ******************************************
69+ 57
70+ 58 * I have not dealt with the problems that occur when the turn signals
71+ 59 * are turned on while the return sensors are within range of their
72+ 60 * actuator fields. Two more bits of port B would have allowed complete
73+ 61 * separation of the two functions. A little extra code might allow
74+ 62 * suppressing the turn signal inputs while both return switches are
75+ 63 * active, to reduce the operator frustration factor.
76+ 64
77+ 65 * I have also mostly ignored the problems presented by shorted switches.
78+ 66 * Having the turn signal functions on port B is handy, because a week
79+ 67 * turn signal spring will not keep the circuit from staying in the STOP
80+ 68 * instruction. Another 50 bytes of ROM might have allowed tracking time
81+ 69 * of no change for every sensor, which could allow shutting out a
82+ 70 * sensor that has been active more than n minutes.
83+ 71
84+ 72 **********************************************************************
85+ 73
86+ 74 * One of the intents of this design was to replace mechanical
87+ 75 * parts (that tend to flow in hot climates and become brittle in cold)
88+ 76 * with logic. In order to eliminate the mechanical latching lever with
89+ 77 * spring loaded return, I have (perhaps arbitrarily) enforced a new "user
90+ 78 * interface" involving momentary contact switches for the turn signals.
91+ 79 * Two possible physical arrangements for the turn signal present
92+
93+
94+TURNSIG.asm Assembled with IASM 11/19/1993 00:26 PAGE 3
95+Turn Signal Switch by Joel Matthew Rees
96+Purpose, Description, and Design
97+
98+ 80 * themselves to my mind: In the one, a spring-loaded, non-latching
99+ 81 * signal rod (the latch/return mechanism was the weakest part) actuates
100+ 82 * momentary contact switches in two axes; the rod can be pushed up or
101+ 83 * down to activate the turn signals, or it can be pushed in to actuate
102+ 84 * the manual cancel. In another arrangement, the signal rod is fixed,
103+ 85 * and three pushbuttons are provided on a pad at its end. (Cancel in
104+ 86 * the center would seem logical.)
105+ 87
106+ 88 * The emergency flasher switch is a momentary on pushbutton, and
107+ 89 * it cancels itself in software -- push on, push off. I think the audio
108+ 90 * feedback and dash panel indicators should be sufficient user feedback.
109+ 91
110+ 92 * The turn signal return mechanism is a pair of reed relays
111+ 93 * mounted inside the bottom of the steering column housing about 11.25
112+ 94 * degrees apart, with one to four magnetic actuators distributed around
113+ 95 * the steering shaft. The shape, size, and position of the magnets and
114+ 96 * reeds should be such that the reeds close only once as a magnet
115+ 97 * passes, and such that the reeds have about 22.5 degrees of total
116+ 98 * actuation. The overlap in actuation is used to determine the direction
117+ 99 * the steering wheel is rotating. Minor changes to the design should
118+ 100 * allow the use of optical sensors, but I have the impression that
119+ 101 * magnetic devices are more immune to extremes of climate. (Maybe?)
120+ 102
121+ 0200 103 SUBHEADER 'Model Schematic'
122+
123+
124+TURNSIG.asm Assembled with IASM 11/19/1993 00:26 PAGE 4
125+Turn Signal Switch by Joel Matthew Rees
126+Model Schematic
127+
128+ 0200 103 PAGE
129+ 104 * An idealized schematic follows:
130+ 105
131+ 106
132+ 107 * PA7>---FRNT_LEFT_DRVR---+---FL_SGNL_LAMP---GND
133+ 108 * |
134+ 109 * +---LEFT_INDCTR---GND
135+ 110 * |
136+ 111 * +---LEFT_AUDIO---GND
137+ 112
138+ 113 * PA6>---FRNT_RGHT_DRVR---+---FR_SGNL_LAMP---GND
139+ 114 * |
140+ 115 * +---RGHT_INDCTR---GND
141+ 116 * |
142+ 117 * +---RGHT_AUDIO---GND
143+ 118
144+ 119 * PA5>---REAR_LEFT_DRVR----RL_SGNL_LAMP---GND
145+ 120 *
146+ 121 * PA4>---REAR_RGHT_DRVR----RR_SGNL_LAMP---GND
147+ 122
148+ 123 * PA3<---+---160K_OHM---------+---BRK_SW---12V
149+ 124 * | |
150+ 125 * +---5V_ZENER---GND +---CENTER_BRK_LGHT---GND
151+ 126
152+ 127 * PA2<---+---160K_OHM---ENGINE_ON_SW---12V
153+ 128 * |
154+ 129 * +---5V_ZENER---GND
155+ 130
156+ 131 * PA1>---DRVRS_ON_CNTRL
157+ 132
158+ 133 * IRQ<---+---100K_OHM---Vdd
159+ 134 * |
160+ 135 * +---EMG_SW---GND
161+ 136
162+ 137 * PB1<>--+----------LEFT_RETURN_SW---+
163+ 138 * | |
164+ 139 * +---LEFT_TURN_SW---+ |
165+ 140 * | |
166+ 141 * Vdd---100K_OHM---+ |
167+ 142 * | |
168+ 143 * +---RGHT_TURN_SW---+ |
169+ 144 * | |
170+ 145 * PB0<>--+----------RGHT_RETURN_SW---+
171+ 146 * |
172+ 147 * PA0<---+---------------------------+
173+ 148 * |
174+ 149 * +---CAN_SW---100K_OHM---Vdd
175+ 150
176+ 151 * RESET<---100K_OHM---Vdd
177+ 152
178+ 153 * IF THIS IS IMPLEMENTED IN A REAL CIRCUIT, ESD PROTECTION MUST BE ADDED!
179+ 154
180+ 0200 155 SUBHEADER 'Circuit Explication'
181+
182+
183+TURNSIG.asm Assembled with IASM 11/19/1993 00:26 PAGE 5
184+Turn Signal Switch by Joel Matthew Rees
185+Circuit Explication
186+
187+ 0200 155 PAGE
188+ 156 * Explanatory notes:
189+ 157
190+ 158 * PA1 allows the signal drivers to be shut down to preserve power.
191+ 159 * I assume a suitable digital switch with power down is available. If
192+ 160 * optical sensors are used for the turn signal return, the optical
193+ 161 * sources would also be turned on by this signal. I assume it will be
194+ 162 * active high.
195+ 163
196+ 164 * I arbitrarily assume the signal lamp drivers will be active low.
197+ 165 * Who could say why? It should be easy to find all references to the
198+ 166 * driver lines with a text editor and reverse the active states of the
199+ 167 * outputs.
200+ 168
201+ 169 * Hanging the indicators and the audio feedback on the front lamp
202+ 170 * drivers separates them from brake activity. Two audio feedback
203+ 171 * devices are used here because there were not enough MCU outputs to
204+ 172 * drive a single cheap clicking device. Stereo audio feedback might be
205+ 173 * a nice touch anyway, allowing a person with binaural hearing to
206+ 174 * determine by sound which signal is on. (If the ROM were a little
207+ 175 * larger, a separate audio feedback could be modulated with different
208+ 176 * sounds for left, right, and emergency flashers.)
209+ 177
210+ 178 * The center brake light is directly switched to eliminate one of
211+ 179 * the separate high-power outputs. Fortunately, its state is not
212+ 180 * dependent on any other inputs.
213+ 181
214+ 182 * The engine-on input (PA2) is necessary so that the MCU knows
215+ 183 * when it can shut itself down to conserve power. It is an interrupting
216+ 184 * input so that the MCU STOP mode can be used. Brake lights and
217+ 185 * emergency flashers must be accessible when the engine is off, so those
218+ 186 * inputs are also interrupting. The engine-on and brake inputs are
219+ 187 * naturally positive-going signals, but the emergency flasher input is
220+ 188 * not naturally biased. So the the emergency flasher seemed a more
221+ 189 * natural match for IRQ.
222+ 190
223+ 191 * The following crude diagram illustrates the actuation in a left
224+ 192 * rotation (restoring from a right turn or turning left). The carots
225+ 193 * indicate the position of the reed switches, the asterisks indicate the
226+ 194 * actuation field of a magnet.
227+ 195
228+ 196 * Actuation Field ********
229+ 197 * Left Return Switch ^ ^ Right Return Switch
230+ 198 * ********
231+ 199 * ^ ^
232+ 200 * ********
233+ 201 * ^ ^
234+ 202 * ********
235+ 203 * ^ ^
236+ 204 * ********
237+ 205 * ^ ^
238+ 206 * ********
239+ 207 * ^ ^
240+ 208 * ********
241+ 209 * ^ ^
242+ 210
243+ 211 * Referring to the above diagram, the right turn signal return
244+ 212 * switch is positioned about 5 5/8 degrees right of bottom center below
245+
246+
247+TURNSIG.asm Assembled with IASM 11/19/1993 00:26 PAGE 6
248+Turn Signal Switch by Joel Matthew Rees
249+Circuit Explication
250+
251+ 213 * the steering column and fixed to the steering column housing, and the
252+ 214 * left return is positioned the same distance to the left. In this way,
253+ 215 * when the steering wheel rotates, the return switch for the direction
254+ 216 * of rotation actuates first, then the opposite direction switch closes,
255+ 217 * then the same direction switch opens, and then the opposite direction
256+ 218 * switch opens. Thus, when restoring from a turn, the return switch for
257+ 219 * the direction of the turn closes after the other switch. In other
258+ 220 * words, if you turn right, the steering wheel will rotate to the left
259+ 221 * when you return to straight, and the switches actuate from left to
260+ 222 * right during the restore. (I say this so many times because it takes
261+ 223 * repeating to convince myself of it.)
262+ 224
263+ 225 * When both turn signals are off, both turn signal switch ports
264+ 226 * are set as inputs. When a turn signal switch input senses a closure,
265+ 227 * its port is made an output and driven high. Now, in addition to
266+ 228 * manual cancel, the cancel port can sense steering wheel rotation. In
267+ 229 * same direction rotation, there is a lead period when the cancel input
268+ 230 * does not remain high if the turn signal input ports' output states are
269+ 231 * inverted. The debounce routine suppresses cancel if this lead time is
270+ 232 * sensed.
271+ 233
272+ 234 * Since the opposite direction turn signal switch port remains an
273+ 235 * input, it can still be sensed. The operator can change turn signals
274+ 236 * directly, without hitting the cancel button.
275+ 237
276+ 238 * The separation of the switches and the actuation arc length I
277+ 239 * specify are based on my assumption that the steering wheel will rotate
278+ 240 * at a maximum speed of three revolutions per second, and that the four
279+ 241 * to six mS (1 MHz crystal) required debounce period requires a minimum
280+ 242 * 10 milli-second separate actuation period. The actual result was 10.9
281+ 243 * degrees separate actuation (21.8 total), which I arbitrarily rounded
282+ 244 * up to a power of two fraction of the circle: 2*PI/16 total actuation
283+ 245 * and 2*PI/32 separate actuation.
284+ 246
285+ 247 * A peculiar characteristic of this design is the apparent lack of
286+ 248 * use for the RESET input. Since power-on reset is built in to the
287+ 249 * K-series MCUs, RESET should probably be tied high. However, I suppose
288+ 250 * it could make a good manual cancel-all input, if such is necessary.
289+ 251
290+ 252 * This assembler appears not to have a bit-not function for
291+ 253 * operand expressions. So, I have in several places resorted to the
292+ 254 * obtuse expedient of exclusive-orring bits to be reset with $FF,
293+ 255 * ergo, AND #{$FF ^ F_OPC ^ F_MNC}
294+ 256 * instead of AND #~(F_OPC | F_MNC)
295+ 257 * which I think would have been clearer.
296+ 258
297+ 259 * One more assembler quirk -- I have used $FF in a couple of
298+ 260 * places I would normally have used -1 to indicate all bits set. The
299+ 261 * assembler apparently turns {-1} into 1 in operands.
300+ 262
301+ 0200 263 SUBHEADER 'Obligatory Mnemonics'
302+
303+
304+TURNSIG.asm Assembled with IASM 11/19/1993 00:26 PAGE 7
305+Turn Signal Switch by Joel Matthew Rees
306+Obligatory Mnemonics
307+
308+ 0200 263 PAGE
309+ 0200 264 $base $0A
310+ 0200 265 $include "68HC05K.EQU"
311+ 266
312+ 0200 267 SUBHEADER 'Program Mnemonics'
313+
314+
315+TURNSIG.asm Assembled with IASM 11/19/1993 00:26 PAGE 8
316+Turn Signal Switch by Joel Matthew Rees
317+Program Mnemonics
318+
319+ 0200 267 PAGE
320+ 268 * physical I/O definitions
321+ 269 * PORTA
322+ 0200 270 F_LDRV equ B7 ; four lamp drivers
323+ 0200 271 F_LDRV_ equ B7_
324+ 0200 272 F_RDRV equ B6
325+ 0200 273 F_RDRV_ equ B6_
326+ 0200 274 R_LDRV equ B5
327+ 0200 275 R_LDRV_ equ B5_
328+ 0200 276 R_RDRV equ B4
329+ 0200 277 R_RDRV_ equ B4_
330+ 0200 278 DRVLMPS equ {F_LDRV | F_RDRV | R_LDRV | R_RDRV}
331+ 0200 279 LFTDRV equ {F_LDRV | R_LDRV}
332+ 0200 280 RGTDRV equ {F_RDRV | R_RDRV}
333+ 0200 281 FRNTDRV equ {F_LDRV | F_RDRV}
334+ 0200 282 REARDRV equ {R_LDRV | R_RDRV}
335+ 0200 283 BRK_SW equ B3
336+ 0200 284 BRK_SW_ equ B3_
337+ 0200 285 NGN_SW equ B2 ; engine (ENG and EMG could be confusing)
338+ 0200 286 NGN_SW_ equ B2_
339+ 0200 287 DRVDRV equ B1
340+ 0200 288 DRVDRV_ equ B1_
341+ 0200 289 EMG_BTF equ DRVDRV ; where to fold EMG_BT
342+ 0200 290 EMG_BTF_ equ DRVDRV_
343+ 0200 291 CAN_BT equ B0
344+ 0200 292 CAN_BT_ equ B0_
345+ 293 * PORTB
346+ 0200 294 LFT_BT equ B1 ; a handy data dependency! DO NOT CHANGE
347+ 0200 295 LFT_BT_ equ B1_
348+ 0200 296 RGT_BT equ B0 ; another handy data dependency!
349+ 0200 297 RGT_BT_ equ B0_
350+ 298 * IRQ input (inverted) is the real EMG_BT
351+ 299
352+ 300
353+ 301 * logical input definitions for debounce and states
354+ 302 * bits are remapped for debounce and speed
355+ 303 * six bits of physical input, high two bits borrowed for cancel logic
356+ 0200 304 F_LFT equ LFT_BT ; another handy data dependency!
357+ 0200 305 F_LFT_ equ LFT_BT_
358+ 0200 306 F_RGT equ RGT_BT ; another handy data dependency!
359+ 0200 307 F_RGT_ equ RGT_BT_
360+ 0200 308 TURNSIG equ {F_LFT | F_RGT}
361+ 0200 309 F_BRK equ {BRK_SW < 2} ; physical output bit
362+ 0200 310 F_BRK_ equ {BRK_SW_ + 2}
363+ 0200 311 F_NGN equ {NGN_SW < 2} ; physical output bit
364+ 0200 312 F_NGN_ equ {NGN_SW_ + 2}
365+ 0200 313 F_EMG equ {DRVDRV < 2} ; fold onto output bit
366+ 0200 314 F_EMG_ equ {DRVDRV_ + 2}
367+ 0200 315 ANYLITE equ {TURNSIG | F_BRK | F_EMG}
368+ 0200 316 F_CAN equ {CAN_BT < 2}
369+ 0200 317 F_CAN_ equ {CAN_BT_ + 2}
370+ 0200 318 F_OPC equ $40 ; opposite direction cancel record
371+ 0200 319 F_MNC equ $80 ; manual cancel record
372+ 320
373+ 321 * The turn signal table and many of the turn signal routines
374+ 322 * depend on F_LFT and F_RGT and LFT_BT and RGT_BT being in bits one and
375+ 323 * zero (but not particular which is which!). If these are changed,
376+ 324 * there will be a domino effect on the rest of the code.
377+
378+
379+TURNSIG.asm Assembled with IASM 11/19/1993 00:26 PAGE 9
380+Turn Signal Switch by Joel Matthew Rees
381+Program Mnemonics
382+
383+ 325
384+ 0200 326 SUBHEADER 'Resource Definitions'
385+
386+
387+TURNSIG.asm Assembled with IASM 11/19/1993 00:26 PAGE 10
388+Turn Signal Switch by Joel Matthew Rees
389+Resource Definitions
390+
391+ 0200 326 PAGE
392+ 327
393+ 328
394+ 0200 329 XTAL equ 1 ; crystal frequency, in MHz
395+ 0200 330 RTIPOW equ 0
396+ 331 * 1 ; bits 1 & 0 for timer hardware
397+ 0200 332 RTIRATE equ {2 < RTIPOW} ; 2 ^ RTIPOW
398+ 0200 333 TIMOUT equ 1
399+ 334 * {9155*XTAL/RTIRATE+1} ; 5 minutes (if XTAL equ is correct)
400+ 335 * only one flash rate, 2/3 duty cycle
401+ 0200 336 FLASH0 equ 1
402+ 337 * {32*XTAL/RTIRATE/4} ; about 1/4 second off time
403+ 0200 338 FLASH1 equ 1
404+ 339 * {32*XTAL/RTIRATE/2} ; about 1/2 second on time
405+ 340
406+ 0017 341 org MOR
407+ 342 * Software Pulldown is used.
408+ 343 * Can't spare the third RC oscillator pin.
409+ 344 * Set RC because we assume the cheap oscillator.
410+ 345 * STOP must not convert to WAIT: saves power when engine off.
411+ 346 * Assume Low Voltage Reset would be meaningless.
412+ 347 * PA3 - PA0 interrupts are used to bring the chip up for brake, engine on.
413+ 348 * Accept level sensitive interrupts, since IRQ is disabled immediately.
414+ 349 * Assume COP might be useful here.
415+ 0017 27 350 fcb {RC | PIRQ | LEVEL | COPEN}
416+ 351
417+ 00E0 352 org RAMBEG
418+ 00E0 353 DEBO rmb 3 ; the debounce record chain
419+ 00E3 354 SSTBLE rmb 1 ; temporary record of stable bits
420+ 00E4 355 TOGGLE rmb 1 ; record of toggles
421+ 00E5 356 ISTATE rmb 1 ; record of the current input state
422+ 00E6 357 STATES rmb 1 ; current controller states
423+ 00E7 358 NGN_TIM rmb 2 ; engine time out timer
424+ 00E9 359 FLASH rmb 1 ; flash timer
425+ 00EA 360 FLDARK rmb 1 ; flash light or dark state, 11111111 == dark
426+ 00EB 361 FLMASK rmb 1 ; flash mask to communicate between BRK, EMG, and TRN
427+ 00EC 362 TMPTRN rmb 1 ; temporary for keep turn signal interpretation
428+ 00ED 363 LASTST rmb 1 ; previous state record to separate timer from decode
429+ 00EE 364 rmb 4
430+ 00F2 365 DBGCT rmb 4 ; count how many times TIMSRV has executed
431+ 366
432+ 367
433+ 368 * ROM definitions follow:
434+ 0200 369 org ROMBEG
435+ 370
436+ 0200 371 SUBHEADER 'Timer Service Code'
437+
438+
439+TURNSIG.asm Assembled with IASM 11/19/1993 00:26 PAGE 11
440+Turn Signal Switch by Joel Matthew Rees
441+Timer Service Code
442+
443+ 0200 371 PAGE
444+ 372
445+ 373 * The timer service routine has these functions: debouncing the
446+ 374 * inputs, flagging changes in TOGGLE, adjusting STATES to match the
447+ 375 * inputs, and maintaining two software clocks. Interrupts occur on timer
448+ 376 * overflow (1024 CPU cycles).
449+ 377
450+ 378 * The debounce routine translates the physical inputs to logical
451+ 379 * inputs, maintains a record of the last three logical states sensed in
452+ 380 * DEBO, debounces (in parallel) each input on three identical states,
453+ 381 * flags changes in the debounced input in TOGGLE, and leaves the current
454+ 382 * debounced input in ISTATE. Since debouncing occurs on three identical
455+ 383 * states, the debounce period is between two and three timer overflows
456+ 384 * -- 4 to 6 mS with a 1 MHz crystal, 2 to 3 mS with a 2 MHz crystal.
457+ 385
458+ 386 * This debounce technique works because we don't care what is
459+ 387 * happening to the inputs between timer overflows, and because we assume
460+ 388 * there is no physical mechanism to induce noise coincident and rythmic
461+ 389 * with timer overflow.
462+ 390
463+ 391 * The TOGGLE cancel (F_CAN) bit is suppressed on same-direction
464+ 392 * rotation. Trailing edge TOGGLE F_CAN and F_EMG are filtered out to
465+ 393 * simplify interpretation of those functions. Opposite direction cancel
466+ 394 * (F_OPC) and manual cancel (F_MNC) ISTATE auxiliary flags are
467+ 395 * maintained to provide information on the source of the F_CAN bit, and
468+ 396 * are always filtered out of TOGGLE and STATES. STATES F_CAN is
469+ 397 * adjusted according to TOGGLE F_CAN rather than ISTATE F_CAN, by which
470+ 398 * means we hope to not need to remember in which direction a cancel was
471+ 399 * sensed. In other words, we hope that F_CAN does not toggle again
472+ 400 * until both return sensors are past the actuator field.
473+ 401
474+ 402 * After adding an event queue and checking the timing results, two
475+ 403 * things became clear: there is plenty of time to handle all the changes
476+ 404 * to STATES without a queue, and TOGGLE makes a sort of horizontal
477+ 405 * priority queue anyway. In other words, there is no reason to make the
478+ 406 * adjustments to STATES asynchronous when there is plenty of headroom
479+ 407 * for synchronous adjustments. Moreover, the adjustments take less time
480+ 408 * than organizing the button events in a queue. (Darn! I was kind of
481+ 409 * proud of that six byte queue, and the shift technique for storing
482+ 410 * events into it.)
483+ 411
484+ 412 * When moving the ISTATE turn signal bits to STATES, the STATES
485+ 413 * turn signal bits are examined to see if the direction has changed. If
486+ 414 * a STATE turn signal bit is on, PORTB is set to wait for F_CAN.
487+ 415
488+ 416 * The engine time-out counter communicates with the power down
489+ 417 * routine via the STATES engine on (F_NGN) bit. In other words, STATES
490+ 418 * F_NGN bit is held off until the ISTATE F_NGN bit and the STATES F_EMG
491+ 419 * and F_BRK bits have been inactive for five minutes. (This perhaps
492+ 420 * overloads the semantics of STATES F_NGN.)
493+ 421
494+ 422 * In the current design, the turn signals are not masked with the
495+ 423 * ISTATE F_NGN bit, and so will function during the time-out period.
496+ 424 * This "feature" can easily be corrected in the debounce routine.
497+ 425
498+ 426 * It should be relatively easy to add a turn signal time-out
499+ 427 * counter to turn off the turn signals after the same turn signal has
500+ 428 * been on an un-reasonable period, such as five or more minutes.
501+
502+
503+TURNSIG.asm Assembled with IASM 11/19/1993 00:26 PAGE 12
504+Turn Signal Switch by Joel Matthew Rees
505+Timer Service Code
506+
507+ 429 * Such a time-out might negatively impact safety when attempting to turn
508+ 430 * in backed-up traffic or onto a very busy highway, or when using the
509+ 431 * turn signal to show a car parked for delivery, etc. It also might
510+ 432 * cause drivers to become even lazier.
511+ 433
512+ 434 * Both timers reset in such a manner as to be in a known state at
513+ 435 * any time they are put into use.
514+ 436
515+ 437 * The single emergency and turn signal signal flasher uses a single
516+ 438 * rate and duty cycle.
517+ 439
518+ 0200 440 SUBHEADER 'Timer Service Code -- Debounce and Toggle Filter'
519+
520+
521+TURNSIG.asm Assembled with IASM 11/19/1993 00:26 PAGE 13
522+Turn Signal Switch by Joel Matthew Rees
523+Timer Service Code -- Debounce and Toggle Filter
524+
525+ 0200 440 PAGE
526+ 441
527+ 0200 83 442 swi ; since we have a few unused ROM locations
528+ 0201 83 443 swi
529+ 0202 83 444 swi
530+ 445
531+ 0203 446 $CYCLE_ADDER_ON
532+ 0203 1608 447 TIMSRV bset TOFR_,TSCR
533+ 448
534+ 449 * move the debounce chain
535+ 0205 B6E1 450 lda DEBO+1
536+ 0207 B7E2 451 sta DEBO+2
537+ 0209 B6E0 452 lda DEBO
538+ 020B B7E1 453 sta DEBO+1
539+ 454
540+ 455 * record previous STATE
541+ 020D B6E6 456 lda STATES
542+ 020F B7ED 457 sta LASTST
543+ 458
544+ 459 * read the static inputs, converting physical to logical
545+ 0211 B600 460 lda PORTA
546+ 0213 A40D 461 and #{BRK_SW | NGN_SW | CAN_BT} ; clears DRV_DRV
547+ 0215 2F02 462 bih TMIEMG ; invert EMG and fold it in
548+ 0217 AA02 463 ora #EMG_BTF ; keep temporally very close to first read
549+ 0219 464 TMIEMG equ *
550+ 0219 48 465 lsla ; remap
551+ 021A 48 466 lsla
552+ 021B B7E0 467 sta DEBO
553+ 021D B601 468 lda PORTB ; PB2-7 always read 0
554+ 021F BAE0 469 ora DEBO
555+ 0221 B7E0 470 sta DEBO
556+ 471
557+ 472 * read the turn signal return and manual cancel auxiliary flags
558+ 473 * (F_CAN & turn_sig_on) <=> read auxiliary flags
559+ 474 * Assume that DDRB showing output means turn signal on and waiting
560+ 475 * for cancel.
561+ 476 * Filtering F_CAN on same-direction turn is handled later.
562+ 477 * Remember that F_CAN should be sensed via TOGGLE, to avoid multiple
563+ 478 * interpretations of one pass of the actuator.
564+ 479
565+ 0223 A504 480 bit #F_CAN ; nothing at all without cancel
566+ 0225 2725 481 beq TM0TURN
567+ 0227 BE05 482 ldx DDRB ; cancel meaningless if not waiting for it
568+ 0229 2721 483 beq TM0TURN
569+TOTAL CYCLES = 0 decimal
570+ 022B 484 $CYCLE_ADDER_OFF
571+ 022B 485 $CYCLE_ADDER_ON
572+ 022B 9F 486 txa
573+ 022C A803 487 eor #{LFT_BT | RGT_BT} ; strobe other side
574+ 022E B701 488 sta PORTB ; set output state first
575+ 0230 B705 489 sta DDRB ; handy (data dependent) output state, huh?
576+ 0232 000000 490 brset CAN_BT_,PORTA,TMTBIT6 ; CAN_BT_ into carry
577+ 0235 46 491 TMTBIT6 rora ; carry into bit 7
578+ 0236 3F05 492 clr DDRB ; kill strobe: manual cancel?
579+ 0238 000000 493 brset CAN_BT_,PORTA,TMTBIT7 ; CAN_BT_ into carry again
580+ 023B 46 494 TMTBIT7 rora ; carry into bit 7 again
581+ 023C A4C0 495 and #{F_OPC | F_MNC}
582+ 023E BAE0 496 ora DEBO
583+
584+
585+TURNSIG.asm Assembled with IASM 11/19/1993 00:26 PAGE 14
586+Turn Signal Switch by Joel Matthew Rees
587+Timer Service Code -- Debounce and Toggle Filter
588+
589+ 0240 A540 497 bit #F_OPC ; ignore turn signals if opposition cancel
590+ 0242 2702 498 beq TMTNTN
591+ 0244 A4FC 499 and #{$FF ^ TURNSIG}
592+ 0246 B7E0 500 TMTNTN sta DEBO
593+ 0248 BF01 501 stx PORTB ; restore turn signal inputs
594+ 024A BF05 502 stx DDRB
595+ 024C 503 TM0TURN equ *
596+ 504 * leave A == DEBO
597+TOTAL CYCLES = 0 decimal
598+ 024C 505 $CYCLE_ADDER_OFF
599+ 024C 506 $CYCLE_ADDER_ON
600+ 507
601+ 508 * debounce inputs, set flags in TOGGLE and ISTATE
602+ 509 * STABLE_BITS = ~((DEBO[0] ^ DEBO[1]) | (DEBO[1] ^ DEBO[2]))
603+ 510 * A == DEBO on entry
604+ 024C B8E1 511 eor DEBO+1
605+ 024E B7E4 512 sta TOGGLE ; re-use TOGGLE, TOGGLE not valid
606+ 0250 B6E1 513 lda DEBO+1
607+ 0252 B8E2 514 eor DEBO+2
608+ 0254 BAE4 515 ora TOGGLE ; a bit for any input that bounced
609+ 0256 43 516 coma ; bits that bounced are clear
610+ 0257 97 517 tax ; STABLE_BITS
611+ 0258 B4E0 518 and DEBO ; state of stable bits
612+ 025A B7E3 519 sta SSTBLE ; (unstable bits still clear)
613+ 025C 9F 520 txa
614+ 025D B4E5 521 and ISTATE ; look only at bits that are stable
615+ 025F B8E3 522 eor SSTBLE ; flag bits that toggled
616+ 0261 B7E4 523 sta TOGGLE ; true TOGGLEs, but not yet filtered
617+ 0263 43 524 coma ; mask of non-toggles
618+ 0264 B4E5 525 and ISTATE ; old state of non-toggles
619+ 0266 B7E5 526 sta ISTATE ; (toggled bits cleared)
620+ 0268 B6E4 527 lda TOGGLE ; mask of toggles
621+ 026A B4E3 528 and SSTBLE ; new states of bits that toggled
622+ 026C BAE5 529 ora ISTATE
623+ 026E B7E5 530 sta ISTATE ; ISTATE now has current debounced inputs
624+ 531 * leave A == ISTATE
625+ 532
626+ 533 * filter out TOGGLE F_CAN if same direction
627+ 534 * A == ISTATE on entry
628+ 0270 A5C0 535 bit #{F_OPC | F_MNC} ; opposite direction or manual?
629+ 0272 2602 536 bne TMF1CAN
630+ 0274 15E4 537 bclr F_CAN_,TOGGLE ; same direction
631+ 0276 538 TMF1CAN equ *
632+ 539 * leave A == ISTATE
633+ 540
634+ 541 * filter out trailing edge of F_EMG and F_CAN in TOGGLE
635+ 542 * also filter out auxiliary TOGGLEs in passing
636+ 543 * ISTATE == A on entry
637+ 0276 AA33 544 ora #{F_NGN | F_BRK | F_LFT | F_RGT} ; not filtered
638+ 0278 B4E4 545 and TOGGLE ; filter (logical) fall(en) edges
639+ 027A A43F 546 and #{$FF ^ F_OPC ^ F_MNC} ; auxiliaries should never TOGGLE
640+ 027C B7E4 547 sta TOGGLE
641+ 548 * leave A == TOGGLE
642+ 549
643+ 027E 550 SUBHEADER 'Timer Service Code -- Adjust STATES'
644+
645+
646+TURNSIG.asm Assembled with IASM 11/19/1993 00:26 PAGE 15
647+Turn Signal Switch by Joel Matthew Rees
648+Timer Service Code -- Adjust STATES
649+
650+ 027E 550 PAGE
651+ 551
652+ 552 * move brake bit from ISTATE to STATES
653+ 027E 1BE6 553 bclr F_BRK_,STATES
654+ 0280 0BE502 554 brclr F_BRK_,ISTATE,TMF0BRK
655+ 0283 1AE6 555 bset F_BRK_,STATES
656+ 0285 556 TMF0BRK equ *
657+ 557
658+ 558 * toggle STATES F_EMG if TOGGLE F_EMG
659+ 559 * act on TOGGLE to avoid multiple reads of EMG button
660+ 0285 07E406 560 brclr F_EMG_,TOGGLE,TMF0EMG
661+ 0288 B6E6 561 lda STATES
662+ 028A A808 562 eor #F_EMG
663+ 028C B7E6 563 sta STATES ; STATES not yet valid!
664+ 028E 564 TMF0EMG equ *
665+ 028E 201A 565 bra TMSTRN ; skip over the turn signal states table
666+ 566 * leaves A indeterminate
667+ 567
668+ 0290 83 568 swi ; since we have a few unused ROM locations
669+ 0291 83 569 swi
670+ 0292 83 570 swi
671+ 0293 83 571 swi
672+ 0294 83 572 swi
673+ 573
674+ 574 * this table is very data dependent
675+ 0295 575 TURNSTATE equ * ; depends on turn signals being rightmost
676+ 576 * S' S I
677+ 0295 00 577 fcb %00 ; 00 00
678+ 0296 01 578 fcb %01 ; 00 01
679+ 0297 02 579 fcb %10 ; 00 10
680+ 0298 08 580 fcb {%00 | F_EMG} ; 00 11 set F_EMG instead
681+ 0299 01 581 fcb %01 ; 01 00
682+ 029A 01 582 fcb %01 ; 01 01
683+ 029B 02 583 fcb %10 ; 01 10 should not occur
684+ 029C 02 584 fcb %10 ; 01 11 this inverts directions
685+ 029D 02 585 fcb %10 ; 10 00
686+ 029E 01 586 fcb %01 ; 10 01 should not occur
687+ 029F 02 587 fcb %10 ; 10 10
688+ 02A0 01 588 fcb %01 ; 10 11 this inverts directions
689+ 02A1 00 589 fcb %00 ; 11 00 should not occur
690+ 02A2 01 590 fcb %01 ; 11 01 should not occur
691+ 02A3 02 591 fcb %10 ; 11 10 should not occur
692+ 02A4 00 592 fcb %00 ; 11 11 should not occur
693+ 593 * Since PEPROM accesses only one bit at a time,
694+ 594 * and since I can't figure out how to build the turn signal new state
695+ 595 * table in the PEPROM as part of this file anyway,
696+ 596 * and since we apparently have plenty of ROM,
697+ 597 * I decided this table is not a good candidate for the PEPROM.
698+ 598 * Darn!
699+ 599 * After careful consideration, I decided this table does not benefit
700+ 600 * from a more symbolic construction. As it stands, it does not matter
701+ 601 * whether F_LFT or F_RGT is b0, only that they do reside in B0 and B1.
702+ 602
703+ 02A5 83 603 swi ; since we have a few unused ROM locations
704+ 02A6 83 604 swi
705+ 02A7 83 605 swi
706+ 02A8 83 606 swi
707+ 02A9 83 607 swi
708+
709+
710+TURNSIG.asm Assembled with IASM 11/19/1993 00:26 PAGE 16
711+Turn Signal Switch by Joel Matthew Rees
712+Timer Service Code -- Adjust STATES
713+
714+ 608
715+ 609 * turn on STATES turn signal if ISTATE turn signal is on
716+ 610 * check to see if direction has changed
717+ 02AA B6E6 611 TMSTRN lda STATES
718+ 02AC A403 612 and #TURNSIG
719+ 02AE 48 613 lsla
720+ 02AF 48 614 lsla
721+ 02B0 B7EC 615 sta TMPTRN
722+ 02B2 B6E5 616 lda ISTATE
723+ 02B4 A403 617 and #TURNSIG
724+ 02B6 BAEC 618 ora TMPTRN
725+ 02B8 97 619 tax
726+ 02B9 D60295 620 lda TURNSTATE,x
727+ 02BC B7EC 621 sta TMPTRN
728+ 02BE B6E6 622 lda STATES
729+ 02C0 A4FC 623 and #{$FF ^ TURNSIG}
730+ 02C2 BAEC 624 ora TMPTRN ; table is 0s in b2-7, except forced F_EMG
731+ 02C4 B7E6 625 sta STATES ; may be reset by F_CAN
732+ 626 * leaves A == STATES
733+ 627
734+ 628 * cancel STATES turn signal if TOGGLE F_CAN is not filtered out
735+ 629 * Act on TOGGLE to avoid multiple reads of single actuator pass!
736+ 630 * A == STATES on entry
737+ 02C6 05E404 631 brclr F_CAN_,TOGGLE,TMCAN0
738+ 02C9 A4FC 632 and #{$FF ^ TURNSIG}
739+ 02CB B7E6 633 sta STATES ; STATES not yet valid!
740+ 02CD 634 TMCAN0 equ * ; turn signals are valid
741+ 635 * leaves A == STATES
742+ 636
743+ 637 * Now we should have no more than one turn signal on.
744+ 638 * set up steering wheel return sense state or clear it
745+ 639 * then latch turn signal input to keep it from reverting
746+ 640 * A == STATES on entry
747+ 02CD A403 641 and #TURNSIG
748+ 02CF B701 642 sta PORTB ; another handy value dependency!
749+ 02D1 B705 643 sta DDRB ; gate it out, if there
750+ 644 * I feel there is a better way, but I'm out of time
751+ 02D3 B7EC 645 sta TMPTRN ; feed response back
752+ 02D5 B6E5 646 lda ISTATE
753+ 02D7 A4FC 647 and #{$FF ^ TURNSIG}
754+ 02D9 BAEC 648 ora TMPTRN
755+ 02DB B7E5 649 sta ISTATE
756+ 650 * leaves A == ISTATE
757+ 651
758+ 652 * if not timed out, STATES F_NGN should not yet be clear!
759+ 02DD B6E8 653 lda NGN_TIM+1
760+ 02DF BAE7 654 ora NGN_TIM
761+ 02E1 2602 655 bne TMFNGN0
762+ 02E3 18E6 656 bset F_NGN_,STATES ; might time out before RTI
763+ 02E5 657 TMFNGN0 equ *
764+ 658
765+ 659 * STATES is still not valid!
766+ 660 * fall through to TMCLOCK
767+ 661
768+ 02E5 662 SUBHEADER 'Timer Service Code -- Engine Time Out and Flasher Timers'
769+
770+
771+TURNSIG.asm Assembled with IASM 11/19/1993 00:26 PAGE 17
772+Turn Signal Switch by Joel Matthew Rees
773+Timer Service Code -- Engine Time Out and Flasher Timers
774+
775+ 02E5 662 PAGE
776+ 663
777+ 664 * reset engine time-out if F_NGN, F_EMG, or F_BRK TOGGLEs
778+ 02E5 B6E4 665 TMCLOCK lda TOGGLE
779+ 02E7 A438 666 and #{F_NGN | F_EMG | F_BRK}
780+ 02E9 2708 667 beq TMORST
781+ 02EB A601 668 lda #{TIMOUT & $FF } ; reset value low byte
782+ 02ED B7E8 669 sta NGN_TIM+1
783+ 02EF A601 670 lda #{TIMOUT / $100 + 1} ; borrow on 0, not -1
784+ 02F1 B7E7 671 sta NGN_TIM
785+ 02F3 672 TMORST equ *
786+ 673
787+ 674 * if flashers TOGGLE off, reset the flashers
788+ 675 * if they TOGGLE on, clear the mask only if none on before
789+ 02F3 A60B 676 lda #{F_EMG | TURNSIG}
790+ 02F5 B5E4 677 bit TOGGLE
791+ 02F7 2714 678 beq TMSCLK
792+ 02F9 B5E6 679 bit STATES ; flasher active?
793+ 02FB 260A 680 bne TMMFLH
794+ 02FD A6FF 681 lda #$FF ; reset flash timer
795+ 02FF B7EA 682 sta FLDARK
796+ 0301 A601 683 lda #FLASH1
797+ 0303 B7E9 684 sta FLASH
798+ 0305 2006 685 bra TMSCLK
799+ 686
800+ 0307 B5ED 687 TMMFLH bit LASTST ; flashers already running?
801+ 0309 2602 688 bne TMMFLH0 ; might be better to shine on every change?
802+ 030B 3FEA 689 clr FLDARK
803+ 030D 690 TMMFLH0 equ *
804+ 691
805+ 692 * Although the Real Time Interrupt is masked, the software clocks
806+ 693 * clock on the RTI flag. See RTIPOW for the RTI flag rate
807+ 694
808+ 030D 0D082D 695 TMSCLK brclr RTIF_,TSCR,TIMDUN
809+ 0310 1408 696 bset RTIFR_,TSCR
810+ 697
811+ 698 * Engine time-out counter only runs when the ISTATE F_NGN bit is
812+ 699 * low and the emergency flashers and brakes (STATES F_EMG and F_BRK) are
813+ 700 * with power down routine via STATES F_NGN.
814+ 701
815+ 0312 08E514 702 brset F_NGN_,ISTATE,TMNGNR0
816+ 0315 B6E6 703 lda STATES
817+ 0317 A438 704 and #{F_NGN | F_EMG | F_BRK} ; brakes or emg flashers?
818+ 0319 A810 705 eor #F_NGN ; already counted out?
819+ 031B 260C 706 bne TMNGNR0
820+ 031D 3AE8 707 dec NGN_TIM+1
821+ 031F 2608 708 bne TMNGNR0 ; initial count is adjusted to make this work
822+ 0321 3AE7 709 dec NGN_TIM
823+ 0323 2604 710 bne TMNGNR0
824+ 0325 19E6 711 bclr F_NGN_,STATES ; signal timed out
825+ 0327 18E4 712 bset F_NGN_,TOGGLE ; communicate change to STATES F_NGN
826+ 0329 713 TMNGNR0 equ * ; Only now is STATES valid!
827+ 714
828+ 715 * The flasher counter runs only when STATES F_EMG, F_LFT, or F_RGT
829+ 716 * are set. When there are no flashers running, FLDARK is set, causing
830+ 717 * FLASH1 (on time) to be loaded when when flasher timer starts.
831+ 718
832+ 0329 A60B 719 TMFLASH lda #{F_EMG | TURNSIG}
833+
834+
835+TURNSIG.asm Assembled with IASM 11/19/1993 00:26 PAGE 18
836+Turn Signal Switch by Joel Matthew Rees
837+Timer Service Code -- Engine Time Out and Flasher Timers
838+
839+ 032B B5E6 720 bit STATES ; flasher active?
840+ 032D 270E 721 beq TMFLH0
841+ 032F 3AE9 722 dec FLASH
842+ 0331 260A 723 bne TMFLH0
843+ 0333 A601 724 lda #FLASH1
844+ 0335 33EA 725 com FLDARK
845+ 0337 2A02 726 bpl TMFLTM ; result dark (1s) or light (0s)
846+ 0339 A601 727 lda #FLASH0
847+ 033B B7E9 728 TMFLTM sta FLASH
848+ 033D 729 TMFLH0 equ *
849+ 730
850+ 731 * It might be amusing to install a turn signal time out so that if
851+ 732 * the turn signals remain flashing for more than ten minutes, they turn
852+ 733 * themselves off. The entire mechanism should fit here. As mentioned
853+ 734 * above, consider safety first!
854+ 735
855+ 736 TIMDUN
856+ 033D 3CF5 737 inc DBGCT+3 ; count number of timer interrupts serviced
857+ 033F 260A 738 bne TIMDUX ; put here strictly for debugging sessions
858+ 0341 3CF4 739 inc DBGCT+2 ; so I can have an idea of virtual time
859+ 0343 2606 740 bne TIMDUX
860+ 0345 3CF3 741 inc DBGCT+1
861+ 0347 2602 742 bne TIMDUX
862+ 0349 3CF2 743 inc DBGCT
863+ 744 TIMDUX
864+ 034B 120A 745 bset IRQR_,ISCR ; POTA and IRQ activity may set IRQF
865+ 034D 80 746 rti
866+TOTAL CYCLES = 0 decimal
867+ 034E 747 $CYCLE_ADDER_OFF
868+ 748
869+ 034E 83 749 swi ; more unused ROM
870+ 034F 83 750 swi
871+ 0350 83 751 swi
872+ 0351 83 752 swi
873+ 0352 83 753 swi
874+ 0353 83 754 swi
875+ 0354 83 755 swi
876+ 756
877+ 0355 757 SUBHEADER 'Initializations'
878+
879+
880+TURNSIG.asm Assembled with IASM 11/19/1993 00:26 PAGE 19
881+Turn Signal Switch by Joel Matthew Rees
882+Initializations
883+
884+ 0355 757 PAGE
885+ 758
886+ 759 * waking up simply resets the MCU
887+ 760 * if SWI occurs, the machine is not in a defined state, and must reset
888+ 761 IRQSRV
889+ 762 SWISRV
890+ 0355 AE5C 763 ldx #$5C ; unique
891+ 0357 CF03F0 764 stx COPR
892+ 035A 9C 765 rsp ; now falls through to RSTSRV
893+ 035B 120A 766 bset IRQR_,ISCR ; it just gets us started
894+ 767
895+ 768 * general inits
896+ 769 RSTSRV
897+ 770 * disable external interrupts
898+ 035D 1F0A 771 bclr IRQE_,ISCR ; disable external interrupts
899+ 035F 120A 772 bset IRQR_,ISCR ; clear the external interrupt flag
900+ 773 * get ports stared right
901+ 0361 A6F0 774 lda #DRVLMPS
902+ 0363 B700 775 sta PORTA ; initial output values
903+ 0365 A6F2 776 lda #{DRVLMPS | DRVDRV}
904+ 0367 B704 777 sta DDRA ; set up directions
905+ 0369 B710 778 sta PDRA ; pull downs only on inputs
906+ 036B 3F01 779 clr PORTB ; initial outputs (do port B just in case)
907+ 036D 3F05 780 clr DDRB ; B initially input
908+ 036F 3F11 781 clr PDRB ; with pull downs set
909+ 782 * make sure EPROM programming stuff is out of the way
910+ 783 * clr EPROG ; ICS05K complains, skip by hand
911+ 0371 3F0F 784 clr PESCR
912+ 785 * set up specific variables
913+ 0373 A610 786 lda #F_NGN ; pretend the engine is on, to get us started
914+ 0375 B7E0 787 sta DEBO ; start debounce chain clear
915+ 0377 B7E1 788 sta DEBO+1 ; DEBO+2 is thrown out on first timer interrupt
916+ 0379 B7E6 789 sta STATES ; no unknown states
917+ 037B B7E5 790 sta ISTATE
918+ 037D A601 791 lda #{TIMOUT & $FF } ; reset time-out low byte
919+ 037F B7E8 792 sta NGN_TIM+1
920+ 0381 A601 793 lda #{TIMOUT / $100 + 1} ; counter borrows on 0, not -1
921+ 0383 B7E7 794 sta NGN_TIM
922+ 0385 A6FF 795 lda #$FF
923+ 0387 B7EA 796 sta FLDARK ; initial flash state is dark
924+ 0389 A601 797 lda #FLASH1
925+ 038B B7E9 798 sta FLASH ; initial flash time is on/light state
926+ 799 * clear the virtual debugging time counter
927+ 038D 3FF2 800 clr DBGCT
928+ 038F 3FF3 801 clr DBGCT+1
929+ 0391 3FF4 802 clr DBGCT+2
930+ 0393 3FF5 803 clr DBGCT+3
931+ 804 * set up hardware timer
932+ 0395 AE6A 805 ldx #$6A ; unique use of X
933+ 0397 CF03F0 806 stx COPR ; b0 clear, about to change timer rate
934+ 039A A600 807 lda #{RTIPOW} ; set rate
935+ 039C B708 808 sta TSCR
936+ 039E AA0C 809 ora #{TOFR | RTIFR} ; clear pending interrupts
937+ 03A0 B708 810 sta TSCR
938+ 03A2 1A08 811 bset TOIE_,TSCR ; first section overflow interrupt only
939+ 812
940+ 813 * Falls through to DOSTATES
941+ 814
942+
943+
944+TURNSIG.asm Assembled with IASM 11/19/1993 00:26 PAGE 20
945+Turn Signal Switch by Joel Matthew Rees
946+DOSTATES: Interpret States
947+
948+ 03A4 815 SUBHEADER 'DOSTATES: Interpret States'
949+
950+
951+TURNSIG.asm Assembled with IASM 11/19/1993 00:26 PAGE 21
952+Turn Signal Switch by Joel Matthew Rees
953+DOSTATES: Interpret States
954+
955+ 03A4 815 PAGE
956+ 816
957+ 817 * The debounce and timer routines make the output state machine
958+ 818 * simple. All indicator lamps are set according to the indicator STATES,
959+ 819 * then masked by the current flasher output state (FLDARK). Then, if the
960+ 820 * brake light STATES bit is set, the rear lamps are forced on. Then,
961+ 821 * DRVDRV is only set if lamps are on (to save power when the engine is
962+ 822 * off).
963+ 823
964+ 824 * Finally, if STATES F_NGN bit is clear, the power-down routine is
965+ 825 * executed (and never returned from). Again, requiring the time-out
966+ 826 * counter to hold off the STATES engine-on bit may be a bit of a
967+ 827 * semantic overload, but it seems more natural than making the STATES
968+ 828 * F_NGN bit a mere mirror of ISTATE F_NGN, and then maintaining a
969+ 829 * separate flag which would operate by the same rules as STATES F_NGN
970+ 830 * does in the present design. It also seems less data coupled than
971+ 831 * having the power-down sense routine examine the internals of the
972+ 832 * counter.
973+ 833
974+ 834 * FLDARK is used slightly ambiguously: in the flasher timer
975+ 835 * routine, bit 7 is used to determine whether to use the on period or
976+ 836 * off period. In the output state machine, below, all lamp bits are
977+ 837 * used to mask out the signal lamps when the flasher says they should be
978+ 838 * dark. Rather than concern myself in several places with the state of
979+ 839 * non-lamp bits, I mask them out where they could cause trouble.
980+ 840
981+ 841 DOSTATES:
982+ 03A4 8F 842 wait ; wait for something intelligible to debounce
983+ 03A5 AE78 843 ldx #$78 ; unique
984+ 03A7 CF03F0 844 stx COPR ; tell COP we're in control
985+ 845
986+ 846 * update the (inverted) lamp output state
987+ 03AA A6F0 847 lda #DRVLMPS ; guess nothing shines (inverted drive)
988+ 848 * A == lamp output state
989+ 849
990+ 850 * now mask in inverted drive bits for any flashers that are on
991+ 03AC 07E602 851 brclr F_EMG_,STATES,STT0EMG
992+ 03AF A40F 852 and #{$FF ^ DRVLMPS}
993+ 03B1 853 STT0EMG equ *
994+ 854 * A == lamp output state
995+ 855
996+ 03B1 03E602 856 brclr F_LFT_,STATES,STT0LFT
997+ 03B4 A45F 857 and #{$FF ^ LFTDRV}
998+ 03B6 858 STT0LFT equ *
999+ 859 * A == lamp output state
1000+ 860
1001+ 03B6 01E602 861 brclr F_RGT_,STATES,STT0RGT
1002+ 03B9 A4AF 862 and #{$FF ^ RGTDRV}
1003+ 03BB 863 STT0RGT equ *
1004+ 864 * A == lamp output state
1005+ 865
1006+ 866 * mask out flasher lamps if flasher is in off state
1007+ 03BB BAEA 867 ora FLDARK
1008+ 868 * A == lamp output state
1009+ 869
1010+ 870 * check for brake lights
1011+ 03BD 0BE602 871 STTBRK brclr F_BRK_,STATES,STT0BRK
1012+ 03C0 A4CF 872 and #{$FF ^ REARDRV} ; brake has higher priority than flash
1013+
1014+
1015+TURNSIG.asm Assembled with IASM 11/19/1993 00:26 PAGE 22
1016+Turn Signal Switch by Joel Matthew Rees
1017+DOSTATES: Interpret States
1018+
1019+ 03C2 873 STT0BRK equ *
1020+ 874 * A == lamp output state
1021+ 875
1022+ 03C2 A4F0 876 and #DRVLMPS ; filter out extraneous bits
1023+ 03C4 B7EB 877 sta FLMASK
1024+ 03C6 A8F0 878 eor #DRVLMPS ; any lamps driven?
1025+ 03C8 2702 879 beq STT0FLH ; invert the CCR zero bit and move it to DRVDRV
1026+ 03CA 12EB 880 bset DRVDRV_,FLMASK
1027+ 03CC 881 STT0FLH equ *
1028+ 882 * now A is free
1029+ 883
1030+ 03CC B600 884 lda PORTA
1031+ 03CE A40D 885 and #{$FF ^ DRVLMPS ^ DRVDRV}
1032+ 03D0 BAEB 886 ora FLMASK
1033+ 03D2 B700 887 sta PORTA
1034+ 888
1035+ 889 * all done with lamps until next timer interrupt
1036+ 890 * loop to wait if engine not timed-out
1037+ 03D4 08E6CD 891 brset F_NGN_,STATES,DOSTATES
1038+ 892
1039+ 893 * At this point, we know there has been no engine, emergency flasher, or
1040+ 894 * brake activity for about five minutes.
1041+ 895
1042+ 896 * go to power conserving state
1043+ 897 * first shut down all lamps
1044+ 03D7 A6F0 898 lda #DRVLMPS ; DRVDRV, CAN_BT also off!
1045+ 899 * should be lda #{DRVLMPS & ~DRVDRV & ~CAN_BT} for clarity
1046+ 03D9 B700 900 sta PORTA ; don't feed CAN_BT to pull downs
1047+ 901 * now make sure power down state is valid!
1048+ 03DB A6F3 902 lda #{DRVLMPS | DRVDRV | CAN_BT}
1049+ 03DD B704 903 sta DDRA ; interrupts only from NGN_SW, BRK_SW, EMG_BT
1050+ 03DF B710 904 sta PDRA ; pull downs only on inputs
1051+ 03E1 3F01 905 clr PORTB ; initial outputs (do port B just in case)
1052+ 03E3 3F05 906 clr DDRB ; B initially input
1053+ 03E5 3F11 907 clr PDRB ; with pull downs set
1054+ 908 * make sure EPROM programming stuff is out of the way
1055+ 909 * clr EPROG ; ICS complains, skip by hand
1056+ 03E7 3F0F 910 clr PESCR
1057+ 911 * enable external interrupts
1058+ 03E9 1E0A 912 bset IRQE_,ISCR ; DO NOT clear the flag (don't miss anything)
1059+ 03EB 8E 913 stop ; also shuts timer down
1060+ 03EC 83 914 swi ; should never come here (IRQSRV resests stack pointer)
1061+ 03ED 83 915 swi ; more unused ROM
1062+ 03EE 83 916 swi
1063+ 03EF 83 917 swi
1064+ 918
1065+ 03F0 919 SUBHEADER 'Interrupt Vectors'
1066+
1067+
1068+TURNSIG.asm Assembled with IASM 11/19/1993 00:26 PAGE 23
1069+Turn Signal Switch by Joel Matthew Rees
1070+Interrupt Vectors
1071+
1072+ 03F0 919 PAGE
1073+ 920
1074+ 03F8 921 org VECTORS
1075+ 03F8 0203 922 fdb TIMSRV
1076+ 03FA 0355 923 fdb IRQSRV
1077+ 03FC 0355 924 fdb SWISRV
1078+ 03FE 035D 925 fdb RSTSRV
1079+ 926
1080+ 0400 927 SUBHEADER 'Symbol Table'
1081+ 0400 928 end
1082+ 929
1083+ 930
1084+
1085+ Symbol Table
1086+
1087+ANYLITE 002B
1088+B0 0001
1089+B0_ 0000
1090+B1 0002
1091+B1_ 0001
1092+B2 0004
1093+B2_ 0002
1094+B3 0008
1095+B3_ 0003
1096+B4 0010
1097+B4_ 0004
1098+B5 0020
1099+B5_ 0005
1100+B6 0040
1101+B6_ 0006
1102+B7 0080
1103+B7_ 0007
1104+BRK_SW 0008
1105+BRK_SW_ 0003
1106+CAN_BT 0001
1107+CAN_BT_ 0000
1108+COPEN 0001
1109+COPR 03F0
1110+DBGCT 00F2
1111+DDRA 0004
1112+DDRB 0005
1113+DEBO 00E0
1114+DOSTATES 03A4
1115+DRVDRV 0002
1116+DRVDRV_ 0001
1117+DRVLMPS 00F0
1118+ELAT 0004
1119+ELAT_ 0002
1120+EMG_BTF 0002
1121+EMG_BTF_ 0001
1122+EPGM 0001
1123+EPGM_ 0000
1124+EPROG 0018
1125+FLASH 00E9
1126+FLASH0 0001
1127+FLASH1 0001
1128+FLDARK 00EA
1129+FLMASK 00EB
1130+
1131+
1132+TURNSIG.asm Assembled with IASM 11/19/1993 00:26 PAGE 24
1133+Turn Signal Switch by Joel Matthew Rees
1134+Symbol Table
1135+
1136+FRNTDRV 00C0
1137+F_BRK 0020
1138+F_BRK_ 0005
1139+F_CAN 0004
1140+F_CAN_ 0002
1141+F_EMG 0008
1142+F_EMG_ 0003
1143+F_LDRV 0080
1144+F_LDRV_ 0007
1145+F_LFT 0002
1146+F_LFT_ 0001
1147+F_MNC 0080
1148+F_NGN 0010
1149+F_NGN_ 0004
1150+F_OPC 0040
1151+F_RDRV 0040
1152+F_RDRV_ 0006
1153+F_RGT 0001
1154+F_RGT_ 0000
1155+IRQE 0080
1156+IRQE_ 0007
1157+IRQF 0008
1158+IRQF_ 0003
1159+IRQR 0002
1160+IRQR_ 0001
1161+IRQSRV 0355
1162+IRQVEC 03FA
1163+ISCR 000A
1164+ISTATE 00E5
1165+LASTST 00ED
1166+LEVEL 0002
1167+LFTDRV 00A0
1168+LFT_BT 0002
1169+LFT_BT_ 0001
1170+LVRE 0008
1171+MOR 0017
1172+MPGM 0002
1173+MPGM_ 0001
1174+NGN_SW 0004
1175+NGN_SW_ 0002
1176+NGN_TIM 00E7
1177+PDRA 0010
1178+PDRB 0011
1179+PEBSR 000E
1180+PEDATA 0080
1181+PEDATA_ 0007
1182+PEPGM 0020
1183+PEPGM_ 0005
1184+PEPRZF 0001
1185+PEPRZF_ 0000
1186+PESCR 000F
1187+PIN3 0040
1188+PIRQ 0004
1189+PORTA 0000
1190+PORTB 0001
1191+RAMBEG 00E0
1192+RAMSIZ 0020
1193+RC 0020
1194+
1195+
1196+TURNSIG.asm Assembled with IASM 11/19/1993 00:26 PAGE 25
1197+Turn Signal Switch by Joel Matthew Rees
1198+Symbol Table
1199+
1200+REARDRV 0030
1201+RESET 03FE
1202+RGTDRV 0050
1203+RGT_BT 0001
1204+RGT_BT_ 0000
1205+ROMBEG 0200
1206+RSTSRV 035D
1207+RT0 0001
1208+RT0_ 0000
1209+RT1 0002
1210+RT1_ 0001
1211+RTIE 0010
1212+RTIE_ 0004
1213+RTIF 0040
1214+RTIFR 0004
1215+RTIFR_ 0002
1216+RTIF_ 0006
1217+RTIPOW 0000
1218+RTIRATE 0002
1219+R_LDRV 0020
1220+R_LDRV_ 0005
1221+R_RDRV 0010
1222+R_RDRV_ 0004
1223+SSTBLE 00E3
1224+STATES 00E6
1225+STKTOP 00FF
1226+STT0BRK 03C2
1227+STT0EMG 03B1
1228+STT0FLH 03CC
1229+STT0LFT 03B6
1230+STT0RGT 03BB
1231+STTBRK 03BD
1232+SWAIT 0010
1233+SWISRV 0355
1234+SWIVEC 03FC
1235+SWPDI 0080
1236+TCNTR 0009
1237+TIMDUN 033D
1238+TIMDUX 034B
1239+TIMER 0009
1240+TIMOUT 0001
1241+TIMSRV 0203
1242+TIMVEC 03F8
1243+TM0TURN 024C
1244+TMCAN0 02CD
1245+TMCLOCK 02E5
1246+TMF0BRK 0285
1247+TMF0EMG 028E
1248+TMF1CAN 0276
1249+TMFLASH 0329
1250+TMFLH0 033D
1251+TMFLTM 033B
1252+TMFNGN0 02E5
1253+TMIEMG 0219
1254+TMMFLH 0307
1255+TMMFLH0 030D
1256+TMNGNR0 0329
1257+TMORST 02F3
1258+
1259+
1260+TURNSIG.asm Assembled with IASM 11/19/1993 00:26 PAGE 26
1261+Turn Signal Switch by Joel Matthew Rees
1262+Symbol Table
1263+
1264+TMPTRN 00EC
1265+TMSCLK 030D
1266+TMSTRN 02AA
1267+TMTBIT6 0235
1268+TMTBIT7 023B
1269+TMTNTN 0246
1270+TOF 0080
1271+TOFR 0008
1272+TOFR_ 0003
1273+TOF_ 0007
1274+TOGGLE 00E4
1275+TOIE 0020
1276+TOIE_ 0005
1277+TSCR 0008
1278+TSTROM 03F0
1279+TURNSIG 0003
1280+TURNSTATE 0295
1281+VECTORS 03F8
1282+XTAL 0001
Binary files /dev/null and b/TURNSIG.MAP differ
--- /dev/null
+++ b/TURNSIG.S19
@@ -0,0 +1,34 @@
1+S104001727BD
2+S11302008383831608B6E1B7E2B6E0B7E1B6E6B792
3+S1130210EDB600A40D2F02AA024848B7E0B601BA11
4+S1130220E0B7E0A5042725BE0527219FA803B70151
5+S1130230B705000000463F0500000046A4C0BAE030
6+S1130240A5402702A4FCB7E0BF01BF05B8E1B7E4AD
7+S1130250B6E1B8E2BAE44397B4E0B7E39FB4E5B8D3
8+S1130260E3B7E443B4E5B7E5B6E4B4E3BAE5B7E528
9+S1130270A5C0260215E4AA33B4E4A43FB7E41BE600
10+S11302800BE5021AE607E406B6E6A808B7E6201A64
11+S113029083838383830001020801010202020102B5
12+S11302A001000102008383838383B6E6A4034848E4
13+S11302B0B7ECB6E5A403BAEC97D60295B7ECB6E66C
14+S11302C0A4FCBAECB7E605E404A4FCB7E6A403B7BF
15+S11302D001B705B7ECB6E5A4FCBAECB7E5B6E8BAE5
16+S11302E0E7260218E6B6E4A4382708A601B7E8A66C
17+S11302F001B7E7A60BB5E42714B5E6260AA6FFB7AF
18+S1130300EAA601B7E92006B5ED26023FEA0D082D5D
19+S1130310140808E514B6E6A438A810260C3AE82612
20+S1130320083AE7260419E618E4A60BB5E6270E3AC0
21+S1130330E9260AA60133EA2A02A601B7E93CF52612
22+S11303400A3CF426063CF326023CF2120A8083831C
23+S11303508383838383AE5CCF03F09C120A1F0A124B
24+S11303600AA6F0B700A6F2B704B7103F013F053F55
25+S1130370113F0FA610B7E0B7E1B7E6B7E5A601B79E
26+S1130380E8A601B7E7A6FFB7EAA601B7E93FF23F3F
27+S1130390F33FF43FF5AE6ACF03F0A600B708AA0C0A
28+S11303A0B7081A088FAE78CF03F0A6F007E602A4C8
29+S11303B00F03E602A45F01E602A4AFBAEA0BE60269
30+S11303C0A4CFA4F0B7EBA8F0270212EBB600A40D5B
31+S11303D0BAEBB70008E6CDA6F0B700A6F3B704B7AA
32+S11303E0103F013F053F113F0F1E0A8E8383838315
33+S10B03F8020303550355035DE4
34+S9030000FC