A PIC program for control NEXA 230V Switch with a PIC and the parallax RF transmitter
Bruce from www.rentron.com helpt me write this code, actually he wrote the hole code to me



Pictures are from
www.nexa.se and www.parallax.com

Code:
<html>
<head></head>
<body><!--StartFragment--><pre><code><font color="#000080"><i>'****************************************************************
'*  Name    : NEXA RemoteControl                                *
'*  Notice  : Copyright (c) 2008 [select VIEW...EDITOR OPTIONS] *
'*          : All Rights Reserved                               *
'*  Date    : 2008-12-30                                        *
'*  Version : 1.0                                               *
'*  Notes   : PIC 16F872 @ 20 Mhz                               *
'*          :                                                   *
'****************************************************************

</i></font><font color="#008000"><b>DEFINE </b></font>OSC 20

T <font color="#008000"><b>CON </b></font>350      <font color="#000080"><i>' T = 350uS
</i></font>T3 <font color="#008000"><b>CON </b></font>1050    <font color="#000080"><i>' 3T
</i></font>T32 <font color="#008000"><b>CON </b></font>11200  <font color="#000080"><i>' 32T (Stop/Synch)

' Note we're using 1 VS X as shown in text
</i></font>A1_ON  <font color="#008000"><b>CON </b></font>%111000000000 <font color="#000080"><i>' 12-bit code for House/Unit A1 ON
</i></font>A1_OFF <font color="#008000"><b>CON </b></font>%011000000000 <font color="#000080"><i>' 12-bit code for House/Unit A1 OFF 
'           ||||||||||||____ 4-bit House code
'           ||||||||________ 4-bit Unit code
'           ||||____________ 3-bit Unknown code
'           |_______________ 1-bit Activation code 1=ON 0=OFF 
'
'        House code  Unit Code 
'       ------------------------
'       | 0000 - A | 0000 - 1  |   
'       | X000 - B | X000 - 2  |
'       | 0X00 - C | 0X00 - 3  |
'       | XX00 - D | XX00 - 4  |
'       | 00X0 - E | 00X0 - 5  |
'       | X0X0 - F | X0X0 - 6  |
'       | 0XX0 - G | 0XX0 - 7  |
'       | XXX0 - H | XXX0 - 8  |
'       | 000X - I | 000X - 9  |
'       | X00X - J | X00X - 10 |
'       | 0X0X - K | 0X0X - 11 |
'       | XX0X - L | XX0X - 12 | 
'       | 00XX - M | 00XX - 13 |
'       | X0XX - N | X0XX - 14 |
'       | 0XXX - O | 0XXX - 15 |
'       | XXXX - P | XXXX - 16 |
'       ------------------------

</i></font>D_PACKET <font color="#008000"><b>VAR WORD </b></font><font color="#000080"><i>' Holds 12-bit data packet to send
</i></font>INDEX <font color="#008000"><b>VAR BYTE    </b></font><font color="#000080"><i>' Data packet bit index pointer
</i></font>LOOPS <font color="#008000"><b>VAR BYTE    </b></font><font color="#000080"><i>' Loop counter

</i></font>TX <font color="#008000"><b>VAR </b></font>PORTB.0    <font color="#000080"><i>' Connects to RF transmitter data in

</i></font><font color="#008000"><b>LOW </b></font>TX            <font color="#000080"><i>' TX output idles low for RF carrier OFF

</i></font>Main:
    D_PACKET = A1_ON
    <font color="#008000"><b>GOSUB </b></font>Send
    <font color="#008000"><b>PAUSE </b></font>5000
    D_PACKET = A1_OFF
    <font color="#008000"><b>GOSUB </b></font>Send
    <font color="#008000"><b>PAUSE </b></font>5000
    <font color="#008000"><b>GOTO </b></font>Main
    
Send:
    <font color="#008000"><b>FOR </b></font>LOOPS = 1 <font color="#008000"><b>TO </b></font>4    <font color="#000080"><i>' send each packet 4 times
      </i></font><font color="#008000"><b>FOR </b></font>INDEX = 0 <font color="#008000"><b>TO </b></font>11 <font color="#000080"><i>' sends 12 bits per pass LSB 1st
        
        </i></font><font color="#008000"><b>HIGH </b></font>TX           <font color="#000080"><i>' The 1st half of a 0 or X  bit period is the
        </i></font><font color="#008000"><b>PAUSEUS </b></font>T         <font color="#000080"><i>' same so no need to repeat this sequence inside
        </i></font><font color="#008000"><b>LOW </b></font>TX            <font color="#000080"><i>' the IF block
        </i></font><font color="#008000"><b>PAUSEUS </b></font>T3 
        
        <font color="#008000"><b>IF </b></font>D_PACKET.0[INDEX]=1 <font color="#008000"><b>THEN
           HIGH </b></font>TX        <font color="#000080"><i>' send a 1 bit (1=X here)
           </i></font><font color="#008000"><b>PAUSEUS </b></font>T3
           <font color="#008000"><b>LOW </b></font>TX
           <font color="#008000"><b>PAUSEUS </b></font>T
        <font color="#008000"><b>ELSE
           HIGH </b></font>TX        <font color="#000080"><i>' send a 0 bit
           </i></font><font color="#008000"><b>PAUSEUS </b></font>T
           <font color="#008000"><b>LOW </b></font>TX
           <font color="#008000"><b>PAUSEUS </b></font>T3
        <font color="#008000"><b>ENDIF
      NEXT </b></font>INDEX          <font color="#000080"><i>' loop until all 12-bits sent
      
      ' Start of Stop/Synch period after each 12-bit packet
      </i></font><font color="#008000"><b>HIGH </b></font>TX
      <font color="#008000"><b>PAUSEUS </b></font>T
      <font color="#008000"><b>LOW </b></font>TX
      <font color="#008000"><b>PAUSEUS </b></font>T32
      <font color="#000080"><i>' End of Stop/Synch period
      
    </i></font><font color="#008000"><b>NEXT </b></font>LOOPS        <font color="#000080"><i>' send 4 packets per pass
    </i></font><font color="#008000"><b>RETURN
      
    END
</b></font></code></pre><!--EndFragment--></body>
</html>