To use this file copy and paste this:
// #URL-lib "http://pin1.org/forthlib/flb/I2C/BV4213.flb" into BV Terminal 3
or here to download.
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// BV4213 Motor controller
// This has an I2c interface and also a step and direction
// interface. When using the I2C interface it can also do PWM
// Capable of driving 4 dc motors 1 way, 2 DC motors fwd and rev
// or 1 stepper motor
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// HISTORY:
// March 2008 * error with VER, fixed
// REQUIRES:
// #URL-lib "http://pin1.org/forthlib/flb/General/soft1.flb"
// #URL-lib "http://pin1.org/forthlib/flb/General/pinsel.flb"
// #URL-lib "http://pin1.org/forthlib/flb/I2C/i2c.flb"
// CONSTANTS:
integer device // holds i2c address
// holds stepper parameters
integer steps
integer direction
integer speedval
integer hf
integer rampval
Full Contents of File
integer  device       
integer  steps
integer  direction
integer  speedval
integer  hf
integer  rampval
: i2sdevice  s  ; 
: a20i2s  &20  sb  p  ; 
: a21i2s  &21  sb  p  ; 
: a21ai2s  &21  sb  1  sb  p  ; 
: a22  i2s  &22  sb  dup  &ff00  and  8  rshift  sb  &ff  and  sb  p  ;
: a24  i2s  &24  sb  device  1+  rs 
            rn  8  lshift  rn  +     
            3  for  rn  next  rl  p
            =>  rampval  =>  hf  =>  speedval  =>  direction  =>  steps  ;
: steps?a24  steps  ; 
: a23  i2s  &23  sb  direction  sb  speedval    sb 
        hf  sb  rampval  sb  p  ;
: dir  =>  direction  a23  ; 
: speed  =>  speedval  a23  ;   
: h/f  =>  hf  a23  ;             
: ramp  =>  0  max  8  min  rampval  a23  ; 
: a1  i2s  1  sb  sb  p  ; 
: a2  i2s  2  sb  sb  p  ; 
: a3  i2s  3  sb  sb  p  ; 
: a4  i2s  4  sb  sb  p  ; 
: a5  i2s  5  sb  sb  p  ; 
: a11  i2s  &11  sb  sb  p  ; 
: a12  i2s  &12  sb  sb  p  ; 
: a13  i2s  &13  sb  sb  p  ; 
: a14  i2s  &14  sb  sb  p  ; 
: a15  i2s  &15  sb  sb  p  ; 
: a16  i2s  &16  sb  sb  p  ; 
-18  constant  dirs   
-17  constant  clk   
-16  constant  enable 
: setup
    dirs  io-out  clk  io-out  enable  io-out 
    0  enable  p!      ; 
: dirss  dirs  p!  ;
: t10100  for  10  ms  0  clk  p!  10  ms  1  clk  p!  next  ;
     
: ver
      device  s  &90  sb  10  sb  device  1+  rs   
      cr  ."  Ver  "  rn  .  [char]  .  emit  rl  emit  p
;       
: a55  device  s  &55  sb  device  1+  rs  rn  1  =  rn  2  =  and  rl  3  =  and  p  ;
: a90 
    device  s  &90  sb  sb  device  1+  rs 
    1-  for  rn  next 
    rl  p  ;
   
: a91
    device  s  &91  sb  sb
    depth  for  sb  next
    p  ;
   
: a94  device  s  &94  sb  p  ; 
: a95  device  s  &95  sb  p  ; 
: a96  device  s  &96  sb  p  ; 
: a99  device  s  &99  sb  dup  sb  &55  sb  &aa  sb  device  sb  =>  device  p  ;
: 4213-init 
    =>  device     
    i2-init         
    a55                 
    if
        a24             
        -1               
    else
        0                 
    then   
;