1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
rem DigitalIO.bas
rem
rem last revision 2004 October 19
rem
rem In this example, HOLD and LOCK are used as macro controlled
rem outputs while CAPTURE remains an input.

rem The 3 rear pins HOLD, LOCK, and CAPTURE can be used either
rem as inputs (default) or as outputs and are controlled by the
rem DIGITAL_IO register (&152 on Tiger 320) in bits 0-2.
rem
rem Writing a 1 into the according flag turns it into an output.
rem Writing a 0 into the according flag turns it into an input.
rem 
rem To avoid errors, the bit flags (e.g. |HOLD_PIN) are read-only. 
rem If a pin is used as an output the whole register &DIGITAL_IO
rem has to be set appropriately.
rem
rem Note: set only the output bits and leave the other bits at 0 !!!

CONST HOLD_ON = 0x0001
CONST LOCK_ON = 0x0002
CONST HOLD_LOCK_ON = 0x0003

// clear tare instead of display hold/key lock function for HOLD/LOCK
MEM &CODE9 = 0055

///////////////////////////////////////////////////////////////////////////
CUSTOMER_ID_MACRO:
///////////////////////////////////////////////////////////////////////////
write "      Digital IO      "
END

///////////////////////////////////////////////////////////////////////////
RESET_MACRO:
///////////////////////////////////////////////////////////////////////////
// set HOLD/LOCK/CAPTURE flag to 0 => all inputs
&DIGITAL_IO = 0

// remember last status of capture pin
|capture_last = |CAPTURE_PIN

#outputs = 0
END

///////////////////////////////////////////////////////////////////////////
MAIN_MACRO:
///////////////////////////////////////////////////////////////////////////

// switch outputs each time CAPTURE pin is connected
if |CAPTURE_PIN = on and |capture_last = off then
  |capture_last = on

  // look only at the output flags
  #outputs = &DIGITAL_IO and HOLD_LOCK_ON

  // set only the output bits and leave the input bits at 0 !!!
  select #outputs
  case HOLD_ON:
    &DIGITAL_IO = HOLD_LOCK_ON
  case HOLD_LOCK_ON:
    &DIGITAL_IO = LOCK_ON // => HOLD flag is 0
  case LOCK_ON:
    &DIGITAL_IO = 0
  default:
    &DIGITAL_IO = HOLD_ON // => LOCK flag is 0
  endsel

elsif |CAPTURE_PIN = off then
  |capture_last = off
endif

// use the LEDs to show the current status of the rear pins
if |HOLD_PIN = on then
  |LED1 = on
  |LED2 = on
else
  |LED1 = off
  |LED2 = off
endif

if |LOCK_PIN = on then
  |LED3 = on
  |LED4 = on
else
  |LED3 = off
  |LED4 = off
endif

if |CAPTURE_PIN = on then
  |LED5 = on
  |LED6 = on
else
  |LED5 = off
  |LED6 = off
endif
  
END

Download DigitalIO.bas
(2.4 KB , Aug. 26, 2008)