'Decoder v1.0 'G.Heron N2APB 4/29/2007 'General purpose decoder program, selecting one of four functions specified by 'the user's setting Code0 and Code 1 switches on the Encoder board. symbol led1 = 4 symbol led2 = 2 symbol led3 = 1 symbol led4 = 0 symbol signal = pin3 symbol down = 0 symbol up = 1 symbol StartCntr = b4 symbol Code0 = bit8 ;memory bits for Code bits received symbol Code1 = bit9 '********************************************************* ' START OF PROGRAM '********************************************************* 'Read the input Signal '... if high, then we're in normal Run mode '... if low, then we're in Test mode Start: if signal = up then Decode 'if input not grounded, then we're in normal Run mode sound 0, (116,5) 'else we're in Test mode so output continuous tone goto Start Decode: high led4 'turn off all LEDs at start high led3 high led2 high led1 loop: StartCntr = 0 'Need 5 consecutive 50ms periods of '1' to detect START bit '(Don't forget we're reading inverted from what spec waveform looks like) x1: if signal = up then loop StartCntr = StartCntr +1 if StartCntr = 5 then x2 pause 50 goto x1 'Wait for low-going edge of START bit x2: if signal = down then x2 'Wait past the 50ms delimeter pause 50 ;--------------------------------------------------------------------- ;Read the two Code bits and select function 0, 1, 2 or 3 respectively. ;--------------------------------------------------------------------- n8: pause 25 'Move to the middle of the data window if signal = 1 then x3 Code0 = 1 'Code0 = 1 goto x4 x3: Code0 = 0 'Code0 = 0 x4: pause 50 if signal = 1 then x5 Code1 = 1 'Code1 = 1 goto x5a x5: Code1 = 0 'Code1 = 0 x5a: b1 = b1 & $03 'test b1 (x,x,x,x,x,x,Code1,Code0) branch b1,(Func0,Func1,Func2,Func3) 'branch to the code detected ;------------------ ;Function 0 Decoded Func0: low LED1 high LED2 high LED3 high LED4 goto loop ;------------------ ;Function 1 Decoded Func1: high LED1 low LED2 high LED3 high LED4 goto loop ;------------------ ;Function 2 Decoded Func2: high LED1 high LED2 low LED3 high LED4 goto loop ;------------------ ;Function 3 Decoded Func3: high LED1 high LED2 high LED3 low LED4 goto loop