procedure delay {
arguments_none
returns_nothing
uniform_delay delay_instructions
variable counter byte
variable temp0 byte
variable temp1 byte
watch_dog_reset
if (ir_in) {
if (counter != 0) {
# We've got a pulse:
if (counter >= 12) {
# We've got a start:
byte0 := temp0
byte1 := temp1
temp0 := 0
temp1 := 0
} else {
# Shift 10 bits:
temp0 := temp0 >> 1
temp0@7 := temp1@0
temp1 := temp1 >> 1
if (counter >= 6) {
temp1@3 := 1
}
}
}
counter := 0
} else {
counter := counter + 1
}
}