Wardialer Rev2 Code
‘# wardialerrev2.bas Rob stave
‘# Basic picaxe code for a sound maker.
‘# uses the picaxe08m and a 4094 to produce a
‘# series of random 8 bit patterns in the form
‘# xxxxyyyy where xxxx and yyyy are three bits on
‘# and one off. For example 1110 1011
‘# this pattern is feed into the NTE 1690 DTMF chip
‘# to produce a sound.
‘# www.robthefiddler.com
symbol INPUT_PIN = 4
symbol DATA_PIN = 1
symbol CLOCK_PIN = 2
symbol STROBE_PIN = 0
‘ w0 = b0 and b1
symbol val = b0
‘ w1
symbol RandomValue = w1
‘ w2 = b4 and b5
symbol loopcount = b4
symbol loopflag = b5
‘ w3 = b6 and b7
symbol rand = b6
symbol tempVariable = b7
‘ w4 used for reading adc
symbol inputValue = w4
eeprom 0, ($EE,$ED,$EB,$E7,$DE,$DD,$DB,$D7,$BE,$BD,$BB,$B7,$7E,$7D,$7B,$77 )
begin:
loopcount = 0;
low DATA_PIN
low CLOCK_PIN
low STROBE_PIN
setfreq m8
SetInt %000010000, %000010000
readadc INPUT_PIN, RandomValue
main:
random RandomValue
readadc INPUT_PIN, inputValue
goto main
‘ ## Interrupt
‘
‘ This is pretty much where most of the code is.
‘ The PICAXE doesnt interrupt on up or down clocks,
‘ Instead, you detect a high and loop until its low.
‘ In general, you want interrupt code to be as short
‘ and sweet as possible. Using this strategy, you really
‘ have 1/2 clock cycle max to do your work.
‘ In this case, as long as the pin is high, I can take
‘ advantage of this and readADC.
interrupt:
if pin3 = 1 then
‘ not ready yet…but readadc while we are waiting.
readadc INPUT_PIN, inputValue
goto interrupt
endif
if inputvalue < 50 then
loopcount = loopcount + 1
gosub inOrder
goto finishInterrupt
endif
if inputvalue < 100 then
loopcount = loopcount - 1
gosub inOrder
goto finishInterrupt
endif
loopcount = loopcount + 1
loopflag =loopcount AND %00000001
if inputvalue > 220 then
rand = b2 AND %00000011
if rand = 0 then
gosub strobeAZero
goto finishInterrupt
endif
endif
if inputvalue > 150 then
loopflag = 1;
endif
if loopflag = 1 then
gosub strobeADigit
else
gosub strobeAZero
endif
finishInterrupt:
SetInt %000001000, %000001000
return
inOrder:
rand = loopcount AND %00001111
read rand, val
gosub clockoutData
return
strobeADigit:
rand = b2 AND %00001111
read rand, val
‘# val is b0 so just read the bits out
‘# and pulse the clock
gosub clockoutData
return
strobeAZero:
val = 0
gosub clockoutData
return
clockoutData:
pin1 = bit7
pulsout CLOCK_PIN, 10
pin1 = bit6
pulsout CLOCK_PIN, 10
pin1 = bit5
pulsout CLOCK_PIN, 10
pin1 = bit4
pulsout CLOCK_PIN, 10
pin1 = bit3
pulsout CLOCK_PIN, 10
pin1 = bit2
pulsout CLOCK_PIN, 10
pin1 = bit1
pulsout CLOCK_PIN, 10
pin1 = bit0
pulsout CLOCK_PIN, 10
‘# pulse the stobe
pulsout STROBE_PIN, 10
return