Please help ? RF Remote Source code


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2007
    Posts
    2

    Default Please help ? RF Remote Source code

    Why ???? can not work .
    I think , problem is in recived source code.
    Can you help me.
    Thanks.

    /*Description RF Remote Transmitter*/
    /* SEND */
    /********** SETUP & I/O **********/
    #include <12f629.h>
    #fuses INTRC_IO // Internal RC Osc, no CLKOUT
    #fuses WDT // Watch Dog Timer
    #fuses PUT // Power Up Timer
    #fuses NOMCLR // Master Clear pin used for I/O
    #fuses NOBROWNOUT // No brownout reset
    #fuses NOCPD // No EE protection
    #fuses NOPROTECT // Code not protected from reading
    #use delay (clock=4000000)

    #define DATA PIN_A5
    #define LED PIN_A4
    #define KEY1 PIN_A0
    #define KEY2 PIN_A1

    /********** TXRUN FUNCTION **********/
    void tx0 (void) { // send bit 0
    output_high (DATA);
    delay_us (250);
    output_low (DATA);
    delay_us (250);
    }
    void tx1 (void) { // send bit 1
    output_high (DATA);
    delay_us (500);
    output_low (DATA);
    delay_us (500);
    }

    void txbyte (char x) { // send one byte
    char i;
    for (i=0;i<=7;i++) {
    if ((x & 1)==1) tx1 (); else tx0 ();
    x >>= 1;
    }
    }

    void txsend (char x) {
    char a,b,c;
    c = 0x53;
    b = 0x35;
    a = 0;
    //address 0-255
    txbyte (0); // preamble
    txbyte (0);
    tx1 (); // start
    txbyte (c); // code 1
    txbyte (b); // code 2
    txbyte (a); // address
    txbyte (x); // command
    tx0 (); // end
    output_low (LED);
    delay_ms (250);
    output_high (LED);
    delay_ms (250);
    }
    /********** MAIN FUNCTION **********/
    void start (void)
    {
    //setup_wdt(WDT_2304MS);
    delay_ms(100);
    }
    void main (void) {
    char f;
    start ();
    port_a_pullups(true);
    set_tris_a(0x0F); // set trisa output
    restart_wdt();
    f = 0;
    while (1)
    {
    //sleep();
    restart_wdt();
    if (f==0)
    {
    if (input (KEY1)==0) {txsend (0x1); f = 1;}
    else if (input (KEY2)==0) {txsend (0x2); f = 1;}
    }
    if (input (KEY1) && input (KEY2)) {f = 0; delay_ms (100);}

    }
    }

    _________________________________________

    /*Description RF Remote Transmitter*/
    /* Recieved */
    /********** SETUP & I/O **********/
    #include <12f629.h>
    #fuses INTRC_IO // Internal RC Osc, no CLKOUT
    #fuses NOWDT // No Watch Dog Timer
    #fuses PUT // Power Up Timer
    #fuses NOMCLR // Master Clear pin used for I/O
    #fuses NOBROWNOUT // No brownout reset
    #fuses NOCPD // No EE protection
    #fuses NOPROTECT // Code not protected from reading
    #use delay (clock=4000000)
    //#byte OSCCON = 0x8F

    #define DATA PIN_A0
    #define REL1 PIN_A4
    #define REL2 PIN_A5

    /********** RXRUN FUNCTION **********/
    int16 rxbit (void) { // check bit cycle
    int16 x;
    x = 0;
    while (input (DATA)==1) x++;
    while (input (DATA)==0) x++;
    return (x);
    }

    void rxpre (void) { // check preamble
    int16 x;
    char c;
    c = 0;
    while (c<5) { // check bit 0
    x = rxbit ();
    if (x>=33 && x<=37) c++; else c = 0;
    }
    while (x<53) {
    x = rxbit (); // check bit 1
    }
    }

    char rxbyte (void) { // read one byte
    char x,i;
    x = 0;
    for (i=0;i<=7;i++) {
    x >>= 1;
    if (rxbit ()>53) x |= 0x80;
    }
    return (x);
    }

    char rxrecv (void) {
    char i,j,a,aa,bb,cc,x;
    cc = 0x53;
    bb = 0x35;
    aa = 0;
    rxpre ();
    i = rxbyte ();
    j = rxbyte ();
    a = rxbyte ();
    x = rxbyte ();
    if (i==cc && j==0xbb && a==aa)return (x); // match
    else return (0xff); // not match
    }

    /********** MAIN FUNCTION **********/
    void start (void) {
    port_a_pullups(true);
    set_tris_a(0x09); // set trisa output
    delay_ms (200);
    }

    void main (void) {
    char x,a,b,c;
    start ();
    a = 0;
    b = 0;
    c = 0;
    output_bit (REL1,a);
    output_bit (REL2,b);
    while (1) {
    x = rxrecv ();
    if (x==0x1)
    {
    if (a==0 && b==0) a = 1;
    else {a = 0;b=0;}
    output_bit (REL1,a);
    output_bit (REL2,b);
    }
    else if (x==0x2)
    {
    if (b==0 && a==0) b = 1;
    else{b = 0;a=0;}
    output_bit (REL2,b);
    output_bit (REL1,a);
    }
    }
    }

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    mmm, sorry, BASIC forum here, not C
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Talking

    Quote Originally Posted by sorasit46 View Post
    Why ???? can not work .
    I think , problem is in recived source code.
    Can you help me.
    Thanks.
    How did you get that to compile with PicBasicPro?
    I want that version!

  4. #4
    Join Date
    Apr 2007
    Posts
    2


    Did you find this post helpful? Yes | No

    Default oh! sorry

    Wrong forums.
    I'm use pic c compiler.

Similar Threads

  1. Problem runing my code
    By Mus.me in forum mel PIC BASIC Pro
    Replies: 33
    Last Post: - 1st December 2009, 20:36
  2. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  3. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  4. code source
    By meyou in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 9th August 2004, 21:01
  5. accessing source code
    By mle in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 21st July 2003, 14:25

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts