Elkészült a Miniplotter első firmware verziója.
Ezt nem a gyerekek készítették, hanem szórakozásból én. :)))
A firmeare tehát az előzőek alapján a Basic STAMP
bélyegszámítógép-re készült. Az alábbi tudást biztosítja hardver
szinten.
- Vonalvastagság 15 méretben
- pontrajzolás
- vonalrajzolás
- négyzetrajzolás
- reset
- home és far pozíciókba térés
A vonalvastagság legvékonyabb méretét kisérleti jelleggel
állapítottam meg. Ehhez képes a 15-ös méret 15 db pöttyöt tesz egy
helyre.
A négyzetrajzolás csak a derékzögű koordinátarendszerben - a
plotter két síkjára párhuzamosan - értelmezett.
A firmware lekezeli a végálláskapcsolókat, és információt is
visszaad a rajzterület teljes méretéről.
Tehát jöjjön a Basic Stamp firmware:
'
{$STAMP BS2p}
'
{$PBASIC 2.5}
motorpause CON 0
'kötelező stepping pause
l1
CON 4 '12
d1
CON 3 '14
c1
CON 2 '11
LOW
l1
prim
CON 5
addr1 CON
6
addr2 CON
7
x
CON 0
y
CON 1
left
CON 0
right CON
1
top
CON 2
bottom CON
3
id
CON $a0
'ram
térkép
command
CON 0
width
CON 20
height
CON 22
'penwidth
CON 14 '//byte 0..15 0=weak,legvékonyabb
rect
CON 26 '6,8,10,12 word
rectx
CON 26
recty
CON 28
rectw
CON 30
recth
CON 32
recttop
CON recth 'aliases
rectbottom
CON recty
rectleft
CON rectx
rectright
CON rectw
rectx2
CON rectw
recty2
CON recth
position
CON 34 '2 x Word //coord x,y = aktuális pozíció
koordinátája
positionx
CON 34 '2 x Word //coord x,y = aktuális pozíció
koordinátája
positiony
CON 36 '2 x Word //coord x,y = aktuális pozíció
koordinátája
setpos
CON 38 '2 x Word //elérendő pozíció
setpx
CON 38 '2 x Word //elérendő
pozíció
setpy
CON 40 '2 x Word //elérendő
pozíció
line
CON 42 '
cim
VAR Word 'i2c eeprom cim és
érték
ertek
VAR Word
a
VAR cim 'általános
változók (kizárva amikor i2c eprom)
b
VAR ertek
setposx
VAR a
setposy
VAR a
posx
VAR b
posy
VAR b
'végálláskapcsolók
switchleft
PIN 9 'x1
switchright
PIN 8 'x2
switchtop
PIN 11 'y1
switchbottom
PIN 10 'y2
INPUT
switchleft
INPUT
switchright
INPUT
switchtop
INPUT
switchbottom
'fej
kikapcsolása
LOW
addr1
LOW
addr2
LOW
prim
'motor
fázisállapotok tárolása
maxphase CON 8
'ennyi fázis van
phase VAR
Nib(maxphase)
'phase(0) =
%0011
'phase(1) =
%0110
'phase(2) =
%1100
'phase(3) =
%1001
phase(0) =
%0001
phase(1) =
%0011
phase(2) =
%0010
phase(3) =
%0110
phase(4) =
%0100
phase(5) =
%1100
phase(6) =
%1000
phase(7) =
%1001
motorphase VAR
Nib(2) 'az adott motor éppen melyik fázisban van
motorphase(x)=0
motorphase(y)=0
penstate VAR Bit
' 1=down=lent van=ír
penwidth VAR
Nib
penstate =
0
penwidth=0
i
VAR Word 'általános ciklusváltozó GOSUB ne menjen belőle
!
dropi VAR
Nib
'j
VAR Byte
cmd
VAR Byte
'**************************
program start
GOSUB
reset
start:
GOSUB
ok
DEBUGIN SPSTR 1
GET
0,cmd
DEBUG
cmd,13
SELECT cmd
CASE "w"
GOSUB getparam
DEBUGIN DEC penwidth
CASE "0"
GOSUB gohome
CASE "1"
GOSUB gofar
CASE "r"
GOSUB reset
CASE "f"
GOSUB drawframe
CASE "b"
GET width,Word a
GET height,Word b
GOSUB getparam
DEBUGIN DEC ertek
PUT rectx,Word ertek
DEBUGIN DEC ertek
PUT recty,Word ertek
DEBUGIN DEC ertek
PUT rectw,Word ertek
DEBUGIN DEC ertek
PUT recth,Word ertek
GOSUB drawbox
CASE "p"
GOSUB getparam
DEBUGIN DEC ertek
PUT setpx,Word ertek
DEBUGIN DEC ertek
PUT setpy,Word ertek
GOSUB drawpoint
CASE "l"
GOSUB getparam
DEBUGIN DEC ertek
PUT rectx,Word ertek
DEBUGIN DEC ertek
PUT recty,Word ertek
DEBUGIN DEC ertek
PUT rectx2,Word ertek
DEBUGIN DEC ertek
PUT recty2,Word ertek
GOSUB drawline
ENDSELECT
GOTO
start
'**************************
functions , függvények
penup:
penstate =
0
RETURN
pendown:
penstate =
1
RETURN
ok:
DEBUG
"MPS1>",CR
RETURN
getparam:
DEBUG
":",CR
RETURN
gotopos:
'DEBUG
13,"x:",DEC setpos(x),",",DEC position(x)
GET
setpx,Word setposx
GET
position,Word posx
IF
setposx
DO
WHILE switchleft=1 AND (posx>setposx)
'
DEBUG 13,"1x:",DEC position(x)
GOSUB motor_step_left
LOOP
ELSE
DO
WHILE switchright=1 AND (posx
'
DEBUG 13,"2x:",DEC position(x)
GOSUB motor_step_right
LOOP
ENDIF
GET
setpy,Word setposy
GET
positiony,Word posy
'DEBUG
13,"y:",DEC setpos(y),",",DEC position(y)
IF
setposy>posy THEN
DO
WHILE switchtop=1 AND (posy
'
DEBUG 13,"1y:",DEC position(y)
GOSUB motor_step_top
LOOP
ELSE
DO
WHILE switchbottom=1 AND (posy>setposy)
'
DEBUG 13,"2y:",DEC position(y)
GOSUB motor_step_bottom
LOOP
ENDIF
'PAUSE
5000
RETURN
gohome:
GOSUB
penup
GOSUB
runleft
GOSUB
RUNbottom
RETURN
gofar:
GOSUB
penup
GOSUB
RUNright
GOSUB
RUNtop
RETURN
reset:
GOSUB
penup
GOSUB
runleft
GOSUB
RUNbottom
'DEBUG
13,"Motor in left,top position: "
'Rajztábla
méretének megállapítása
GOSUB
RUNright
GOSUB
RUNtop
GET
positionx,Word a
GET
positiony,Word b
DEBUG
"W:",DEC a,CR,"H:",DEC b,CR
PUT
width,Word a
PUT
height,Word b
'
GET width,Word a
'
GET height,Word b
'
DEBUG 13,"Width:",DEC a,"Height:",DEC b
GOSUB
runleft
GOSUB
runbottom
PUT
setpos,Word 0,Word 0
PUT
position,Word 0,Word 0
RETURN
runleft:
DO WHILE
switchleft = 1
GOSUB motor_step_left
LOOP
RETURN
runtop:
DO WHILE
switchtop = 1
GOSUB motor_step_top
LOOP
RETURN
runright:
DO WHILE
switchright = 1
GOSUB motor_step_right
LOOP
RETURN
runbottom:
DO WHILE
switchbottom = 1
GOSUB motor_step_bottom
LOOP
RETURN
motor_step_left:
IF
switchleft=1 THEN
'
DEBUG 13,"Motor go left position",DEC
switchleft
IF
motorphase(x)<(maxphase-1) THEN
motorphase(x)=motorphase(x)+1
ELSE
motorphase(x)=0
ENDIF
GET
positionx,Word b
IF
b>0 THEN
b=b-1
ELSE
b=0
ENDIF
PUT
positionx,Word b
SHIFTOUT d1,c1,MSBFIRST,[phase(motorphase(x)) <<
4]
PULSOUT l1,1
PAUSE motorpause
GOTO
drop1 'és egyben return
ELSE
'
DEBUG 13,"Motor in left position",DEC
switchleft
PUT
position,Word 0
ENDIF
RETURN
motor_step_right:
IF
switchright=1 THEN
'
DEBUG 13,"Motor go right position",DEC
switchright
IF
motorphase(x)>0 THEN
motorphase(x)=motorphase(x)-1
ELSE
motorphase(x)=MAXphase-1
ENDIF
GET
positionx, Word posx
posx=posx+1
PUT
positionx,Word posx
SHIFTOUT d1,c1,MSBFIRST,[phase(motorphase(x)) <<
4]
PULSOUT l1,1
PAUSE motorpause
GOTO
drop1 'és egyben return
ENDIF
RETURN
motor_step_bottom:
IF
switchbottom=1 THEN
'
DEBUG 13,"Motor go bottom position",DEC
switchbottom
IF
motorphase(y)>0 THEN
motorphase(y)=motorphase(y)-1
ELSE
motorphase(y)=MAXphase-1
ENDIF
GET
positiony,Word posy
IF
posy>0 THEN
posy=posy-1
ELSE
posy=0
ENDIF
PUT
positiony,Word posy
SHIFTOUT d1,c1,MSBFIRST,[phase(motorphase(y))]
PULSOUT l1,1
PAUSE motorpause
GOTO
drop1 'és egyben return
ELSE
'
DEBUG 13,"Motor in bottom position: ",DEC
switchtop
PUT
positiony,Word 0
ENDIF
RETURN
motor_step_top:
IF
switchtop=1 THEN
'
DEBUG 13,"Motor go top position",DEC
switchtop
IF
motorphase(y)<(maxphase-1) THEN
motorphase(y)=motorphase(y)+1
ELSE
motorphase(y)=0
ENDIF
GET
positiony,Word posy
posy=posy+1
PUT
positiony,Word posy
SHIFTOUT d1,c1,MSBFIRST,[phase(motorphase(y))]
PULSOUT l1,1
PAUSE motorpause
GOTO
drop1 'és egyben return
ENDIF
RETURN
drop1:
IF
penstate=1 THEN
FOR
dropi=0 TO penwidth
HIGH addr1
PULSOUT prim,40
LOW addr1
NEXT
ENDIF
RETURN
drawbox:
GOSUB
penup
GET
rectx,Word a
PUT
setpx,Word a
GET
recty,Word b
PUT
setpy,Word b
GOSUB
gotopos
GOSUB
pendown
GET
rectx,Word a
GET
rectw,Word b
PUT
setpx , Word (a+b)
GOSUB
gotopos
GET
recty,Word a
GET
recth,Word b
PUT
setpy , Word (a+b)
GOSUB
gotopos
GET
rectx,Word a
PUT
setpx, Word a
GOSUB
gotopos
GET
recty,Word b
PUT
setpy,Word b
GOSUB
gotopos
RETURN
drawline:
ax
VAR Word
ay
VAR Word
aw
VAR Word
ah
VAR Word
signw
VAR Bit
signh
VAR Bit
GET
rectx, Word a
PUT
setpx, Word a
ax=a
'200
GET
recty, Word b
PUT
setpy, Word b
ay=b
'200
GOSUB
penup
GOSUB
gotopos
GET
rectx2, Word a
'300
aw=a-ax
'200-10=190
signw=aw.BIT15
GET
recty2, Word a
'100
ah=a-ay
'200-10=190
signh=ah.BIT15
'előjel
'0
aw=ABS(aw)
ah=ABS(ah)
GOSUB
pendown
FOR
i=0 TO ah
IF signh=1 THEN
PUT setpy, Word (ay-i)
'10+0, 10+1, 10+2 ... 10+190
ELSE
PUT setpy, Word (ay+i)
'10+0, 10+1, 10+2 ... 10+190
ENDIF
IF ah=0 THEN
ah=1
ENDIF
'a=(((aw/4)*(i/4))/(ah/4))*4
a=(aw/ah)*i
'1*0,1*1
IF ABS(a)>aw THEN
a=aw
ENDIF
IF signw=1 THEN
PUT setpx, Word (ax-a)
'10+0,10+1
ELSE
PUT setpx, Word (ax+a)
'10+0,10+1
ENDIF
GOSUB gotopos
NEXT
RETURN
drawpoint:
GOSUB
penup
GOSUB
gotopos
GOSUB
pendown
GOSUB
drop1
RETURN
drawframe:
fi
VAR Nib
'PUT
rectx,Word 0,Word 0
GET
width,Word a
GET
height,Word b
'PUT
rectw,Word a,Word b
'GOSUB drawbox
penwidth=0
FOR
fi=0 TO b/100
PUT
rectx,Word 0,Word fi*100
PUT
rectx2,Word a,Word fi*100
GOSUB drawline
GET
width,Word a
GET
height,Word b
NEXT
FOR
fi=0 TO a/100
PUT
rectx,Word fi*100,Word 0
PUT
rectx2,Word fi*100,Word b
GOSUB drawline
GET
width,Word a
GET
height,Word b
NEXT
RETURN