Datasheet

Jon Waddington
105
VAR
byte housecode
byte code
OBJ
serial : "simple_Serial"
PUB init(rx, tx, house)
{initialise X10 house code and serial communications}
housecode := house << 4
serial.init(rx, tx, 4800)
PUB do(device, function) | rx
{method to perform a function on X10 devices}
repeat until rx == (($04 + (housecode + device))& $FF) 'repeat until checksum received
serial.tx($04) 'transmit header
serial.tx(housecode + device) 'transmit code
rx := serial.rx 'receive checksum
if rx == $A5 'if controller is polling system
serial.tx($C3) 'respond to polling
serial.tx($00) 'send acknowledgement of checksum
repeat until rx == $55 'wait until 'ready to receive' is received
rx := serial.rx
repeat until rx == (($06 + (housecode + function))& $FF) 'repeat until checksum received
serial.tx($06) 'transmit code
serial.tx(housecode + function) 'transmit code
rx := serial.rx 'receive checksum
serial.tx($00) 'send acknowledgement of checksum
repeat until rx := $55 'wait until 'ready to receive' is received
rx := serial.rx
PUB dim(device, d) | rx
d := (d << 3)
repeat until rx == (($04 + (housecode + device))& $FF) 'repeat until checksum received
serial.tx($04) 'transmit header
serial.tx(housecode + device) 'transmit code
rx := serial.rx 'receive checksum
if rx == $A5 'if controller is polling system
serial.tx($C3) 'respond to polling
serial.tx($00) 'send acknowledgement of checksum
repeat until rx == $55 'wait until 'ready to receive' is received
rx := serial.rx
repeat until rx == ((($06 + d) + (housecode + %0100))& $FF) 'repeat until checksum received
serial.tx($06 + d) 'transmit code
serial.tx(housecode + %0100) 'transmit code
rx := serial.rx 'receive checksum
serial.tx($00) 'send acknowledgement of checksum
repeat until rx := $55 'wait until 'ready to receive' is received
rx := serial.rx