symbol DOUT=input6 ;<-MAX7301
symbol CSEL=output6 ;chip select (load)
symbol DIN =output5 ;->MAX7301
symbol CLK =output4 ;clock
low CSEL:low DIN:low CLK
wait 1 'system stabilize
b1=$04 'config
b0=$01 'NORMAL
gosub shiftout
b1=$09 'ports 4-7 = virtual/unused
b0=%01010101 '01=OUTPUT so won't float
gosub shiftout
b1=$0a 'ports 8-11 = virtual/unused
b0=%01010101 '01=OUTPUT so won't float
gosub shiftout
b1=$0b 'ports 12-15
b0=%01010101 '01=OUTPUT, 10 or 11=INPUT
gosub shiftout ' (11=internal pullups)
b1=$0c 'ports 16-19
b0=%11111111 'inputs
gosub shiftout
b1=$0d 'ports 20-23
b0=%11111111 'inputs
gosub shiftout
b1=$0e 'ports 24-27
b0=%11111111 'inputs
gosub shiftout
b1=$0f 'ports 28-31
b0=%10101010 'inputs
gosub shiftout
setfreq m8 'run at 8MHz instead of 4MHz
loop:
b1=$2c 'port 12 'Just toggling
b0=$00 'set LO 'these ports to
gosub shiftout 'flash some LEDs.
b1=$2d 'port 13
b0=$01 'set HI
gosub shiftout
|
b1=$2c 'port 12
b0=$01 'set HI
gosub shiftout
b1=$2d 'port 13
b0=$00 'set LO
gosub shiftout
b1=$d0 'read input ports 16-23 (8 bits)
gosub shiftout 'must shiftout before shiftin
gosub shiftin 'b0 is the returned value
sertxd ("ok:",#b0," ") '9600 baud if @ 8MHz
goto loop
shiftout:
for b10=1 to 16
w6=w0 & $8000 'mask; (w0=b1:b0)
low DIN
if w6=0 then bit_is_low
high DIN
bit_is_low:
pulsout CLK,5
w0=w0*2 '<< shift bits left
next b10
pulsout CSEL,5
return
shiftin:
w0=0
for b10=1 to 16
w0=w0*2 '<< shift bits left
if DOUT=0 then skipMSB
w0=w0+1
skipMSB:
pulsout CLK,5
next b10
return
|