{ Tachyon - 4D Systems uLCD-32PTU Library vs.1 NG Lordi 7/2013 } TACHYON [~ : uLCD-32PTU.fth ." uLCD-32PTU Library " ; DECIMAL \ useful constants #26 == Txp #27 == Rxp #9600 == baud $0000 == black $001F == blue $0400 == green $901A == violet $F800 == red $FD20 == orange $FFE0 == yellow $FFFF == white #0 == default #16 == bold #32 == italic #64 == inverse #128 == underline $72 == r $77 == w $61 == a #0 == font1 #1 == font2 #2 == font3 WVARIABLE handle \ utilities : start ( -- ) \ sets i/o pins & default baud Txp MASK OUTSET Rxp MASK INPUTS baud SERBAUD ; \ Peter's serial in/out routines are slightly modified to eliminate pin no. input. : SERO ( data -- ) Txp MASK SWAP 2* baudcnt @ DELTA 9 FOR WAITCNT SHROUT NEXT DROP WAITCNT OUTSET ; : SERI ( -- data ) Rxp MASK DUP baudcnt @ 2/ SWAP WAITPNE DELTA baudcnt @ DELTA 0 8 FOR SHRINP WAITCNT NEXT NIP #24 SHR ; : ack ( -- ) \ checks for ack bye $06 SERI $06 <> IF ." Error! " CR THEN ; : rword ( -- word ) \ receives a word from uLCD SERI SERI SWAP B>W ; : ack+ ( -- word ) \ leaves word sent by uLCD SERI $06 <> IF ." Error! " CR ELSE rword THEN ; : sword ( word -- ) \ sends 2 bytes (word) W>B SERO SERO ; : cmd ( hex -- ) \ sends hex serial command preceded by $FF $FF SERO SERO ; : send ( n -- ) \ sends n words to uLCD 0 DO sword LOOP ; \ display commands : clr ( -- ) \ clears display $CD cmd ack ; : mode ( n -- ) \ sets screen mode where n is 0, 1, 2, or 3 $9E cmd sword ack+ DROP ; : bgrd ( n -- ) \ sets background color to n (0-65535) $A4 cmd sword ack+ DROP clr ; : cursor ( col row -- ) \ move cursor to specified location $E9 cmd sword sword ack ; : contrast ( 1/0 -- ) \ turns display on/off $9C cmd sword ack ; : origin ( y x -- ) \ sets origin $CC cmd sword sword ack ; \ text related commands : txtc ( n -- ) \ sets text color to n (0-65535) $E7 cmd sword ack ; : txtb ( n -- ) \ sets text background color $E6 cmd sword ack+ DROP ; : txta ( n1 n2 attribute -- ) \ sets text attributes: bold, italic, inverse, underline \ where n1 sets the pixel x-gap & n2 sets the pixel y-gap $DA cmd sword ack+ $E1 cmd sword ack+ 2DROP $E2 cmd sword ack+ DROP ; : putc ( c -- ) \ sends character to display $FE cmd sword ack ; : putstr ( string_addr -- ) \ sends a string to display $00 SERO $18 SERO DUP STRLEN 0 DO DUP I + C@ SERO LOOP $00 SERO ack+ DROP ; : font ( hgt wdth font -- ) \ where font is font1, font2, or font3 $E5 cmd sword ack+ $E4 cmd sword ack+ 2DROP $E3 cmd sword ack+ DROP ; \ basic graphics commands : putx ( color y x -- ) \ sets pixel on display $C1 cmd sword sword sword ack ; : line ( color y2 x2 y1 x1 -- ) \ draws line between (x1,y1) and (x2,y2) $C8 cmd 5 send ack ; : rect ( color y2 x2 y1 x1 -- ) \ draws rectangle between (x1,y1) and (x2,y2) $C5 cmd 5 send ack ; : pline ( n -- ) \ where n is a bit pattern defining a line pattern (1 = off) $9B cmd sword ack+ DROP ; \ sd file storage commands : mount ( -- ) \ mount sd card $03 cmd ack rword 0= IF ." Not Mounted! " CR THEN ; : unmount ( -- ) \ unmount sd card $02 cmd ack ; : fopen ( mode string_address -- ) \ where mode is r, w, or a, saves handle $00 SERO $OA SERO 8 0 DO DUP I + C@ SERO LOOP DROP $00 SERO SERO ack+ handle W! ; : fclose ( file_handle -- ) $18 cmd sword ack+ 0= IF ." Not Closed!" CR THEN ; : capture ( file_handle -- ) \ save full screen to sd - landscape mode 1 $10 cmd 0 sword 0 sword 239 sword 319 sword sword ack+ 0= IF " Successful! " THEN ; : display ( file_handle -- ) \ display image stored on sd $11 cmd 0 sword 0 sword sword ack+ DROP ; \ touch screen commands : tdetect ( y2 x2 y1 x1 -- ) \ define touch detect region between (x1,y1) and (x2,y2) $39 cmd 4 send ack ; : tset ( mode -- ) \ set touch mode - 0, 1, or 2 $38 cmd sword ack ; : tget ( mode -- x/y coord ) \ mode 0: return state of touch screen - 0, 1, 2, or 3 \ mode 1 - x coordinate mode 2 - y coordinate $37 cmd sword ack+ ; ]~ END