
' {$STAMP BS2} Change for your Stamp Type, recommend one of the faster stamps.
' {$PBASIC 2.5}
Black CON 0
White CON 255
Blue CON 3
Green CON 28
Red CON 224
Cyan CON Blue + Green
Yellow CON Green + Red
Magenta CON Blue + Red
Reset PIN 3 ' Connect ALL P0-P3 pins with 10K resistors
SData PIN 2
SClock PIN 1
CS PIN 0
dat VAR Byte
ctr VAR Word ' Used in InitLCD & Clear subroutines
x VAR Byte ' X-Coordinate (0 to 129)
y VAR Byte ' Y-Coordinate (0 to 129)
color VAR Byte ' Color to plot
' PAK-XI commands
PASSMODE CON 1 ' Only send position when asked (default)
ACTMODE CON 2 ' Send position when button clicked (not very useful for Stamp)
CLRCTR CON 3 ' Clear X,Y counters and button latch
CLRALL CON 4 ' Same as CLRCTR but also clears input buffer
GETPKT CON 5 ' Send X,Y, button latch packet (5 bytes: Xhigh, Xlow, YHigh, Ylow, Status)
GETPKTZ CON 7 ' Same as GETPKT but also clears counters
NORMMODE CON 9 ' Normal mode (same as pulling IMODE high), resets PAK
RAWMODE CON 10 ' Raw mode (same as grounding IMODE), resets PAK
ESC CON 11 ' Send next byte directly to mouse
INIT CON 13 ' Initialize mouse
LATCH CON 15 ' Read button latch and clear it
PAKRESET CON 255 ' Full reset
' Bits in status byte
YOVERMASK CON $80 ' Y overflow
XOVERMASK CON $40 ' X overflow
YSIGNMASK CON $20 ' Y Sign (1=negative)
XSIGNMASK CON $10 ' X Sign (1=negative)
'MIDBMASK CON 4 ' Middle button (note: some mice won't activate middle button w/o special commands)
RIGHTMASK CON 2 ' Right button
LEFTMASK CON 1 ' Left Button
OPIN CON 8 ' Output to PAK-Pin P8
IPIN CON 9 ' Input from PAK-Pin P9
FPIN CON 13 ' Flow control
BAUD CON 240 ' Baud rate (9600) CHANGE FOR OTHER BS
CPIN CON 200 ' DPI of the mouse (could be 800 or 200)
FRACIN CON 25 ' .0025 inch per count
' Temporary words/bytes
TW VAR Word
TB0 VAR TW.HIGHBYTE
TB1 VAR TW.LOWBYTE
TB2 VAR Byte
TB3 VAR Byte
' X&Y Raw counts
XRAW VAR Word
YRAW VAR Word
' X&Y Position
Xpos VAR Word
Ypos VAR Word
Start:
GOSUB InitLCD
GOSUB Clear
' Reset PAK-XI
SEROUT OPIN,BAUD,[PAKRESET]
PAUSE 500 ' Wait for it to happen
'Main Loop for Reading Trackpad Input
DO
' Get position report
SEROUT OPIN,BAUD,[GETPKT]
SERIN IPIN\FPIN,BAUD,[XRAW.HIGHBYTE, XRAW.LOWBYTE, YRAW.HIGHBYTE, YRAW.LOWBYTE, TB2]
'DEBUG "x=", SDEC W4, " y=", SDEC W5, " status=", HEX TB2, CR
Xpos=ABS(XRAW/CPIN)
IF Xpos>130 THEN Xpos=129
Ypos=ABS(YRAW/CPIN)
IF Ypos>130 THEN Ypos=129
'DEBUG "X=", DEC Xpos, " Y=", DEC Ypos, CR
'Insert Plot Commands
x=Xpos
y=Ypos
color=Blue
GOSUB Plot
LOOP
END
SendCommand:
SHIFTOUT SData, SClock, MSBFIRST, [0\1, dat\8]
RETURN
SendData:
SHIFTOUT SData, SClock, MSBFIRST, [255\1, dat\8]
RETURN
InitLCD:
HIGH CS
PAUSE 10
HIGH SClock
LOW SData
LOW Reset
PAUSE 1
Reset = 1
PAUSE 20
CS = 0
dat = $CA : GOSUB SendCommand
dat = $03 : GOSUB SendData
dat = 32 : GOSUB SendData
dat = 12 : GOSUB SendData
dat = $00 : GOSUB SendData
dat = $BB : GOSUB SendCommand
dat = $01 : GOSUB SendData
dat = $D1: GOSUB SendCommand
dat = $94 : GOSUB SendCommand
dat = $81 : GOSUB SendCommand
dat = 5 : GOSUB SendData
dat = $01 : GOSUB SendData
dat = $20 : GOSUB SendCommand
dat = $0F : GOSUB SendData
PAUSE 100
dat = $A7: GOSUB SendCommand
dat = $BC : GOSUB SendCommand
dat = $00 : GOSUB SendData
dat = 0 : GOSUB SendData
dat = $01 : GOSUB SendData
dat = $00 : GOSUB SendData
dat = $CE : GOSUB SendCommand
dat = 0 : GOSUB SendData
dat = 2 : GOSUB SendData
dat = 4 : GOSUB SendData
dat = 6 : GOSUB SendData
dat = 8 : GOSUB SendData
dat = 10 : GOSUB SendData
dat = 12: GOSUB SendData
dat = 15 : GOSUB SendData
dat = 0 : GOSUB SendData
dat = 2 : GOSUB SendData
dat = 4 : GOSUB SendData
dat = 6 : GOSUB SendData
dat = 8 : GOSUB SendData
dat = 10 : GOSUB SendData
dat = 12 : GOSUB SendData
dat = 15 : GOSUB SendData
dat = 0 : GOSUB SendData
dat = 5 : GOSUB SendData
dat = 10 : GOSUB SendData
dat = 15 : GOSUB SendData
dat = $25 : GOSUB SendCommand
dat = $AF : GOSUB SendCommand
PAUSE 200
FOR ctr = 0 TO 130
dat = $D6 : GOSUB SendCommand
NEXT
RETURN
Plot:
dat = $75 : GOSUB SendCommand
dat = y : GOSUB SendData
dat = 131 : GOSUB SendData
dat = $15 : GOSUB SendCommand
dat = x : GOSUB SendData
dat = 129 : GOSUB SendData
dat = $5C : GOSUB SendCommand
dat = color : GOSUB SendData
RETURN
Clear:
x = 0 : y = 0: color = Yellow: GOSUB Plot
FOR ctr = 1 TO 17424
SHIFTOUT SData, SClock, MSBFIRST, [255\1, dat\8]
NEXT
RETURN
Will the first cellphone equipped with Google's new open-source operating system, Android, go on sale by summer's end?
Will the Phoenix lander find verifiable signs of life on the surface of Mars by January 1, 2009?
Will the HTC Touch Diamond arrive in North America by September 31st?