TX Side:
Send byte value of "1" continuously with 50ms between each byte sent (1 = %00000001, as in the number right after 0, just to keep us both straight here)
Code:
DEFINE OSC 20 'Defines oscillator rate
INCLUDE "modedefs.bas"
CLEAR
LED VAR BYTE : LED = 1 : ADCON1=$ff : TRISD.0=0
LOOP: SEROUT PORTD.0,T2400,[LED] : PAUSE 50 : GOTO LOOP
END
Rx Side:
Start with the LED off. If a byte of value = %00000001 is received, turn the LED on PortB.1 on.
If a value of %0000001 is received, PortB.1 will turn on and stay on.
If something other than a value of %00000001 is received, the SERIN command will take it and PortB.2 will flash for 1/10 second then go back to trying again.
If nothing is received after 2 seconds, both LEDs will flash for 1 second then go back to trying again.
Code:
DEFINE OSC 20 'Defines oscillator
INCLUDE "modedefs.bas"
CLEAR
LED VAR BYTE : LED = 0 :ADCON1=$ff : TRISB=8
LOOP: SERIN PORTB.4,T2400,2000,nothing,[LED]
IF LED=1 THEN
PORTB.1=1
ELSE
PORTB.2 = 1 : pause 100 : PORTB.2 = 0
ENDIF
GOTO LOOP
nothing: PortB=3:pause 100:portb.0:pause 100:portb=3:pause 100:portb=0:pause 100
PortB=3:pause 100:portb.0:pause 100:portb=3:pause 100:portb=0:pause 100
PortB=3:pause 100:portb.0:pause 100:goto loop
END
Of course, this assumes all the hardware is working correctly...
Bookmarks