Sure, maybe something like this...
	Code:
	@ DEVICE XT_OSC,MCLR_OFF,LVP_OFF,WDT_OFF,PROTECT_OFF
DEFINE LOADER_USED 1
' ** Setup the Resonator Frequency, in Mhz **
Define OSC 4 
Baud con 84 ' 9600 baud rate
' ** Port configurations **
TX    VAR PORTB.5
RX    VAR PORTB.2
CLK   VAR PORTA.4
DI    Var PORTA.0
RESET VAR PORTB.6
PIEZO VAR PORTB.7
DAT VAR WORD
Idx VAR BYTE
;---------------------------------------------------------------------------
Init:
  ANSEL = 0 'Configure all pins to digital operation since not using ADC
  CMCON = 7 ' disable comparators
begin:
  low piezo
  dat = $FFF7 
  serout2 tx,baud,["1st Data = ",bin16 dat,13,10]
  GOSUB SendDat
  dat = $3
  serout2 tx,baud,["2nd Data = ",bin16 dat,13,10] 
  GOSUB SendDat
  dat = $fffe
  serout2 tx,baud,["3rd Data = ",bin16 dat,13,10]
  GOSUB SendDat
STOP
;---------------------------------------------------------------------------
SendDAT:
  LOW RESET                    ; 5ms reset pulse
  PAUSE 5
  INPUT RESET
  PAUSE 300                    ; 300ms before data
  For Idx = 15 to 0 STEP -1    ; loop thru the bits
    LOW CLK                    ;   set CLK LOW
    IF dat.0(Idx) THEN         
      INPUT DI                 ;   if bit = 1 then INPUT, not HIGH
    ELSE
      LOW DI                   ;   if bit = 0 then LOW
    ENDIF
    PAUSE 1                    ;   data settle time
    INPUT CLK                  ;   clks data on rising edge
    PAUSE 1                    ;   data read time
  NEXT Idx                     ; do rest of the bits
  INPUT DI                     ; leave data line tri-stated
RETURN
 
				
			
Bookmarks