( i2c/2-wire 0
[c]fig8r)
$B8 const twbr
$B9 const twsr
$BC const twcr
$BB const twdr
$BA const twar
$BD const twamr
create badI2c "
bad i2c"
: ?twsr ( msk)
twsr ic@ and 0=
badI2c ?error
;
Now you're ready to write code to talk to the digital to analog converter:
Writing to the DAC
( Maxim DAC bit 0=reg)
$4C const max517/8Base
$40 const max519Base
: >dac ( val addr)
dup $FE and i2c{
1 and >i2c >i2c
}i2c
;
Here, all that's required to start using the DAC is to initially activate the i2c using
Then FIGnition can send 8-bit values to the DAC to be converted to analog voltages by
typing
number aDac >dac
DAC.
One use of a DAC could be to control the envelope parameters of a simple digitally-
controlled monophonic analog synthesizer. Here, we could use a Max 518 dual DAC to
control a high-pass filter and amplitude, with software on FIGnition to manage pitch using
its normal audio out and sound envelopes along with a simple sequencer and arpeggiator.
9.5 Using I2C to talk to a Microchip I/O Ex-
pander
A Microchip 23008 I/O Expander (RS Part# 403-563) can provide an extra 8 I/O GPIO pins
for a FIGnition. Like FIGnition's GPIOs you can control the data direction of any of the pins
as well as reading or writing to them and activate pull-ups. It requires a very similar circuit:
: twcr! ( c-)
$84 or twcr ic!
;
: ?twINT
begin
twcr ic@ $80
and
until
;
: ?twSTO
begin
twcr ic@ $10
and
0= until
;
Demonstration Code
max517/8Base const aDac
: demoDac
i2ini
begin
256 0 do
i aDac >dac
loop
inkey until
;
. The
demoDac
: i2ini
0 twsr ic!
$C0 twbr ic!
;
: i2c{ ( addr)
$20 twcr! ?twINT
$18 ?twsr
( a) twdr ic! 0
twcr!
?twINT $58 ?twsr
;
: }i2c
$10 twcr! ?twSTO
;
example outputs a sawtooth pattern to the
: >i2c ( c)
twdr ic! 0 twcr!
?twINT $28 ?twsr
;
: i2c> ( -c)
$30 twcr! ?twINT
twdr ic@
;
: i2c>+ ( -c)
0 twcr! ?twINT
twdr ic@
;
i2cini
.