Home » Archimedes archive » Acorn User » AU 1997-07 A.adf » Regulars » Rambles/EnhancdIIC/IIC_Demo

Rambles/EnhancdIIC/IIC_Demo

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » Archimedes archive » Acorn User » AU 1997-07 A.adf » Regulars
Filename: Rambles/EnhancdIIC/IIC_Demo
Read OK:
File size: 1FD1 bytes
Load address: 0000
Exec address: 0000
File contents
   10 REM > IIC_Demo
   20 :
   30 ONERRORIFERR=17RUN:      ELSEPRINT"Error ";:      REPORT:      PRINT" at line "ERL:      END
   40 REM IIC Device Bus Addresses : Odd to read from, Even to write to
   50 
   60 IIC_DAC=&90
   70 IIC_ADC=&91
   80 IIC_DigIn=&41
   90 IIC_DigOut=&40
  100 :
  110 REM Analogue to Digital Convertor - 8591 Status bits
  120 IIC_ADC_Status=&40
  130 :
  140 REM Digital i/o port 8574 Bit Allocation
  150 REM NB these are effectively inverting, ie 0 is ON and 1 is OFF
  160 RelayOn=&01
  170 MotorOn=&02
  180 RedTraffLED=&04
  190 AmbrTraffLED=&08
  200 GrnTraffLED=&10
  210 RedLED3=&20
  220 RedLED2=&40
  230 RedLED1=&80
  240 :
  250 REM Digital Output Port Local Copy (used by PROCWriteDigital ())
  260 DigOutCopy% = 0
  270 PROCWriteDigital(IIC_DigOut, 0, &FF) :       REM All Off initially
  280 :
  290 REM Attach Voices for sound output
  300 SYS"Sound_Configure",8,208,48,0,0
  310 FOR i%=1 TO 8
  320   SYS"Sound_AttachVoice",i%,1
  330 NEXT i%
  340 :
  350 VDU26,12
  360 REPEAT
  370   PRINT TAB(10,2)"This BASIC program demonstrates the range of ODDULES from"
  380   PRINT TAB(10,4)"Baildon Electronics.  They are intended to provide low cost"
  390   PRINT TAB(10,6)"but flexible Input/Output expansion for the Archimedes and"
  400   PRINT TAB(10,8)"A3000 range of computers.  Here we have the AnDi Oddule,"
  410   PRINT TAB(10,10)"ie combined Analogue and Digital I/O.  Up to 8 of these"
  420   PRINT TAB(10,12)"can be connected to the computer.   Note the simplicity of"
  430   PRINT TAB(10,14)"each - there are only two Integrated Circuits in each AnDi"
  440   PRINT TAB(10,16)"Oddule - one for analogue and one for digital I/O.  There"
  450   PRINT TAB(10,18)"are other Oddules in development, and if you have any"
  460   PRINT TAB(10,20)"suggestions, then we will be pleased to hear from you."
  470   PRINT TAB(10,24)"Press one of the buttons on the circuit board for a demonstration:"
  480   PRINT TAB(17,26)"BLUE for Analogue to Digital Convertor Demonstration"
  490   PRINT TAB(17,28)"GREY for Digital to Analogue Convertor Demonstration"
  500   PRINT TAB(17,30)"RED for Digital Input/Output Demonstration"
  510   IFINKEY (-99) THENX=GET:        QUIT
  520 
  530   l%=FNReadDigital(IIC_DigIn)
  540   IF (l% AND RedLED1) = 0 THEN
  550     PROCLightTosound
  560     ELSE
  570     IF (l% AND RedLED2) = 0 THEN
  580       PROCDemoDtoA
  590       ELSE
  600       IF (l% AND RedLED3) = 0 THEN
  610         PROCDemoDigitalIO
  620         ELSE
  630         PROCWriteDigital(IIC_DigOut, &FF, RedLED1+RedLED2+RedLED3)
  640         PROCDelay (10)
  650       ENDIF
  660     ENDIF
  670   ENDIF
  680   PROCWriteDigital(IIC_DigOut, 0, &FF) :         REM All Off
  690   PROCDelay (10)
  700 UNTIL FALSE
  710 END
  720 :
  730 DEF PROCLightTosound
  740 REM Light Controlled Sound Generator
  750 LOCAL i%,j%
  760 CLS
  770 PRINT TAB(10,4)"The potential difference across the Photo-conductive cell is"
  780 PRINT TAB(10,6)"regularly sampled.  The samples are used to control the pitch of"
  790 PRINT TAB(10,8)"the eight internal sound channels, each channel being taken in"
  800 PRINT TAB(10,10)"rotation.  The Analogue to Digital Convertor (ADC) provides"
  810 PRINT TAB(10,12)"8 bit resolution from each of 4 channels.  The analogue"
  820 PRINT TAB(10,14)"inputs can be used in a variety of single-ended and/or"
  830 PRINT TAB(10,16)"differential combinations.  The maximum sample rate is"
  840 PRINT TAB(10,18)"limited by the IIC Bus to about 10,000 samples per second."
  850 PRINT TAB(10,20)"The convertor is of the multiplying type.   Analogue-ground"
  860 PRINT TAB(10,22)"(AGnd) and the reference voltage (VRef) are accessible to"
  870 PRINT TAB(10,24)"the user (range 0 to 5v)"
  880 PROCWriteDigital(IIC_DigOut, &FF, RedLED1)
  890 FOR i%=1 TO 20
  900   FOR j%=1 TO 8
  910     av = FNReadAnalogue (IIC_ADC)
  920     SOUND j%,-15,av/2,50   :           REM av/2 is Pitch of note
  930     PROCDelay(1)
  940   NEXT j%
  950 NEXT i%
  960 CLS
  970 ENDPROC
  980 :
  990 DEF PROCDemoDtoA
 1000 REM Demo of digital to analogue conversion
 1010 LOCAL i%,j%,k%
 1020 CLS
 1030 PRINT TAB(10,8)"The output of the 8 bit Digital to Analogue Convertor (DAC)"
 1040 PRINT TAB(10,10)"is static, that is the output does not require periodic refreshing."
 1050 PRINT TAB(10,12)"It can easily outpace this analogue meter !"
 1060 PRINT TAB(10,14)"The rate of update of the output is limited by the IIC bus"
 1070 PRINT TAB(10,16)"to 10,000 updates per second."
 1080 PRINT TAB(10,18)"The convertor is of the multiplying type.   Analogue-ground"
 1090 PRINT TAB(10,20)"(AGnd) and the reference voltage (VRef) are accessible to"
 1100 PRINT TAB(10,22)"the user (range 0 to 5v)"
 1110 PROCWriteDigital (IIC_DigOut,&FF, RedLED2)
 1120 FOR i% = 1 TO 4
 1130   FOR j% = 1 TO 21 STEP 2
 1140     FOR k% = 0 TO 210 STEP j%
 1150       PROCWriteAnalogue(IIC_DAC, k%)
 1160       PROCDelay (1)
 1170     NEXT k%
 1180     FOR k% = 210 TO 0 STEP -j%
 1190       PROCWriteAnalogue(IIC_DAC, k%)
 1200       PROCDelay (1)
 1210     NEXT k%
 1220   NEXT j%
 1230 NEXT i%
 1240 CLS
 1250 ENDPROC
 1260 :
 1270 DEF PROCDemoDigitalIO
 1280 LOCAL i%, av, Tmp
 1290 CLS
 1300 PRINT TAB(7,4)"There are a total of eight digital signal lines, each of which can be"
 1310 PRINT TAB(7,6)"used for input and for output.  The outputs are of the Open Collector"
 1320 PRINT TAB(7,8)"type and so can be used to switch on relays and motors etc by"
 1330 PRINT TAB(7,10)"connecting each output pin to a +ve supply at up to 50v through the"
 1340 PRINT TAB(7,12)"relay coil (etc).  The inputs are TTL (transistor-transistor logic)"
 1350 PRINT TAB(7,14)"compatible but they can also be used as outputs to drive other logic"
 1360 PRINT TAB(7,16)"and to switch on LEDs (ie Only 3 Inputs are used to sense the push"
 1370 PRINT TAB(7,18)"buttons and also to drive the 3 LEDs).  The outputs can be switched on"
 1380 PRINT TAB(7,20)"or off very quickly under program control.  They are used here to vary"
 1390 PRINT TAB(7,22)"the speed of a DC motor by Pulse Width Modulation of the supply"
 1400 PRINT TAB(7,24)"voltage across the motor.  The maximum update rate is limited by the"
 1410 PRINT TAB(7,26)"IIC bus at about 100us minimum.  The maximum load of each output is"
 1420 PRINT TAB(7,28)"200mA current sink when ON or 50V when OFF."
 1430 PROCWriteDigital (IIC_DigOut, &FF, RedLED3)
 1440 FOR i%=1 TO 50
 1450   PROCWriteDigital (IIC_DigOut, &FF, RelayOn)
 1460   PROCDelay(150/i%)
 1470   PROCWriteDigital (IIC_DigOut, &FF, RelayOn)
 1480   PROCDelay(150/i%)
 1490 NEXT i%
 1500 PROCWriteDigital (IIC_DigOut, &FF, RedTraffLED)
 1510 PROCDelay (150)
 1520 PROCWriteDigital (IIC_DigOut, &FF, AmbrTraffLED)
 1530 PROCDelay (150)
 1540 PROCWriteDigital (IIC_DigOut, &FF, RedTraffLED + AmbrTraffLED + GrnTraffLED)
 1550 PROCRunMotor(0.03) :       REM very slow
 1560 PROCRunMotor(0.1)
 1570 PROCRunMotor(0.3)
 1580 PROCRunMotor(1)
 1590 PROCRunMotor(3)
 1600 PROCRunMotor(10)
 1610 PROCRunMotor(21)
 1620 PROCRunMotor(46)
 1630 PROCRunMotor(100)    :       REM maximum speed
 1640 REM Now Light Controlled !
 1650 FOR i%=1 TO 25
 1660   av=FNReadAnalogue(IIC_ADC)
 1670   PROCRunMotor(av/2)
 1680 NEXT i%
 1690 REM Now slow down
 1700 PROCWriteDigital (IIC_DigOut, &FF, GrnTraffLED + AmbrTraffLED)
 1710 Tmp =av/2
 1720 REPEAT
 1730   Tmp=Tmp/2
 1740   PROCRunMotor(Tmp)
 1750 UNTIL (Tmp < 1)
 1760 PROCRunMotor(1)
 1770 PROCWriteDigital (IIC_DigOut, &FF, RedTraffLED + AmbrTraffLED)
 1780 PROCRunMotor(0)
 1790 CLS
 1800 ENDPROC
 1810 :
 1820 DEF PROCRunMotor(speed)
 1830 REM Pulse Width Modulation (PWM) Motor Control to speed (percentage of maximum)
 1840 LOCAL i%,j%,mark%,space%,period%
 1850 period%=3000
 1860 mark% = ABS(speed)/100*period%
 1870 space%= period% - mark%
 1880 FOR i%=1 TO 10
 1890   PROCWriteDigital (IIC_DigOut, &FF - MotorOn, 0)
 1900   FORj%=1TOmark%:        NEXTj%
 1910   PROCWriteDigital (IIC_DigOut, &FF - MotorOn, MotorOn)
 1920   FORj%=1TOspace%:        NEXTj%
 1930 NEXT i%
 1940 ENDPROC
 1950 :
 1960 DEF PROCDelay(Period%)
 1970 REM wait for Period% centiseconds
 1980 LOCAL T%
 1990 T%=TIME
 2000 WHILE ((TIME-T%) < Period%)
 2010   REM ... twiddle thumbs ...
 2020 ENDWHILE
 2030 ENDPROC
 2040 :
 2050 DEF FNReadDigital(PortAdrs%)
 2060 REM read 8 bits from specified input port
 2070 LOCAL Buf%
 2080 DIM Buf% 10
 2090 SYS"IIC_Control",PortAdrs%,Buf%,1
 2100 =?Buf%
 2110 :
 2120 DEF PROCWriteDigital (PortAdrs%, AndMask%, EorMask%)
 2130 REM change 8 bits of specified output port according to masks
 2140 REM to set a bit use AndMask% = 0, EorMask% = 1
 2150 REM to clear a bit use AndMask% = 0, EorMask% = 0
 2160 REM to toggle a bit use AndMask% = 1, EorMask% = 1
 2170 REM to ignore a bit (ie no change) use AndMask% = 1, EorMask% = 0
 2180 LOCAL Buf%
 2190 DIM Buf% 10
 2200 DigOutCopy% = (DigOutCopy% AND AndMask%) EOR EorMask%
 2210 ?Buf%=DigOutCopy%
 2220 SYS"IIC_Control",PortAdrs%,Buf%,1
 2230 ENDPROC
 2240 :
 2250 DEF FNReadAnalogue (PortAdrs%)
 2260 REM Read analogue value (range 0 - 255) from specified port
 2270 LOCAL Buf%
 2280 DIM Buf% 10
 2290 ?Buf%=IIC_ADC_Status
 2300 SYS"IIC_Control",PortAdrs%,Buf%,3
 2310 =Buf%?2
 2320 :
 2330 DEF PROCWriteAnalogue (PortAdrs%, Value%)
 2340 REM Write analogue value (range 0 - 255) to specified port
 2350 LOCAL Buf%
 2360 DIM Buf% 10
 2370 ?Buf%=IIC_ADC_Status
 2380 Buf%?1=Value%
 2390 SYS"IIC_Control",PortAdrs%,Buf%,2
 2400 ENDPROC

 � > IIC_Demo
 :
C ��=17�:      ��"Error ";:      �:      �" at line "�:      �
(D � IIC Device Bus Addresses : Odd to read from, Even to write to
2 
< IIC_DAC=&90
F IIC_ADC=&91
P IIC_DigIn=&41
Z IIC_DigOut=&40
d :
n7 � Analogue to Digital Convertor - 8591 Status bits
x IIC_ADC_Status=&40
� :
�+ � Digital i/o port 8574 Bit Allocation
�B � NB these are effectively inverting, ie 0 is ON and 1 is OFF
� RelayOn=&01
� MotorOn=&02
� RedTraffLED=&04
� AmbrTraffLED=&08
� GrnTraffLED=&10
� RedLED3=&20
� RedLED2=&40
� RedLED1=&80
� :
�C � Digital Output Port Local Copy (used by PROCWriteDigital ())
 DigOutCopy% = 0
B �WriteDigital(IIC_DigOut, 0, &FF) :       � All Off initially
 :
"% � Attach Voices for sound output
,% ș"Sound_Configure",8,208,48,0,0
6 � i%=1 � 8
@!   ș"Sound_AttachVoice",i%,1
J	 � i%
T :
^ �26,12
h �
rJ   � �10,2)"This BASIC program demonstrates the range of ODDULES from"
|L   � �10,4)"Baildon Electronics.  They are intended to provide low cost"
�K   � �10,6)"but flexible Input/Output expansion for the Archimedes and"
�I   � �10,8)"A3000 range of computers.  Here we have the AnDi Oddule,"
�I   � �10,10)"ie combined Analogue and Digital I/O.  Up to 8 of these"
�L   � �10,12)"can be connected to the computer.   Note the simplicity of"
�L   � �10,14)"each - there are only two Integrated Circuits in each AnDi"
�K   � �10,16)"Oddule - one for analogue and one for digital I/O.  There"
�G   � �10,18)"are other Oddules in development, and if you have any"
�H   � �10,20)"suggestions, then we will be pleased to hear from you."
�T   � �10,24)"Press one of the buttons on the circuit board for a demonstration:"
�F   � �17,26)"BLUE for Analogue to Digital Convertor Demonstration"
�F   � �17,28)"GREY for Digital to Analogue Convertor Demonstration"
�<   � �17,30)"RED for Digital Input/Output Demonstration"
�   � (-99) �X=�:        Ș
 
!   l%=�ReadDigital(IIC_DigIn)
   � (l% � RedLED1) = 0 �
&     �LightTosound
0
     �
:     � (l% � RedLED2) = 0 �
D       �DemoDtoA
N       �
X!       � (l% � RedLED3) = 0 �
b         �DemoDigitalIO
l         �
vD         �WriteDigital(IIC_DigOut, &FF, RedLED1+RedLED2+RedLED3)
�         �Delay (10)
�       �
�
     �
�   �
�<   �WriteDigital(IIC_DigOut, 0, &FF) :         � All Off
�   �Delay (10)
� � �
� �
� :
� � �LightTosound
�' � Light Controlled Sound Generator
� � i%,j%
� �
K � �10,4)"The potential difference across the Photo-conductive cell is"
O � �10,6)"regularly sampled.  The samples are used to control the pitch of"
M � �10,8)"the eight internal sound channels, each channel being taken in"
 K � �10,10)"rotation.  The Analogue to Digital Convertor (ADC) provides"
*G � �10,12)"8 bit resolution from each of 4 channels.  The analogue"
4F � �10,14)"inputs can be used in a variety of single-ended and/or"
>F � �10,16)"differential combinations.  The maximum sample rate is"
HJ � �10,18)"limited by the IIC Bus to about 10,000 samples per second."
RK � �10,20)"The convertor is of the multiplying type.   Analogue-ground"
\I � �10,22)"(AGnd) and the reference voltage (VRef) are accessible to"
f( � �10,24)"the user (range 0 to 5v)"
p, �WriteDigital(IIC_DigOut, &FF, RedLED1)
z � i%=1 � 20
�   � j%=1 � 8
�%     av = �ReadAnalogue (IIC_ADC)
�?     � j%,-15,av/2,50   :           � av/2 is Pitch of note
�     �Delay(1)
�   � j%
�	 � i%
� �
� �
� :
� � �DemoDtoA
�- � Demo of digital to analogue conversion
� � i%,j%,k%
� �
J � �10,8)"The output of the 8 bit Digital to Analogue Convertor (DAC)"
S � �10,10)"is static, that is the output does not require periodic refreshing."
; � �10,12)"It can easily outpace this analogue meter !"
$J � �10,14)"The rate of update of the output is limited by the IIC bus"
.- � �10,16)"to 10,000 updates per second."
8K � �10,18)"The convertor is of the multiplying type.   Analogue-ground"
BI � �10,20)"(AGnd) and the reference voltage (VRef) are accessible to"
L( � �10,22)"the user (range 0 to 5v)"
V, �WriteDigital (IIC_DigOut,&FF, RedLED2)
` � i% = 1 � 4
j   � j% = 1 � 21 � 2
t     � k% = 0 � 210 � j%
~&       �WriteAnalogue(IIC_DAC, k%)
�       �Delay (1)
�
     � k%
�     � k% = 210 � 0 � -j%
�&       �WriteAnalogue(IIC_DAC, k%)
�       �Delay (1)
�
     � k%
�   � j%
�	 � i%
� �
� �
� :
� � �DemoDigitalIO
 � i%, av, Tmp

 �
S � �7,4)"There are a total of eight digital signal lines, each of which can be"
S � �7,6)"used for input and for output.  The outputs are of the Open Collector"
(K � �7,8)"type and so can be used to switch on relays and motors etc by"
2R � �7,10)"connecting each output pin to a +ve supply at up to 50v through the"
<R � �7,12)"relay coil (etc).  The inputs are TTL (transistor-transistor logic)"
FS � �7,14)"compatible but they can also be used as outputs to drive other logic"
PQ � �7,16)"and to switch on LEDs (ie Only 3 Inputs are used to sense the push"
ZU � �7,18)"buttons and also to drive the 3 LEDs).  The outputs can be switched on"
dU � �7,20)"or off very quickly under program control.  They are used here to vary"
nN � �7,22)"the speed of a DC motor by Pulse Width Modulation of the supply"
xS � �7,24)"voltage across the motor.  The maximum update rate is limited by the"
�R � �7,26)"IIC bus at about 100us minimum.  The maximum load of each output is"
�: � �7,28)"200mA current sink when ON or 50V when OFF."
�- �WriteDigital (IIC_DigOut, &FF, RedLED3)
� � i%=1 � 50
�/   �WriteDigital (IIC_DigOut, &FF, RelayOn)
�   �Delay(150/i%)
�/   �WriteDigital (IIC_DigOut, &FF, RelayOn)
�   �Delay(150/i%)
�	 � i%
�1 �WriteDigital (IIC_DigOut, &FF, RedTraffLED)
� �Delay (150)
�2 �WriteDigital (IIC_DigOut, &FF, AmbrTraffLED)
� �Delay (150)
N �WriteDigital (IIC_DigOut, &FF, RedTraffLED + AmbrTraffLED + GrnTraffLED)
( �RunMotor(0.03) :       � very slow
 �RunMotor(0.1)
" �RunMotor(0.3)
, �RunMotor(1)
6 �RunMotor(3)
@ �RunMotor(10)
J �RunMotor(21)
T �RunMotor(46)
^. �RunMotor(100)    :       � maximum speed
h � Now Light Controlled !
r � i%=1 � 25
|    av=�ReadAnalogue(IIC_ADC)
�   �RunMotor(av/2)
�	 � i%
� � Now slow down
�@ �WriteDigital (IIC_DigOut, &FF, GrnTraffLED + AmbrTraffLED)
� Tmp =av/2
� �
�   Tmp=Tmp/2
�   �RunMotor(Tmp)
� � (Tmp < 1)
� �RunMotor(1)
�@ �WriteDigital (IIC_DigOut, &FF, RedTraffLED + AmbrTraffLED)
� �RunMotor(0)
� �
 �
 :
 � �RunMotor(speed)
&R � Pulse Width Modulation (PWM) Motor Control to speed (percentage of maximum)
0! � i%,j%,mark%,space%,period%
: period%=3000
D! mark% = �(speed)/100*period%
N space%= period% - mark%
X � i%=1 � 10
b3   �WriteDigital (IIC_DigOut, &FF - MotorOn, 0)
l   �j%=1�mark%:        �j%
v9   �WriteDigital (IIC_DigOut, &FF - MotorOn, MotorOn)
�   �j%=1�space%:        �j%
�	 � i%
� �
� :
� � �Delay(Period%)
�$ � wait for Period% centiseconds
�	 � T%
�	 T%=�
� ȕ ((�-T%) < Period%)
�   � ... twiddle thumbs ...
� �
� �
� :
 � �ReadDigital(PortAdrs%)
, � read 8 bits from specified input port
 � Buf%
  � Buf% 10
*% ș"IIC_Control",PortAdrs%,Buf%,1
4 =?Buf%
> :
H4 � �WriteDigital (PortAdrs%, AndMask%, EorMask%)
R@ � change 8 bits of specified output port according to masks
\2 � to set a bit use AndMask% = 0, EorMask% = 1
f4 � to clear a bit use AndMask% = 0, EorMask% = 0
p5 � to toggle a bit use AndMask% = 1, EorMask% = 1
zD � to ignore a bit (ie no change) use AndMask% = 1, EorMask% = 0
� � Buf%
� � Buf% 10
�6 DigOutCopy% = (DigOutCopy% � AndMask%) � EorMask%
� ?Buf%=DigOutCopy%
�% ș"IIC_Control",PortAdrs%,Buf%,1
� �
� :
�  � �ReadAnalogue (PortAdrs%)
�> � Read analogue value (range 0 - 255) from specified port
� � Buf%
� � Buf% 10
� ?Buf%=IIC_ADC_Status
�% ș"IIC_Control",PortAdrs%,Buf%,3
	 =Buf%?2
	 :
	) � �WriteAnalogue (PortAdrs%, Value%)
	$= � Write analogue value (range 0 - 255) to specified port
	. � Buf%
	8 � Buf% 10
	B ?Buf%=IIC_ADC_Status
	L Buf%?1=Value%
	V% ș"IIC_Control",PortAdrs%,Buf%,2
	` �
�
00000000  0d 00 0a 11 20 f4 20 3e  20 49 49 43 5f 44 65 6d  |.... . > IIC_Dem|
00000010  6f 0d 00 14 06 20 3a 0d  00 1e 43 20 ee 85 e7 9f  |o.... :...C ....|
00000020  3d 31 37 f9 3a 20 20 20  20 20 20 8b f1 22 45 72  |=17.:      .."Er|
00000030  72 6f 72 20 22 3b 3a 20  20 20 20 20 20 f6 3a 20  |ror ";:      .: |
00000040  20 20 20 20 20 f1 22 20  61 74 20 6c 69 6e 65 20  |     ." at line |
00000050  22 9e 3a 20 20 20 20 20  20 e0 0d 00 28 44 20 f4  |".:      ...(D .|
00000060  20 49 49 43 20 44 65 76  69 63 65 20 42 75 73 20  | IIC Device Bus |
00000070  41 64 64 72 65 73 73 65  73 20 3a 20 4f 64 64 20  |Addresses : Odd |
00000080  74 6f 20 72 65 61 64 20  66 72 6f 6d 2c 20 45 76  |to read from, Ev|
00000090  65 6e 20 74 6f 20 77 72  69 74 65 20 74 6f 0d 00  |en to write to..|
000000a0  32 05 20 0d 00 3c 10 20  49 49 43 5f 44 41 43 3d  |2. ..<. IIC_DAC=|
000000b0  26 39 30 0d 00 46 10 20  49 49 43 5f 41 44 43 3d  |&90..F. IIC_ADC=|
000000c0  26 39 31 0d 00 50 12 20  49 49 43 5f 44 69 67 49  |&91..P. IIC_DigI|
000000d0  6e 3d 26 34 31 0d 00 5a  13 20 49 49 43 5f 44 69  |n=&41..Z. IIC_Di|
000000e0  67 4f 75 74 3d 26 34 30  0d 00 64 06 20 3a 0d 00  |gOut=&40..d. :..|
000000f0  6e 37 20 f4 20 41 6e 61  6c 6f 67 75 65 20 74 6f  |n7 . Analogue to|
00000100  20 44 69 67 69 74 61 6c  20 43 6f 6e 76 65 72 74  | Digital Convert|
00000110  6f 72 20 2d 20 38 35 39  31 20 53 74 61 74 75 73  |or - 8591 Status|
00000120  20 62 69 74 73 0d 00 78  17 20 49 49 43 5f 41 44  | bits..x. IIC_AD|
00000130  43 5f 53 74 61 74 75 73  3d 26 34 30 0d 00 82 06  |C_Status=&40....|
00000140  20 3a 0d 00 8c 2b 20 f4  20 44 69 67 69 74 61 6c  | :...+ . Digital|
00000150  20 69 2f 6f 20 70 6f 72  74 20 38 35 37 34 20 42  | i/o port 8574 B|
00000160  69 74 20 41 6c 6c 6f 63  61 74 69 6f 6e 0d 00 96  |it Allocation...|
00000170  42 20 f4 20 4e 42 20 74  68 65 73 65 20 61 72 65  |B . NB these are|
00000180  20 65 66 66 65 63 74 69  76 65 6c 79 20 69 6e 76  | effectively inv|
00000190  65 72 74 69 6e 67 2c 20  69 65 20 30 20 69 73 20  |erting, ie 0 is |
000001a0  4f 4e 20 61 6e 64 20 31  20 69 73 20 4f 46 46 0d  |ON and 1 is OFF.|
000001b0  00 a0 10 20 52 65 6c 61  79 4f 6e 3d 26 30 31 0d  |... RelayOn=&01.|
000001c0  00 aa 10 20 4d 6f 74 6f  72 4f 6e 3d 26 30 32 0d  |... MotorOn=&02.|
000001d0  00 b4 14 20 52 65 64 54  72 61 66 66 4c 45 44 3d  |... RedTraffLED=|
000001e0  26 30 34 0d 00 be 15 20  41 6d 62 72 54 72 61 66  |&04.... AmbrTraf|
000001f0  66 4c 45 44 3d 26 30 38  0d 00 c8 14 20 47 72 6e  |fLED=&08.... Grn|
00000200  54 72 61 66 66 4c 45 44  3d 26 31 30 0d 00 d2 10  |TraffLED=&10....|
00000210  20 52 65 64 4c 45 44 33  3d 26 32 30 0d 00 dc 10  | RedLED3=&20....|
00000220  20 52 65 64 4c 45 44 32  3d 26 34 30 0d 00 e6 10  | RedLED2=&40....|
00000230  20 52 65 64 4c 45 44 31  3d 26 38 30 0d 00 f0 06  | RedLED1=&80....|
00000240  20 3a 0d 00 fa 43 20 f4  20 44 69 67 69 74 61 6c  | :...C . Digital|
00000250  20 4f 75 74 70 75 74 20  50 6f 72 74 20 4c 6f 63  | Output Port Loc|
00000260  61 6c 20 43 6f 70 79 20  28 75 73 65 64 20 62 79  |al Copy (used by|
00000270  20 50 52 4f 43 57 72 69  74 65 44 69 67 69 74 61  | PROCWriteDigita|
00000280  6c 20 28 29 29 0d 01 04  14 20 44 69 67 4f 75 74  |l ()).... DigOut|
00000290  43 6f 70 79 25 20 3d 20  30 0d 01 0e 42 20 f2 57  |Copy% = 0...B .W|
000002a0  72 69 74 65 44 69 67 69  74 61 6c 28 49 49 43 5f  |riteDigital(IIC_|
000002b0  44 69 67 4f 75 74 2c 20  30 2c 20 26 46 46 29 20  |DigOut, 0, &FF) |
000002c0  3a 20 20 20 20 20 20 20  f4 20 41 6c 6c 20 4f 66  |:       . All Of|
000002d0  66 20 69 6e 69 74 69 61  6c 6c 79 0d 01 18 06 20  |f initially.... |
000002e0  3a 0d 01 22 25 20 f4 20  41 74 74 61 63 68 20 56  |:.."% . Attach V|
000002f0  6f 69 63 65 73 20 66 6f  72 20 73 6f 75 6e 64 20  |oices for sound |
00000300  6f 75 74 70 75 74 0d 01  2c 25 20 c8 99 22 53 6f  |output..,% .."So|
00000310  75 6e 64 5f 43 6f 6e 66  69 67 75 72 65 22 2c 38  |und_Configure",8|
00000320  2c 32 30 38 2c 34 38 2c  30 2c 30 0d 01 36 0f 20  |,208,48,0,0..6. |
00000330  e3 20 69 25 3d 31 20 b8  20 38 0d 01 40 21 20 20  |. i%=1 . 8..@!  |
00000340  20 c8 99 22 53 6f 75 6e  64 5f 41 74 74 61 63 68  | .."Sound_Attach|
00000350  56 6f 69 63 65 22 2c 69  25 2c 31 0d 01 4a 09 20  |Voice",i%,1..J. |
00000360  ed 20 69 25 0d 01 54 06  20 3a 0d 01 5e 0b 20 ef  |. i%..T. :..^. .|
00000370  32 36 2c 31 32 0d 01 68  06 20 f5 0d 01 72 4a 20  |26,12..h. ...rJ |
00000380  20 20 f1 20 8a 31 30 2c  32 29 22 54 68 69 73 20  |  . .10,2)"This |
00000390  42 41 53 49 43 20 70 72  6f 67 72 61 6d 20 64 65  |BASIC program de|
000003a0  6d 6f 6e 73 74 72 61 74  65 73 20 74 68 65 20 72  |monstrates the r|
000003b0  61 6e 67 65 20 6f 66 20  4f 44 44 55 4c 45 53 20  |ange of ODDULES |
000003c0  66 72 6f 6d 22 0d 01 7c  4c 20 20 20 f1 20 8a 31  |from"..|L   . .1|
000003d0  30 2c 34 29 22 42 61 69  6c 64 6f 6e 20 45 6c 65  |0,4)"Baildon Ele|
000003e0  63 74 72 6f 6e 69 63 73  2e 20 20 54 68 65 79 20  |ctronics.  They |
000003f0  61 72 65 20 69 6e 74 65  6e 64 65 64 20 74 6f 20  |are intended to |
00000400  70 72 6f 76 69 64 65 20  6c 6f 77 20 63 6f 73 74  |provide low cost|
00000410  22 0d 01 86 4b 20 20 20  f1 20 8a 31 30 2c 36 29  |"...K   . .10,6)|
00000420  22 62 75 74 20 66 6c 65  78 69 62 6c 65 20 49 6e  |"but flexible In|
00000430  70 75 74 2f 4f 75 74 70  75 74 20 65 78 70 61 6e  |put/Output expan|
00000440  73 69 6f 6e 20 66 6f 72  20 74 68 65 20 41 72 63  |sion for the Arc|
00000450  68 69 6d 65 64 65 73 20  61 6e 64 22 0d 01 90 49  |himedes and"...I|
00000460  20 20 20 f1 20 8a 31 30  2c 38 29 22 41 33 30 30  |   . .10,8)"A300|
00000470  30 20 72 61 6e 67 65 20  6f 66 20 63 6f 6d 70 75  |0 range of compu|
00000480  74 65 72 73 2e 20 20 48  65 72 65 20 77 65 20 68  |ters.  Here we h|
00000490  61 76 65 20 74 68 65 20  41 6e 44 69 20 4f 64 64  |ave the AnDi Odd|
000004a0  75 6c 65 2c 22 0d 01 9a  49 20 20 20 f1 20 8a 31  |ule,"...I   . .1|
000004b0  30 2c 31 30 29 22 69 65  20 63 6f 6d 62 69 6e 65  |0,10)"ie combine|
000004c0  64 20 41 6e 61 6c 6f 67  75 65 20 61 6e 64 20 44  |d Analogue and D|
000004d0  69 67 69 74 61 6c 20 49  2f 4f 2e 20 20 55 70 20  |igital I/O.  Up |
000004e0  74 6f 20 38 20 6f 66 20  74 68 65 73 65 22 0d 01  |to 8 of these"..|
000004f0  a4 4c 20 20 20 f1 20 8a  31 30 2c 31 32 29 22 63  |.L   . .10,12)"c|
00000500  61 6e 20 62 65 20 63 6f  6e 6e 65 63 74 65 64 20  |an be connected |
00000510  74 6f 20 74 68 65 20 63  6f 6d 70 75 74 65 72 2e  |to the computer.|
00000520  20 20 20 4e 6f 74 65 20  74 68 65 20 73 69 6d 70  |   Note the simp|
00000530  6c 69 63 69 74 79 20 6f  66 22 0d 01 ae 4c 20 20  |licity of"...L  |
00000540  20 f1 20 8a 31 30 2c 31  34 29 22 65 61 63 68 20  | . .10,14)"each |
00000550  2d 20 74 68 65 72 65 20  61 72 65 20 6f 6e 6c 79  |- there are only|
00000560  20 74 77 6f 20 49 6e 74  65 67 72 61 74 65 64 20  | two Integrated |
00000570  43 69 72 63 75 69 74 73  20 69 6e 20 65 61 63 68  |Circuits in each|
00000580  20 41 6e 44 69 22 0d 01  b8 4b 20 20 20 f1 20 8a  | AnDi"...K   . .|
00000590  31 30 2c 31 36 29 22 4f  64 64 75 6c 65 20 2d 20  |10,16)"Oddule - |
000005a0  6f 6e 65 20 66 6f 72 20  61 6e 61 6c 6f 67 75 65  |one for analogue|
000005b0  20 61 6e 64 20 6f 6e 65  20 66 6f 72 20 64 69 67  | and one for dig|
000005c0  69 74 61 6c 20 49 2f 4f  2e 20 20 54 68 65 72 65  |ital I/O.  There|
000005d0  22 0d 01 c2 47 20 20 20  f1 20 8a 31 30 2c 31 38  |"...G   . .10,18|
000005e0  29 22 61 72 65 20 6f 74  68 65 72 20 4f 64 64 75  |)"are other Oddu|
000005f0  6c 65 73 20 69 6e 20 64  65 76 65 6c 6f 70 6d 65  |les in developme|
00000600  6e 74 2c 20 61 6e 64 20  69 66 20 79 6f 75 20 68  |nt, and if you h|
00000610  61 76 65 20 61 6e 79 22  0d 01 cc 48 20 20 20 f1  |ave any"...H   .|
00000620  20 8a 31 30 2c 32 30 29  22 73 75 67 67 65 73 74  | .10,20)"suggest|
00000630  69 6f 6e 73 2c 20 74 68  65 6e 20 77 65 20 77 69  |ions, then we wi|
00000640  6c 6c 20 62 65 20 70 6c  65 61 73 65 64 20 74 6f  |ll be pleased to|
00000650  20 68 65 61 72 20 66 72  6f 6d 20 79 6f 75 2e 22  | hear from you."|
00000660  0d 01 d6 54 20 20 20 f1  20 8a 31 30 2c 32 34 29  |...T   . .10,24)|
00000670  22 50 72 65 73 73 20 6f  6e 65 20 6f 66 20 74 68  |"Press one of th|
00000680  65 20 62 75 74 74 6f 6e  73 20 6f 6e 20 74 68 65  |e buttons on the|
00000690  20 63 69 72 63 75 69 74  20 62 6f 61 72 64 20 66  | circuit board f|
000006a0  6f 72 20 61 20 64 65 6d  6f 6e 73 74 72 61 74 69  |or a demonstrati|
000006b0  6f 6e 3a 22 0d 01 e0 46  20 20 20 f1 20 8a 31 37  |on:"...F   . .17|
000006c0  2c 32 36 29 22 42 4c 55  45 20 66 6f 72 20 41 6e  |,26)"BLUE for An|
000006d0  61 6c 6f 67 75 65 20 74  6f 20 44 69 67 69 74 61  |alogue to Digita|
000006e0  6c 20 43 6f 6e 76 65 72  74 6f 72 20 44 65 6d 6f  |l Convertor Demo|
000006f0  6e 73 74 72 61 74 69 6f  6e 22 0d 01 ea 46 20 20  |nstration"...F  |
00000700  20 f1 20 8a 31 37 2c 32  38 29 22 47 52 45 59 20  | . .17,28)"GREY |
00000710  66 6f 72 20 44 69 67 69  74 61 6c 20 74 6f 20 41  |for Digital to A|
00000720  6e 61 6c 6f 67 75 65 20  43 6f 6e 76 65 72 74 6f  |nalogue Converto|
00000730  72 20 44 65 6d 6f 6e 73  74 72 61 74 69 6f 6e 22  |r Demonstration"|
00000740  0d 01 f4 3c 20 20 20 f1  20 8a 31 37 2c 33 30 29  |...<   . .17,30)|
00000750  22 52 45 44 20 66 6f 72  20 44 69 67 69 74 61 6c  |"RED for Digital|
00000760  20 49 6e 70 75 74 2f 4f  75 74 70 75 74 20 44 65  | Input/Output De|
00000770  6d 6f 6e 73 74 72 61 74  69 6f 6e 22 0d 01 fe 1f  |monstration"....|
00000780  20 20 20 e7 a6 20 28 2d  39 39 29 20 8c 58 3d a5  |   .. (-99) .X=.|
00000790  3a 20 20 20 20 20 20 20  20 c8 98 0d 02 08 05 20  |:        ...... |
000007a0  0d 02 12 21 20 20 20 6c  25 3d a4 52 65 61 64 44  |...!   l%=.ReadD|
000007b0  69 67 69 74 61 6c 28 49  49 43 5f 44 69 67 49 6e  |igital(IIC_DigIn|
000007c0  29 0d 02 1c 1d 20 20 20  e7 20 28 6c 25 20 80 20  |)....   . (l% . |
000007d0  52 65 64 4c 45 44 31 29  20 3d 20 30 20 8c 0d 02  |RedLED1) = 0 ...|
000007e0  26 16 20 20 20 20 20 f2  4c 69 67 68 74 54 6f 73  |&.     .LightTos|
000007f0  6f 75 6e 64 0d 02 30 0a  20 20 20 20 20 cc 0d 02  |ound..0.     ...|
00000800  3a 1f 20 20 20 20 20 e7  20 28 6c 25 20 80 20 52  |:.     . (l% . R|
00000810  65 64 4c 45 44 32 29 20  3d 20 30 20 8c 0d 02 44  |edLED2) = 0 ...D|
00000820  14 20 20 20 20 20 20 20  f2 44 65 6d 6f 44 74 6f  |.       .DemoDto|
00000830  41 0d 02 4e 0c 20 20 20  20 20 20 20 cc 0d 02 58  |A..N.       ...X|
00000840  21 20 20 20 20 20 20 20  e7 20 28 6c 25 20 80 20  |!       . (l% . |
00000850  52 65 64 4c 45 44 33 29  20 3d 20 30 20 8c 0d 02  |RedLED3) = 0 ...|
00000860  62 1b 20 20 20 20 20 20  20 20 20 f2 44 65 6d 6f  |b.         .Demo|
00000870  44 69 67 69 74 61 6c 49  4f 0d 02 6c 0e 20 20 20  |DigitalIO..l.   |
00000880  20 20 20 20 20 20 cc 0d  02 76 44 20 20 20 20 20  |      ...vD     |
00000890  20 20 20 20 f2 57 72 69  74 65 44 69 67 69 74 61  |    .WriteDigita|
000008a0  6c 28 49 49 43 5f 44 69  67 4f 75 74 2c 20 26 46  |l(IIC_DigOut, &F|
000008b0  46 2c 20 52 65 64 4c 45  44 31 2b 52 65 64 4c 45  |F, RedLED1+RedLE|
000008c0  44 32 2b 52 65 64 4c 45  44 33 29 0d 02 80 18 20  |D2+RedLED3).... |
000008d0  20 20 20 20 20 20 20 20  f2 44 65 6c 61 79 20 28  |        .Delay (|
000008e0  31 30 29 0d 02 8a 0c 20  20 20 20 20 20 20 cd 0d  |10)....       ..|
000008f0  02 94 0a 20 20 20 20 20  cd 0d 02 9e 08 20 20 20  |...     .....   |
00000900  cd 0d 02 a8 3c 20 20 20  f2 57 72 69 74 65 44 69  |....<   .WriteDi|
00000910  67 69 74 61 6c 28 49 49  43 5f 44 69 67 4f 75 74  |gital(IIC_DigOut|
00000920  2c 20 30 2c 20 26 46 46  29 20 3a 20 20 20 20 20  |, 0, &FF) :     |
00000930  20 20 20 20 f4 20 41 6c  6c 20 4f 66 66 0d 02 b2  |    . All Off...|
00000940  12 20 20 20 f2 44 65 6c  61 79 20 28 31 30 29 0d  |.   .Delay (10).|
00000950  02 bc 08 20 fd 20 a3 0d  02 c6 06 20 e0 0d 02 d0  |... . ..... ....|
00000960  06 20 3a 0d 02 da 14 20  dd 20 f2 4c 69 67 68 74  |. :.... . .Light|
00000970  54 6f 73 6f 75 6e 64 0d  02 e4 27 20 f4 20 4c 69  |Tosound...' . Li|
00000980  67 68 74 20 43 6f 6e 74  72 6f 6c 6c 65 64 20 53  |ght Controlled S|
00000990  6f 75 6e 64 20 47 65 6e  65 72 61 74 6f 72 0d 02  |ound Generator..|
000009a0  ee 0c 20 ea 20 69 25 2c  6a 25 0d 02 f8 06 20 db  |.. . i%,j%.... .|
000009b0  0d 03 02 4b 20 f1 20 8a  31 30 2c 34 29 22 54 68  |...K . .10,4)"Th|
000009c0  65 20 70 6f 74 65 6e 74  69 61 6c 20 64 69 66 66  |e potential diff|
000009d0  65 72 65 6e 63 65 20 61  63 72 6f 73 73 20 74 68  |erence across th|
000009e0  65 20 50 68 6f 74 6f 2d  63 6f 6e 64 75 63 74 69  |e Photo-conducti|
000009f0  76 65 20 63 65 6c 6c 20  69 73 22 0d 03 0c 4f 20  |ve cell is"...O |
00000a00  f1 20 8a 31 30 2c 36 29  22 72 65 67 75 6c 61 72  |. .10,6)"regular|
00000a10  6c 79 20 73 61 6d 70 6c  65 64 2e 20 20 54 68 65  |ly sampled.  The|
00000a20  20 73 61 6d 70 6c 65 73  20 61 72 65 20 75 73 65  | samples are use|
00000a30  64 20 74 6f 20 63 6f 6e  74 72 6f 6c 20 74 68 65  |d to control the|
00000a40  20 70 69 74 63 68 20 6f  66 22 0d 03 16 4d 20 f1  | pitch of"...M .|
00000a50  20 8a 31 30 2c 38 29 22  74 68 65 20 65 69 67 68  | .10,8)"the eigh|
00000a60  74 20 69 6e 74 65 72 6e  61 6c 20 73 6f 75 6e 64  |t internal sound|
00000a70  20 63 68 61 6e 6e 65 6c  73 2c 20 65 61 63 68 20  | channels, each |
00000a80  63 68 61 6e 6e 65 6c 20  62 65 69 6e 67 20 74 61  |channel being ta|
00000a90  6b 65 6e 20 69 6e 22 0d  03 20 4b 20 f1 20 8a 31  |ken in".. K . .1|
00000aa0  30 2c 31 30 29 22 72 6f  74 61 74 69 6f 6e 2e 20  |0,10)"rotation. |
00000ab0  20 54 68 65 20 41 6e 61  6c 6f 67 75 65 20 74 6f  | The Analogue to|
00000ac0  20 44 69 67 69 74 61 6c  20 43 6f 6e 76 65 72 74  | Digital Convert|
00000ad0  6f 72 20 28 41 44 43 29  20 70 72 6f 76 69 64 65  |or (ADC) provide|
00000ae0  73 22 0d 03 2a 47 20 f1  20 8a 31 30 2c 31 32 29  |s"..*G . .10,12)|
00000af0  22 38 20 62 69 74 20 72  65 73 6f 6c 75 74 69 6f  |"8 bit resolutio|
00000b00  6e 20 66 72 6f 6d 20 65  61 63 68 20 6f 66 20 34  |n from each of 4|
00000b10  20 63 68 61 6e 6e 65 6c  73 2e 20 20 54 68 65 20  | channels.  The |
00000b20  61 6e 61 6c 6f 67 75 65  22 0d 03 34 46 20 f1 20  |analogue"..4F . |
00000b30  8a 31 30 2c 31 34 29 22  69 6e 70 75 74 73 20 63  |.10,14)"inputs c|
00000b40  61 6e 20 62 65 20 75 73  65 64 20 69 6e 20 61 20  |an be used in a |
00000b50  76 61 72 69 65 74 79 20  6f 66 20 73 69 6e 67 6c  |variety of singl|
00000b60  65 2d 65 6e 64 65 64 20  61 6e 64 2f 6f 72 22 0d  |e-ended and/or".|
00000b70  03 3e 46 20 f1 20 8a 31  30 2c 31 36 29 22 64 69  |.>F . .10,16)"di|
00000b80  66 66 65 72 65 6e 74 69  61 6c 20 63 6f 6d 62 69  |fferential combi|
00000b90  6e 61 74 69 6f 6e 73 2e  20 20 54 68 65 20 6d 61  |nations.  The ma|
00000ba0  78 69 6d 75 6d 20 73 61  6d 70 6c 65 20 72 61 74  |ximum sample rat|
00000bb0  65 20 69 73 22 0d 03 48  4a 20 f1 20 8a 31 30 2c  |e is"..HJ . .10,|
00000bc0  31 38 29 22 6c 69 6d 69  74 65 64 20 62 79 20 74  |18)"limited by t|
00000bd0  68 65 20 49 49 43 20 42  75 73 20 74 6f 20 61 62  |he IIC Bus to ab|
00000be0  6f 75 74 20 31 30 2c 30  30 30 20 73 61 6d 70 6c  |out 10,000 sampl|
00000bf0  65 73 20 70 65 72 20 73  65 63 6f 6e 64 2e 22 0d  |es per second.".|
00000c00  03 52 4b 20 f1 20 8a 31  30 2c 32 30 29 22 54 68  |.RK . .10,20)"Th|
00000c10  65 20 63 6f 6e 76 65 72  74 6f 72 20 69 73 20 6f  |e convertor is o|
00000c20  66 20 74 68 65 20 6d 75  6c 74 69 70 6c 79 69 6e  |f the multiplyin|
00000c30  67 20 74 79 70 65 2e 20  20 20 41 6e 61 6c 6f 67  |g type.   Analog|
00000c40  75 65 2d 67 72 6f 75 6e  64 22 0d 03 5c 49 20 f1  |ue-ground"..\I .|
00000c50  20 8a 31 30 2c 32 32 29  22 28 41 47 6e 64 29 20  | .10,22)"(AGnd) |
00000c60  61 6e 64 20 74 68 65 20  72 65 66 65 72 65 6e 63  |and the referenc|
00000c70  65 20 76 6f 6c 74 61 67  65 20 28 56 52 65 66 29  |e voltage (VRef)|
00000c80  20 61 72 65 20 61 63 63  65 73 73 69 62 6c 65 20  | are accessible |
00000c90  74 6f 22 0d 03 66 28 20  f1 20 8a 31 30 2c 32 34  |to"..f( . .10,24|
00000ca0  29 22 74 68 65 20 75 73  65 72 20 28 72 61 6e 67  |)"the user (rang|
00000cb0  65 20 30 20 74 6f 20 35  76 29 22 0d 03 70 2c 20  |e 0 to 5v)"..p, |
00000cc0  f2 57 72 69 74 65 44 69  67 69 74 61 6c 28 49 49  |.WriteDigital(II|
00000cd0  43 5f 44 69 67 4f 75 74  2c 20 26 46 46 2c 20 52  |C_DigOut, &FF, R|
00000ce0  65 64 4c 45 44 31 29 0d  03 7a 10 20 e3 20 69 25  |edLED1)..z. . i%|
00000cf0  3d 31 20 b8 20 32 30 0d  03 84 11 20 20 20 e3 20  |=1 . 20....   . |
00000d00  6a 25 3d 31 20 b8 20 38  0d 03 8e 25 20 20 20 20  |j%=1 . 8...%    |
00000d10  20 61 76 20 3d 20 a4 52  65 61 64 41 6e 61 6c 6f  | av = .ReadAnalo|
00000d20  67 75 65 20 28 49 49 43  5f 41 44 43 29 0d 03 98  |gue (IIC_ADC)...|
00000d30  3f 20 20 20 20 20 d4 20  6a 25 2c 2d 31 35 2c 61  |?     . j%,-15,a|
00000d40  76 2f 32 2c 35 30 20 20  20 3a 20 20 20 20 20 20  |v/2,50   :      |
00000d50  20 20 20 20 20 f4 20 61  76 2f 32 20 69 73 20 50  |     . av/2 is P|
00000d60  69 74 63 68 20 6f 66 20  6e 6f 74 65 0d 03 a2 12  |itch of note....|
00000d70  20 20 20 20 20 f2 44 65  6c 61 79 28 31 29 0d 03  |     .Delay(1)..|
00000d80  ac 0b 20 20 20 ed 20 6a  25 0d 03 b6 09 20 ed 20  |..   . j%.... . |
00000d90  69 25 0d 03 c0 06 20 db  0d 03 ca 06 20 e1 0d 03  |i%.... ..... ...|
00000da0  d4 06 20 3a 0d 03 de 10  20 dd 20 f2 44 65 6d 6f  |.. :.... . .Demo|
00000db0  44 74 6f 41 0d 03 e8 2d  20 f4 20 44 65 6d 6f 20  |DtoA...- . Demo |
00000dc0  6f 66 20 64 69 67 69 74  61 6c 20 74 6f 20 61 6e  |of digital to an|
00000dd0  61 6c 6f 67 75 65 20 63  6f 6e 76 65 72 73 69 6f  |alogue conversio|
00000de0  6e 0d 03 f2 0f 20 ea 20  69 25 2c 6a 25 2c 6b 25  |n.... . i%,j%,k%|
00000df0  0d 03 fc 06 20 db 0d 04  06 4a 20 f1 20 8a 31 30  |.... ....J . .10|
00000e00  2c 38 29 22 54 68 65 20  6f 75 74 70 75 74 20 6f  |,8)"The output o|
00000e10  66 20 74 68 65 20 38 20  62 69 74 20 44 69 67 69  |f the 8 bit Digi|
00000e20  74 61 6c 20 74 6f 20 41  6e 61 6c 6f 67 75 65 20  |tal to Analogue |
00000e30  43 6f 6e 76 65 72 74 6f  72 20 28 44 41 43 29 22  |Convertor (DAC)"|
00000e40  0d 04 10 53 20 f1 20 8a  31 30 2c 31 30 29 22 69  |...S . .10,10)"i|
00000e50  73 20 73 74 61 74 69 63  2c 20 74 68 61 74 20 69  |s static, that i|
00000e60  73 20 74 68 65 20 6f 75  74 70 75 74 20 64 6f 65  |s the output doe|
00000e70  73 20 6e 6f 74 20 72 65  71 75 69 72 65 20 70 65  |s not require pe|
00000e80  72 69 6f 64 69 63 20 72  65 66 72 65 73 68 69 6e  |riodic refreshin|
00000e90  67 2e 22 0d 04 1a 3b 20  f1 20 8a 31 30 2c 31 32  |g."...; . .10,12|
00000ea0  29 22 49 74 20 63 61 6e  20 65 61 73 69 6c 79 20  |)"It can easily |
00000eb0  6f 75 74 70 61 63 65 20  74 68 69 73 20 61 6e 61  |outpace this ana|
00000ec0  6c 6f 67 75 65 20 6d 65  74 65 72 20 21 22 0d 04  |logue meter !"..|
00000ed0  24 4a 20 f1 20 8a 31 30  2c 31 34 29 22 54 68 65  |$J . .10,14)"The|
00000ee0  20 72 61 74 65 20 6f 66  20 75 70 64 61 74 65 20  | rate of update |
00000ef0  6f 66 20 74 68 65 20 6f  75 74 70 75 74 20 69 73  |of the output is|
00000f00  20 6c 69 6d 69 74 65 64  20 62 79 20 74 68 65 20  | limited by the |
00000f10  49 49 43 20 62 75 73 22  0d 04 2e 2d 20 f1 20 8a  |IIC bus"...- . .|
00000f20  31 30 2c 31 36 29 22 74  6f 20 31 30 2c 30 30 30  |10,16)"to 10,000|
00000f30  20 75 70 64 61 74 65 73  20 70 65 72 20 73 65 63  | updates per sec|
00000f40  6f 6e 64 2e 22 0d 04 38  4b 20 f1 20 8a 31 30 2c  |ond."..8K . .10,|
00000f50  31 38 29 22 54 68 65 20  63 6f 6e 76 65 72 74 6f  |18)"The converto|
00000f60  72 20 69 73 20 6f 66 20  74 68 65 20 6d 75 6c 74  |r is of the mult|
00000f70  69 70 6c 79 69 6e 67 20  74 79 70 65 2e 20 20 20  |iplying type.   |
00000f80  41 6e 61 6c 6f 67 75 65  2d 67 72 6f 75 6e 64 22  |Analogue-ground"|
00000f90  0d 04 42 49 20 f1 20 8a  31 30 2c 32 30 29 22 28  |..BI . .10,20)"(|
00000fa0  41 47 6e 64 29 20 61 6e  64 20 74 68 65 20 72 65  |AGnd) and the re|
00000fb0  66 65 72 65 6e 63 65 20  76 6f 6c 74 61 67 65 20  |ference voltage |
00000fc0  28 56 52 65 66 29 20 61  72 65 20 61 63 63 65 73  |(VRef) are acces|
00000fd0  73 69 62 6c 65 20 74 6f  22 0d 04 4c 28 20 f1 20  |sible to"..L( . |
00000fe0  8a 31 30 2c 32 32 29 22  74 68 65 20 75 73 65 72  |.10,22)"the user|
00000ff0  20 28 72 61 6e 67 65 20  30 20 74 6f 20 35 76 29  | (range 0 to 5v)|
00001000  22 0d 04 56 2c 20 f2 57  72 69 74 65 44 69 67 69  |"..V, .WriteDigi|
00001010  74 61 6c 20 28 49 49 43  5f 44 69 67 4f 75 74 2c  |tal (IIC_DigOut,|
00001020  26 46 46 2c 20 52 65 64  4c 45 44 32 29 0d 04 60  |&FF, RedLED2)..`|
00001030  11 20 e3 20 69 25 20 3d  20 31 20 b8 20 34 0d 04  |. . i% = 1 . 4..|
00001040  6a 18 20 20 20 e3 20 6a  25 20 3d 20 31 20 b8 20  |j.   . j% = 1 . |
00001050  32 31 20 88 20 32 0d 04  74 1c 20 20 20 20 20 e3  |21 . 2..t.     .|
00001060  20 6b 25 20 3d 20 30 20  b8 20 32 31 30 20 88 20  | k% = 0 . 210 . |
00001070  6a 25 0d 04 7e 26 20 20  20 20 20 20 20 f2 57 72  |j%..~&       .Wr|
00001080  69 74 65 41 6e 61 6c 6f  67 75 65 28 49 49 43 5f  |iteAnalogue(IIC_|
00001090  44 41 43 2c 20 6b 25 29  0d 04 88 15 20 20 20 20  |DAC, k%)....    |
000010a0  20 20 20 f2 44 65 6c 61  79 20 28 31 29 0d 04 92  |   .Delay (1)...|
000010b0  0d 20 20 20 20 20 ed 20  6b 25 0d 04 9c 1d 20 20  |.     . k%....  |
000010c0  20 20 20 e3 20 6b 25 20  3d 20 32 31 30 20 b8 20  |   . k% = 210 . |
000010d0  30 20 88 20 2d 6a 25 0d  04 a6 26 20 20 20 20 20  |0 . -j%...&     |
000010e0  20 20 f2 57 72 69 74 65  41 6e 61 6c 6f 67 75 65  |  .WriteAnalogue|
000010f0  28 49 49 43 5f 44 41 43  2c 20 6b 25 29 0d 04 b0  |(IIC_DAC, k%)...|
00001100  15 20 20 20 20 20 20 20  f2 44 65 6c 61 79 20 28  |.       .Delay (|
00001110  31 29 0d 04 ba 0d 20 20  20 20 20 ed 20 6b 25 0d  |1)....     . k%.|
00001120  04 c4 0b 20 20 20 ed 20  6a 25 0d 04 ce 09 20 ed  |...   . j%.... .|
00001130  20 69 25 0d 04 d8 06 20  db 0d 04 e2 06 20 e1 0d  | i%.... ..... ..|
00001140  04 ec 06 20 3a 0d 04 f6  15 20 dd 20 f2 44 65 6d  |... :.... . .Dem|
00001150  6f 44 69 67 69 74 61 6c  49 4f 0d 05 00 12 20 ea  |oDigitalIO.... .|
00001160  20 69 25 2c 20 61 76 2c  20 54 6d 70 0d 05 0a 06  | i%, av, Tmp....|
00001170  20 db 0d 05 14 53 20 f1  20 8a 37 2c 34 29 22 54  | ....S . .7,4)"T|
00001180  68 65 72 65 20 61 72 65  20 61 20 74 6f 74 61 6c  |here are a total|
00001190  20 6f 66 20 65 69 67 68  74 20 64 69 67 69 74 61  | of eight digita|
000011a0  6c 20 73 69 67 6e 61 6c  20 6c 69 6e 65 73 2c 20  |l signal lines, |
000011b0  65 61 63 68 20 6f 66 20  77 68 69 63 68 20 63 61  |each of which ca|
000011c0  6e 20 62 65 22 0d 05 1e  53 20 f1 20 8a 37 2c 36  |n be"...S . .7,6|
000011d0  29 22 75 73 65 64 20 66  6f 72 20 69 6e 70 75 74  |)"used for input|
000011e0  20 61 6e 64 20 66 6f 72  20 6f 75 74 70 75 74 2e  | and for output.|
000011f0  20 20 54 68 65 20 6f 75  74 70 75 74 73 20 61 72  |  The outputs ar|
00001200  65 20 6f 66 20 74 68 65  20 4f 70 65 6e 20 43 6f  |e of the Open Co|
00001210  6c 6c 65 63 74 6f 72 22  0d 05 28 4b 20 f1 20 8a  |llector"..(K . .|
00001220  37 2c 38 29 22 74 79 70  65 20 61 6e 64 20 73 6f  |7,8)"type and so|
00001230  20 63 61 6e 20 62 65 20  75 73 65 64 20 74 6f 20  | can be used to |
00001240  73 77 69 74 63 68 20 6f  6e 20 72 65 6c 61 79 73  |switch on relays|
00001250  20 61 6e 64 20 6d 6f 74  6f 72 73 20 65 74 63 20  | and motors etc |
00001260  62 79 22 0d 05 32 52 20  f1 20 8a 37 2c 31 30 29  |by"..2R . .7,10)|
00001270  22 63 6f 6e 6e 65 63 74  69 6e 67 20 65 61 63 68  |"connecting each|
00001280  20 6f 75 74 70 75 74 20  70 69 6e 20 74 6f 20 61  | output pin to a|
00001290  20 2b 76 65 20 73 75 70  70 6c 79 20 61 74 20 75  | +ve supply at u|
000012a0  70 20 74 6f 20 35 30 76  20 74 68 72 6f 75 67 68  |p to 50v through|
000012b0  20 74 68 65 22 0d 05 3c  52 20 f1 20 8a 37 2c 31  | the"..<R . .7,1|
000012c0  32 29 22 72 65 6c 61 79  20 63 6f 69 6c 20 28 65  |2)"relay coil (e|
000012d0  74 63 29 2e 20 20 54 68  65 20 69 6e 70 75 74 73  |tc).  The inputs|
000012e0  20 61 72 65 20 54 54 4c  20 28 74 72 61 6e 73 69  | are TTL (transi|
000012f0  73 74 6f 72 2d 74 72 61  6e 73 69 73 74 6f 72 20  |stor-transistor |
00001300  6c 6f 67 69 63 29 22 0d  05 46 53 20 f1 20 8a 37  |logic)"..FS . .7|
00001310  2c 31 34 29 22 63 6f 6d  70 61 74 69 62 6c 65 20  |,14)"compatible |
00001320  62 75 74 20 74 68 65 79  20 63 61 6e 20 61 6c 73  |but they can als|
00001330  6f 20 62 65 20 75 73 65  64 20 61 73 20 6f 75 74  |o be used as out|
00001340  70 75 74 73 20 74 6f 20  64 72 69 76 65 20 6f 74  |puts to drive ot|
00001350  68 65 72 20 6c 6f 67 69  63 22 0d 05 50 51 20 f1  |her logic"..PQ .|
00001360  20 8a 37 2c 31 36 29 22  61 6e 64 20 74 6f 20 73  | .7,16)"and to s|
00001370  77 69 74 63 68 20 6f 6e  20 4c 45 44 73 20 28 69  |witch on LEDs (i|
00001380  65 20 4f 6e 6c 79 20 33  20 49 6e 70 75 74 73 20  |e Only 3 Inputs |
00001390  61 72 65 20 75 73 65 64  20 74 6f 20 73 65 6e 73  |are used to sens|
000013a0  65 20 74 68 65 20 70 75  73 68 22 0d 05 5a 55 20  |e the push"..ZU |
000013b0  f1 20 8a 37 2c 31 38 29  22 62 75 74 74 6f 6e 73  |. .7,18)"buttons|
000013c0  20 61 6e 64 20 61 6c 73  6f 20 74 6f 20 64 72 69  | and also to dri|
000013d0  76 65 20 74 68 65 20 33  20 4c 45 44 73 29 2e 20  |ve the 3 LEDs). |
000013e0  20 54 68 65 20 6f 75 74  70 75 74 73 20 63 61 6e  | The outputs can|
000013f0  20 62 65 20 73 77 69 74  63 68 65 64 20 6f 6e 22  | be switched on"|
00001400  0d 05 64 55 20 f1 20 8a  37 2c 32 30 29 22 6f 72  |..dU . .7,20)"or|
00001410  20 6f 66 66 20 76 65 72  79 20 71 75 69 63 6b 6c  | off very quickl|
00001420  79 20 75 6e 64 65 72 20  70 72 6f 67 72 61 6d 20  |y under program |
00001430  63 6f 6e 74 72 6f 6c 2e  20 20 54 68 65 79 20 61  |control.  They a|
00001440  72 65 20 75 73 65 64 20  68 65 72 65 20 74 6f 20  |re used here to |
00001450  76 61 72 79 22 0d 05 6e  4e 20 f1 20 8a 37 2c 32  |vary"..nN . .7,2|
00001460  32 29 22 74 68 65 20 73  70 65 65 64 20 6f 66 20  |2)"the speed of |
00001470  61 20 44 43 20 6d 6f 74  6f 72 20 62 79 20 50 75  |a DC motor by Pu|
00001480  6c 73 65 20 57 69 64 74  68 20 4d 6f 64 75 6c 61  |lse Width Modula|
00001490  74 69 6f 6e 20 6f 66 20  74 68 65 20 73 75 70 70  |tion of the supp|
000014a0  6c 79 22 0d 05 78 53 20  f1 20 8a 37 2c 32 34 29  |ly"..xS . .7,24)|
000014b0  22 76 6f 6c 74 61 67 65  20 61 63 72 6f 73 73 20  |"voltage across |
000014c0  74 68 65 20 6d 6f 74 6f  72 2e 20 20 54 68 65 20  |the motor.  The |
000014d0  6d 61 78 69 6d 75 6d 20  75 70 64 61 74 65 20 72  |maximum update r|
000014e0  61 74 65 20 69 73 20 6c  69 6d 69 74 65 64 20 62  |ate is limited b|
000014f0  79 20 74 68 65 22 0d 05  82 52 20 f1 20 8a 37 2c  |y the"...R . .7,|
00001500  32 36 29 22 49 49 43 20  62 75 73 20 61 74 20 61  |26)"IIC bus at a|
00001510  62 6f 75 74 20 31 30 30  75 73 20 6d 69 6e 69 6d  |bout 100us minim|
00001520  75 6d 2e 20 20 54 68 65  20 6d 61 78 69 6d 75 6d  |um.  The maximum|
00001530  20 6c 6f 61 64 20 6f 66  20 65 61 63 68 20 6f 75  | load of each ou|
00001540  74 70 75 74 20 69 73 22  0d 05 8c 3a 20 f1 20 8a  |tput is"...: . .|
00001550  37 2c 32 38 29 22 32 30  30 6d 41 20 63 75 72 72  |7,28)"200mA curr|
00001560  65 6e 74 20 73 69 6e 6b  20 77 68 65 6e 20 4f 4e  |ent sink when ON|
00001570  20 6f 72 20 35 30 56 20  77 68 65 6e 20 4f 46 46  | or 50V when OFF|
00001580  2e 22 0d 05 96 2d 20 f2  57 72 69 74 65 44 69 67  |."...- .WriteDig|
00001590  69 74 61 6c 20 28 49 49  43 5f 44 69 67 4f 75 74  |ital (IIC_DigOut|
000015a0  2c 20 26 46 46 2c 20 52  65 64 4c 45 44 33 29 0d  |, &FF, RedLED3).|
000015b0  05 a0 10 20 e3 20 69 25  3d 31 20 b8 20 35 30 0d  |... . i%=1 . 50.|
000015c0  05 aa 2f 20 20 20 f2 57  72 69 74 65 44 69 67 69  |../   .WriteDigi|
000015d0  74 61 6c 20 28 49 49 43  5f 44 69 67 4f 75 74 2c  |tal (IIC_DigOut,|
000015e0  20 26 46 46 2c 20 52 65  6c 61 79 4f 6e 29 0d 05  | &FF, RelayOn)..|
000015f0  b4 15 20 20 20 f2 44 65  6c 61 79 28 31 35 30 2f  |..   .Delay(150/|
00001600  69 25 29 0d 05 be 2f 20  20 20 f2 57 72 69 74 65  |i%).../   .Write|
00001610  44 69 67 69 74 61 6c 20  28 49 49 43 5f 44 69 67  |Digital (IIC_Dig|
00001620  4f 75 74 2c 20 26 46 46  2c 20 52 65 6c 61 79 4f  |Out, &FF, RelayO|
00001630  6e 29 0d 05 c8 15 20 20  20 f2 44 65 6c 61 79 28  |n)....   .Delay(|
00001640  31 35 30 2f 69 25 29 0d  05 d2 09 20 ed 20 69 25  |150/i%).... . i%|
00001650  0d 05 dc 31 20 f2 57 72  69 74 65 44 69 67 69 74  |...1 .WriteDigit|
00001660  61 6c 20 28 49 49 43 5f  44 69 67 4f 75 74 2c 20  |al (IIC_DigOut, |
00001670  26 46 46 2c 20 52 65 64  54 72 61 66 66 4c 45 44  |&FF, RedTraffLED|
00001680  29 0d 05 e6 11 20 f2 44  65 6c 61 79 20 28 31 35  |).... .Delay (15|
00001690  30 29 0d 05 f0 32 20 f2  57 72 69 74 65 44 69 67  |0)...2 .WriteDig|
000016a0  69 74 61 6c 20 28 49 49  43 5f 44 69 67 4f 75 74  |ital (IIC_DigOut|
000016b0  2c 20 26 46 46 2c 20 41  6d 62 72 54 72 61 66 66  |, &FF, AmbrTraff|
000016c0  4c 45 44 29 0d 05 fa 11  20 f2 44 65 6c 61 79 20  |LED).... .Delay |
000016d0  28 31 35 30 29 0d 06 04  4e 20 f2 57 72 69 74 65  |(150)...N .Write|
000016e0  44 69 67 69 74 61 6c 20  28 49 49 43 5f 44 69 67  |Digital (IIC_Dig|
000016f0  4f 75 74 2c 20 26 46 46  2c 20 52 65 64 54 72 61  |Out, &FF, RedTra|
00001700  66 66 4c 45 44 20 2b 20  41 6d 62 72 54 72 61 66  |ffLED + AmbrTraf|
00001710  66 4c 45 44 20 2b 20 47  72 6e 54 72 61 66 66 4c  |fLED + GrnTraffL|
00001720  45 44 29 0d 06 0e 28 20  f2 52 75 6e 4d 6f 74 6f  |ED)...( .RunMoto|
00001730  72 28 30 2e 30 33 29 20  3a 20 20 20 20 20 20 20  |r(0.03) :       |
00001740  f4 20 76 65 72 79 20 73  6c 6f 77 0d 06 18 13 20  |. very slow.... |
00001750  f2 52 75 6e 4d 6f 74 6f  72 28 30 2e 31 29 0d 06  |.RunMotor(0.1)..|
00001760  22 13 20 f2 52 75 6e 4d  6f 74 6f 72 28 30 2e 33  |". .RunMotor(0.3|
00001770  29 0d 06 2c 11 20 f2 52  75 6e 4d 6f 74 6f 72 28  |)..,. .RunMotor(|
00001780  31 29 0d 06 36 11 20 f2  52 75 6e 4d 6f 74 6f 72  |1)..6. .RunMotor|
00001790  28 33 29 0d 06 40 12 20  f2 52 75 6e 4d 6f 74 6f  |(3)..@. .RunMoto|
000017a0  72 28 31 30 29 0d 06 4a  12 20 f2 52 75 6e 4d 6f  |r(10)..J. .RunMo|
000017b0  74 6f 72 28 32 31 29 0d  06 54 12 20 f2 52 75 6e  |tor(21)..T. .Run|
000017c0  4d 6f 74 6f 72 28 34 36  29 0d 06 5e 2e 20 f2 52  |Motor(46)..^. .R|
000017d0  75 6e 4d 6f 74 6f 72 28  31 30 30 29 20 20 20 20  |unMotor(100)    |
000017e0  3a 20 20 20 20 20 20 20  f4 20 6d 61 78 69 6d 75  |:       . maximu|
000017f0  6d 20 73 70 65 65 64 0d  06 68 1d 20 f4 20 4e 6f  |m speed..h. . No|
00001800  77 20 4c 69 67 68 74 20  43 6f 6e 74 72 6f 6c 6c  |w Light Controll|
00001810  65 64 20 21 0d 06 72 10  20 e3 20 69 25 3d 31 20  |ed !..r. . i%=1 |
00001820  b8 20 32 35 0d 06 7c 20  20 20 20 61 76 3d a4 52  |. 25..|    av=.R|
00001830  65 61 64 41 6e 61 6c 6f  67 75 65 28 49 49 43 5f  |eadAnalogue(IIC_|
00001840  41 44 43 29 0d 06 86 16  20 20 20 f2 52 75 6e 4d  |ADC)....   .RunM|
00001850  6f 74 6f 72 28 61 76 2f  32 29 0d 06 90 09 20 ed  |otor(av/2).... .|
00001860  20 69 25 0d 06 9a 14 20  f4 20 4e 6f 77 20 73 6c  | i%.... . Now sl|
00001870  6f 77 20 64 6f 77 6e 0d  06 a4 40 20 f2 57 72 69  |ow down...@ .Wri|
00001880  74 65 44 69 67 69 74 61  6c 20 28 49 49 43 5f 44  |teDigital (IIC_D|
00001890  69 67 4f 75 74 2c 20 26  46 46 2c 20 47 72 6e 54  |igOut, &FF, GrnT|
000018a0  72 61 66 66 4c 45 44 20  2b 20 41 6d 62 72 54 72  |raffLED + AmbrTr|
000018b0  61 66 66 4c 45 44 29 0d  06 ae 0e 20 54 6d 70 20  |affLED).... Tmp |
000018c0  3d 61 76 2f 32 0d 06 b8  06 20 f5 0d 06 c2 10 20  |=av/2.... ..... |
000018d0  20 20 54 6d 70 3d 54 6d  70 2f 32 0d 06 cc 15 20  |  Tmp=Tmp/2.... |
000018e0  20 20 f2 52 75 6e 4d 6f  74 6f 72 28 54 6d 70 29  |  .RunMotor(Tmp)|
000018f0  0d 06 d6 10 20 fd 20 28  54 6d 70 20 3c 20 31 29  |.... . (Tmp < 1)|
00001900  0d 06 e0 11 20 f2 52 75  6e 4d 6f 74 6f 72 28 31  |.... .RunMotor(1|
00001910  29 0d 06 ea 40 20 f2 57  72 69 74 65 44 69 67 69  |)...@ .WriteDigi|
00001920  74 61 6c 20 28 49 49 43  5f 44 69 67 4f 75 74 2c  |tal (IIC_DigOut,|
00001930  20 26 46 46 2c 20 52 65  64 54 72 61 66 66 4c 45  | &FF, RedTraffLE|
00001940  44 20 2b 20 41 6d 62 72  54 72 61 66 66 4c 45 44  |D + AmbrTraffLED|
00001950  29 0d 06 f4 11 20 f2 52  75 6e 4d 6f 74 6f 72 28  |).... .RunMotor(|
00001960  30 29 0d 06 fe 06 20 db  0d 07 08 06 20 e1 0d 07  |0).... ..... ...|
00001970  12 06 20 3a 0d 07 1c 17  20 dd 20 f2 52 75 6e 4d  |.. :.... . .RunM|
00001980  6f 74 6f 72 28 73 70 65  65 64 29 0d 07 26 52 20  |otor(speed)..&R |
00001990  f4 20 50 75 6c 73 65 20  57 69 64 74 68 20 4d 6f  |. Pulse Width Mo|
000019a0  64 75 6c 61 74 69 6f 6e  20 28 50 57 4d 29 20 4d  |dulation (PWM) M|
000019b0  6f 74 6f 72 20 43 6f 6e  74 72 6f 6c 20 74 6f 20  |otor Control to |
000019c0  73 70 65 65 64 20 28 70  65 72 63 65 6e 74 61 67  |speed (percentag|
000019d0  65 20 6f 66 20 6d 61 78  69 6d 75 6d 29 0d 07 30  |e of maximum)..0|
000019e0  21 20 ea 20 69 25 2c 6a  25 2c 6d 61 72 6b 25 2c  |! . i%,j%,mark%,|
000019f0  73 70 61 63 65 25 2c 70  65 72 69 6f 64 25 0d 07  |space%,period%..|
00001a00  3a 11 20 70 65 72 69 6f  64 25 3d 33 30 30 30 0d  |:. period%=3000.|
00001a10  07 44 21 20 6d 61 72 6b  25 20 3d 20 94 28 73 70  |.D! mark% = .(sp|
00001a20  65 65 64 29 2f 31 30 30  2a 70 65 72 69 6f 64 25  |eed)/100*period%|
00001a30  0d 07 4e 1c 20 73 70 61  63 65 25 3d 20 70 65 72  |..N. space%= per|
00001a40  69 6f 64 25 20 2d 20 6d  61 72 6b 25 0d 07 58 10  |iod% - mark%..X.|
00001a50  20 e3 20 69 25 3d 31 20  b8 20 31 30 0d 07 62 33  | . i%=1 . 10..b3|
00001a60  20 20 20 f2 57 72 69 74  65 44 69 67 69 74 61 6c  |   .WriteDigital|
00001a70  20 28 49 49 43 5f 44 69  67 4f 75 74 2c 20 26 46  | (IIC_DigOut, &F|
00001a80  46 20 2d 20 4d 6f 74 6f  72 4f 6e 2c 20 30 29 0d  |F - MotorOn, 0).|
00001a90  07 6c 1e 20 20 20 e3 6a  25 3d 31 b8 6d 61 72 6b  |.l.   .j%=1.mark|
00001aa0  25 3a 20 20 20 20 20 20  20 20 ed 6a 25 0d 07 76  |%:        .j%..v|
00001ab0  39 20 20 20 f2 57 72 69  74 65 44 69 67 69 74 61  |9   .WriteDigita|
00001ac0  6c 20 28 49 49 43 5f 44  69 67 4f 75 74 2c 20 26  |l (IIC_DigOut, &|
00001ad0  46 46 20 2d 20 4d 6f 74  6f 72 4f 6e 2c 20 4d 6f  |FF - MotorOn, Mo|
00001ae0  74 6f 72 4f 6e 29 0d 07  80 1f 20 20 20 e3 6a 25  |torOn)....   .j%|
00001af0  3d 31 b8 73 70 61 63 65  25 3a 20 20 20 20 20 20  |=1.space%:      |
00001b00  20 20 ed 6a 25 0d 07 8a  09 20 ed 20 69 25 0d 07  |  .j%.... . i%..|
00001b10  94 06 20 e1 0d 07 9e 06  20 3a 0d 07 a8 16 20 dd  |.. ..... :.... .|
00001b20  20 f2 44 65 6c 61 79 28  50 65 72 69 6f 64 25 29  | .Delay(Period%)|
00001b30  0d 07 b2 24 20 f4 20 77  61 69 74 20 66 6f 72 20  |...$ . wait for |
00001b40  50 65 72 69 6f 64 25 20  63 65 6e 74 69 73 65 63  |Period% centisec|
00001b50  6f 6e 64 73 0d 07 bc 09  20 ea 20 54 25 0d 07 c6  |onds.... . T%...|
00001b60  09 20 54 25 3d 91 0d 07  d0 1a 20 c8 95 20 28 28  |. T%=..... .. ((|
00001b70  91 2d 54 25 29 20 3c 20  50 65 72 69 6f 64 25 29  |.-T%) < Period%)|
00001b80  0d 07 da 1f 20 20 20 f4  20 2e 2e 2e 20 74 77 69  |....   . ... twi|
00001b90  64 64 6c 65 20 74 68 75  6d 62 73 20 2e 2e 2e 0d  |ddle thumbs ....|
00001ba0  07 e4 06 20 ce 0d 07 ee  06 20 e1 0d 07 f8 06 20  |... ..... ..... |
00001bb0  3a 0d 08 02 1e 20 dd 20  a4 52 65 61 64 44 69 67  |:.... . .ReadDig|
00001bc0  69 74 61 6c 28 50 6f 72  74 41 64 72 73 25 29 0d  |ital(PortAdrs%).|
00001bd0  08 0c 2c 20 f4 20 72 65  61 64 20 38 20 62 69 74  |.., . read 8 bit|
00001be0  73 20 66 72 6f 6d 20 73  70 65 63 69 66 69 65 64  |s from specified|
00001bf0  20 69 6e 70 75 74 20 70  6f 72 74 0d 08 16 0b 20  | input port.... |
00001c00  ea 20 42 75 66 25 0d 08  20 0e 20 de 20 42 75 66  |. Buf%.. . . Buf|
00001c10  25 20 31 30 0d 08 2a 25  20 c8 99 22 49 49 43 5f  |% 10..*% .."IIC_|
00001c20  43 6f 6e 74 72 6f 6c 22  2c 50 6f 72 74 41 64 72  |Control",PortAdr|
00001c30  73 25 2c 42 75 66 25 2c  31 0d 08 34 0b 20 3d 3f  |s%,Buf%,1..4. =?|
00001c40  42 75 66 25 0d 08 3e 06  20 3a 0d 08 48 34 20 dd  |Buf%..>. :..H4 .|
00001c50  20 f2 57 72 69 74 65 44  69 67 69 74 61 6c 20 28  | .WriteDigital (|
00001c60  50 6f 72 74 41 64 72 73  25 2c 20 41 6e 64 4d 61  |PortAdrs%, AndMa|
00001c70  73 6b 25 2c 20 45 6f 72  4d 61 73 6b 25 29 0d 08  |sk%, EorMask%)..|
00001c80  52 40 20 f4 20 63 68 61  6e 67 65 20 38 20 62 69  |R@ . change 8 bi|
00001c90  74 73 20 6f 66 20 73 70  65 63 69 66 69 65 64 20  |ts of specified |
00001ca0  6f 75 74 70 75 74 20 70  6f 72 74 20 61 63 63 6f  |output port acco|
00001cb0  72 64 69 6e 67 20 74 6f  20 6d 61 73 6b 73 0d 08  |rding to masks..|
00001cc0  5c 32 20 f4 20 74 6f 20  73 65 74 20 61 20 62 69  |\2 . to set a bi|
00001cd0  74 20 75 73 65 20 41 6e  64 4d 61 73 6b 25 20 3d  |t use AndMask% =|
00001ce0  20 30 2c 20 45 6f 72 4d  61 73 6b 25 20 3d 20 31  | 0, EorMask% = 1|
00001cf0  0d 08 66 34 20 f4 20 74  6f 20 63 6c 65 61 72 20  |..f4 . to clear |
00001d00  61 20 62 69 74 20 75 73  65 20 41 6e 64 4d 61 73  |a bit use AndMas|
00001d10  6b 25 20 3d 20 30 2c 20  45 6f 72 4d 61 73 6b 25  |k% = 0, EorMask%|
00001d20  20 3d 20 30 0d 08 70 35  20 f4 20 74 6f 20 74 6f  | = 0..p5 . to to|
00001d30  67 67 6c 65 20 61 20 62  69 74 20 75 73 65 20 41  |ggle a bit use A|
00001d40  6e 64 4d 61 73 6b 25 20  3d 20 31 2c 20 45 6f 72  |ndMask% = 1, Eor|
00001d50  4d 61 73 6b 25 20 3d 20  31 0d 08 7a 44 20 f4 20  |Mask% = 1..zD . |
00001d60  74 6f 20 69 67 6e 6f 72  65 20 61 20 62 69 74 20  |to ignore a bit |
00001d70  28 69 65 20 6e 6f 20 63  68 61 6e 67 65 29 20 75  |(ie no change) u|
00001d80  73 65 20 41 6e 64 4d 61  73 6b 25 20 3d 20 31 2c  |se AndMask% = 1,|
00001d90  20 45 6f 72 4d 61 73 6b  25 20 3d 20 30 0d 08 84  | EorMask% = 0...|
00001da0  0b 20 ea 20 42 75 66 25  0d 08 8e 0e 20 de 20 42  |. . Buf%.... . B|
00001db0  75 66 25 20 31 30 0d 08  98 36 20 44 69 67 4f 75  |uf% 10...6 DigOu|
00001dc0  74 43 6f 70 79 25 20 3d  20 28 44 69 67 4f 75 74  |tCopy% = (DigOut|
00001dd0  43 6f 70 79 25 20 80 20  41 6e 64 4d 61 73 6b 25  |Copy% . AndMask%|
00001de0  29 20 82 20 45 6f 72 4d  61 73 6b 25 0d 08 a2 16  |) . EorMask%....|
00001df0  20 3f 42 75 66 25 3d 44  69 67 4f 75 74 43 6f 70  | ?Buf%=DigOutCop|
00001e00  79 25 0d 08 ac 25 20 c8  99 22 49 49 43 5f 43 6f  |y%...% .."IIC_Co|
00001e10  6e 74 72 6f 6c 22 2c 50  6f 72 74 41 64 72 73 25  |ntrol",PortAdrs%|
00001e20  2c 42 75 66 25 2c 31 0d  08 b6 06 20 e1 0d 08 c0  |,Buf%,1.... ....|
00001e30  06 20 3a 0d 08 ca 20 20  dd 20 a4 52 65 61 64 41  |. :...  . .ReadA|
00001e40  6e 61 6c 6f 67 75 65 20  28 50 6f 72 74 41 64 72  |nalogue (PortAdr|
00001e50  73 25 29 0d 08 d4 3e 20  f4 20 52 65 61 64 20 61  |s%)...> . Read a|
00001e60  6e 61 6c 6f 67 75 65 20  76 61 6c 75 65 20 28 72  |nalogue value (r|
00001e70  61 6e 67 65 20 30 20 2d  20 32 35 35 29 20 66 72  |ange 0 - 255) fr|
00001e80  6f 6d 20 73 70 65 63 69  66 69 65 64 20 70 6f 72  |om specified por|
00001e90  74 0d 08 de 0b 20 ea 20  42 75 66 25 0d 08 e8 0e  |t.... . Buf%....|
00001ea0  20 de 20 42 75 66 25 20  31 30 0d 08 f2 19 20 3f  | . Buf% 10.... ?|
00001eb0  42 75 66 25 3d 49 49 43  5f 41 44 43 5f 53 74 61  |Buf%=IIC_ADC_Sta|
00001ec0  74 75 73 0d 08 fc 25 20  c8 99 22 49 49 43 5f 43  |tus...% .."IIC_C|
00001ed0  6f 6e 74 72 6f 6c 22 2c  50 6f 72 74 41 64 72 73  |ontrol",PortAdrs|
00001ee0  25 2c 42 75 66 25 2c 33  0d 09 06 0c 20 3d 42 75  |%,Buf%,3.... =Bu|
00001ef0  66 25 3f 32 0d 09 10 06  20 3a 0d 09 1a 29 20 dd  |f%?2.... :...) .|
00001f00  20 f2 57 72 69 74 65 41  6e 61 6c 6f 67 75 65 20  | .WriteAnalogue |
00001f10  28 50 6f 72 74 41 64 72  73 25 2c 20 56 61 6c 75  |(PortAdrs%, Valu|
00001f20  65 25 29 0d 09 24 3d 20  f4 20 57 72 69 74 65 20  |e%)..$= . Write |
00001f30  61 6e 61 6c 6f 67 75 65  20 76 61 6c 75 65 20 28  |analogue value (|
00001f40  72 61 6e 67 65 20 30 20  2d 20 32 35 35 29 20 74  |range 0 - 255) t|
00001f50  6f 20 73 70 65 63 69 66  69 65 64 20 70 6f 72 74  |o specified port|
00001f60  0d 09 2e 0b 20 ea 20 42  75 66 25 0d 09 38 0e 20  |.... . Buf%..8. |
00001f70  de 20 42 75 66 25 20 31  30 0d 09 42 19 20 3f 42  |. Buf% 10..B. ?B|
00001f80  75 66 25 3d 49 49 43 5f  41 44 43 5f 53 74 61 74  |uf%=IIC_ADC_Stat|
00001f90  75 73 0d 09 4c 12 20 42  75 66 25 3f 31 3d 56 61  |us..L. Buf%?1=Va|
00001fa0  6c 75 65 25 0d 09 56 25  20 c8 99 22 49 49 43 5f  |lue%..V% .."IIC_|
00001fb0  43 6f 6e 74 72 6f 6c 22  2c 50 6f 72 74 41 64 72  |Control",PortAdr|
00001fc0  73 25 2c 42 75 66 25 2c  32 0d 09 60 06 20 e1 0d  |s%,Buf%,2..`. ..|
00001fd0  ff                                                |.|
00001fd1