include 16f628_20 include delay_20mc include jstepper CMCON = 7 -- set portA to normal digital IO -- only PIC628 port_a_direction = 0b1111_1111 -- all input port_b_direction = 0b0000_0000 -- all output port_b = 0b0000_0000 var volatile bit b_step is pin_a0 var volatile bit b_dir is pin_a1 var volatile bit a_step is pin_a2 var volatile bit a_dir is pin_a3 var volatile bit step_type is pin_a4 var byte stepper_a = 0b_0001 -- start of the stepper sequences var byte stepper_b = 0b_0001 var bit b_step_t = false var bit a_step_t = false forever loop if b_step != b_step_t then -- has the step input changed ? b_step_t = b_step if b_step == false then -- is it the negative going edge? if b_dir == true then -- what direction should the stepper spin? if step_type == true then -- is it full or half step? stepper_motor_half_forward( stepper_b ) -- half foreward port_b_high = stepper_b else stepper_motor_full_forward( stepper_b ) -- full foreward port_b_high = stepper_b end if else if step_type == true then stepper_motor_half_backward( stepper_b ) -- half backward port_b_high = stepper_b else stepper_motor_full_backward( stepper_b ) -- full backward port_b_high = stepper_b end if end if end if end if if a_step != a_step_t then -- has the step input changed ? a_step_t = a_step if a_step == false then -- is it the negative going edge? if a_dir == true then -- what direction should the stepper spin? if step_type == true then -- is it full or half step? stepper_motor_half_forward( stepper_a ) -- half foreward port_b_low = stepper_a else stepper_motor_full_forward( stepper_a ) -- full foreward port_b_low = stepper_a end if else if step_type == true then stepper_motor_half_backward( stepper_a ) -- half backward port_b_low = stepper_a else stepper_motor_full_backward( stepper_a ) -- full backward port_b_low = stepper_a end if end if end if end if -- stepper_motor_full_forward( stepper_b ) -- port_b_low = stepper_b -- port_b_high = stepper_b -- delay_100ms(1) end loop