$regfile = "m8adef.dat"
$crystal = 8000000
Config Timer1 = Timer, Prescale = 1, Compare_A = Disconnect, Clear_Timer = 1
Config Timer2 = Timer, Prescale = 1, Compare = Disconnect, Clear_Timer = 1
Config Twislave = &H20,Btr = 1,Bitrate = 100000,Gencall = 1
Dim temp1 as Integer, temp2 as Integer, fast as Integer, slow as Integer
Dim stan As Byte
$baud = 19200
$hwstack = 32
$swstack = 10
$framesize = 40
Config Pinb.1 = Output 'stepper1
Config Pinb.3 = Output 'stepper2
stepper1 Alias Portb.1
stepper2 Alias Portb.3
On Compare1a run_stepper1
On compare2 run_stepper2
Enable Interrupts
enable timer2 ' ??? should it be
stan=10
fast=350
slow=600
Do
'slow down stepper1
if stan=0 then
stan=10
for temp1=fast to slow step 10
Compare1a=temp1
waitus 200
next temp1
disable Compare1a
end if
'slow down stepper2
if stan=3 then
stan=10
for temp2=fast to slow step 10
Compare2=temp2
waitus 200
next temp2
disable compare2
end if
'start stepper1
if stan=1 then
stan=10
Enable Compare1a
for temp1=slow to fast step -10
Compare1a=temp1
waitus 200
next temp1
end if
'start stepper2
if stan=4 then
stan=10
Enable compare2
for temp2=slow to fast step -10
Compare2=temp2
waitus 200
next temp2
end if
Loop
Twi_stop_rstart_received:
Return
Twi_addressed_goread:
Return
Twi_addressed_gowrite:
Return
Twi_gotdata:
stan=twi
Return
Twi_master_needs_byte:
'Twi_btr
Twi = stan
Return
Twi_master_need_nomore_byte:
Return
run_stepper1:
Toggle stepper1
Return
run_stepper2:
Toggle stepper2
Return
|