As I promised, CODE!
Interface Test #1
CON
_xinfreq = 5000000
_clkmode = xtal1 + pll16x
counthi = $27
countlow = $10
speedy = $80
OBJ
debug:"FullDuplexSerialPlus"
bob:"MMBe"
PUB Main
Comm
repeat
Display
PUB Comm
debug.start(31,30,0,57600)
bob.start(3,4,2400)
waitcnt(clkfreq+cnt)
debug.tx(16)
PUB Display | key, forward, reverse, power, xf, xr, status, a, b
xr:=0
xf:=0
repeat until xf == 1 or xr ==1
debug.str(string(13,"press F or R for direction"))
key:=debug.rx
debug.tx(13)
debug.tx(key)
debug.dec(key)
debug.tx(13)
status := bob.getstatus
debug.dec(status)
if key == 102
xf:=1
debug.str(string(13,"Motor is moving forward"))
bob.setdir(0)
bob.set(200)
if key == 114
xr:=1
debug.str(string(13,"Motor is moving in reverse"))
bob.setdir(1)
bob.set(200)
if key == 115
bob.motorstop
if xf == 1 or xr == 1
debug.str(string(13, "yay it worked"))
Interface Test #2
CON
_xinfreq = 5000000
_clkmode = xtal1 + pll16x
OBJ
Debug : "FullDuplexSerialPlus"
MMB : "MMBe"
VAR
byte counthi, countlow, Speed, dir, trip
word MoveCount, TotalCount
PUB Main
Comm
waitcnt(clkfreq+cnt)
Totalcount := mmb.readHiCount
Debug.dec(Totalcount)
Debug.tx(13)
repeat
MoveCount := debug.getdec
Speed := debug.getdec
dir := debug.getdec
mmb.setdir(dir)
outb[15..0]:= MoveCount
counthi := outb[15..8]
countlow := outb[7..0]
Debug.tx(13)
Debug.dec (mmb.encode(counthi,countlow,speed))
repeat
Totalcount := mmb.readHiCount
Debug.dec(Totalcount)
Debug.tx(13)
{if totalcount > 10000 and trip == 0
trip :=1
mmb.encode(counthi,countlow,60)}
PUB Comm
debug.start(31,30,0,57600)
mmb.start(3,4,2400)
waitcnt(clkfreq+cnt)
debug.tx(16)
PUB Display | key
mmb.set(128)
repeat
key:=debug.getdec
Speed Control
CON
_xinfreq = 5000000
_clkmode = xtal1 + pll16x
OBJ
Debug : "FullDuplexSerialPlus"
MMB : "MMBe"
VAR
byte counthi, countlow, Speed, dir, trip
word MoveCount, TotalCount
PUB Main | x
Comm
mmb.speedcon_mode
x := 0
movecount := debug.getdec
outb[15..0]:= MoveCount
counthi := outb[15..8]
countlow := outb[7..0]
repeat
x++
mmb.speedcon(counthi,countlow)
waitcnt(clkfreq*2 +cnt)
mmb.motorrev
PUB Comm
debug.start(31,30,0,57600)
mmb.start(1,2,2400)
waitcnt(clkfreq+cnt)
debug.tx(16)
No comments:
Post a Comment