Cut'n'paste from your program, relevant parts marked with red.
Pin aliases:
Code:
Clk VAR PORTC.4
Sda VAR PORTC.5
Csn VAR PORTC.3
Variable assignment and call to Send routine:
Code:
WData = $1877: GOSUB Send
Send routine, calls OutByte:
Code:
Send:
GOSUB StartCommunication
GOSUB OutByte
GOSUB StopCommunication
RETURN
Outbyte iterates thru wData and calls either SendOne or SendZero depending on if the bit is a one or a zero:
Code:
OutByte: 'send a 16 bit word
FOR Bit_Counter = 1 TO 16
IF wData.15 = 1 THEN 'MSB first
GOSUB SendOne
ELSE
GOSUB SendZero
ENDIF
WData = wData << 1
NEXT Bit_Counter
RETURN
Sendone:
Code:
SendOne: 'Send a bit 0
HIGH Sda: GOSUB WasteTime
LOW Clk: GOSUB WasteTime
HIGH Clk: GOSUB WasteTime
RETURN
Sendzero:
Code:
SendZero: 'sending a bit 1
LOW Sda: GOSUB WasteTime
LOW Clk: GOSUB WasteTime
HIGH Clk: GOSUB WasteTime
HIGH Sda: GOSUB WasteTime
RETURN
/Henrik.
Bookmarks