© Bueno Systems, Inc. • TSL1401-DB (2009.10.01)
Page 10 of 52
LOOP
END
' -----[ Subroutines ]-----------------------------------------------------
' -----[ GetPix ]----------------------------------------------------------
' Acquire 128 thresholded pixels from sensor chip.
' exp is the exposure time in microseconds.
GetPix:
SHIFTOUT si, clk, 0, [1\1] 'Clock out the SI pulse.
PWM clk, 128, 1 'Rapidly send 150 or so CLKs.
PULSOUT si, exp >> 1 MIN 1016 – 1016 'Wait for remaining integration time.
SHIFTOUT si, clk, 0, [1\1] 'Clock out another SI pulse.
'Read 8 words (128 bits) of data.
SHIFTIN ao, clk, LSBPRE, [pdata(0)\16, pdata(1)\16, pdata(2)\16, pdata(3)\16]
SHIFTIN ao, clk, LSBPRE, [pdata(4)\16, pdata(5)\16, pdata(6)\16, pdata(7)\16]
RETURN
' -----[ DispHdr ]---------------------------------------------------------
' Display a header to aid in identifying pixel positions.
DispHdr:
FOR i = 0 TO 12 'Display tens digits.
DEBUG DEC i DIG 0
IF i < 12 THEN DEBUG " " ELSE DEBUG CR
NEXT
FOR i = 0 TO 127 'Display ones digits.
DEBUG DEC i // 10
NEXT
RETURN
' -----[ DispPix ]---------------------------------------------------------
' Display 128 pixels: light pixels as "1"; dark, as "_".
DispPix:
FOR i = 0 TO 127
IF pixels(i) THEN DEBUG "1" ELSE DEBUG "."
NEXT
RETURN
' -----[ FindEdge ]--------------------------------------------------------
' Find the first edge within the range lptr through rptr, in the direction
' given by dir and of the type indicated by which (0 = light-to-dark;
' 1 = dark-to-light).
FindEdge:
which = 1 - which 'Look for opposite kind of pixel first.
GOSUB FindPix
which = 1 - which 'Then look for desired pixel,
' by falling through to FindPix.
' -----[ FindPix ]---------------------------------------------------------