PIC12F program mod

Discussion in 'Embedded Systems and Microcontrollers' started by seesoe, Apr 30, 2011.

  1. seesoe

    Thread Starter Active Member

    Dec 7, 2008
    99
    0
    hello, im working on 3 button rf remote control system, my final circuit design can be found at the bottom of page 2 on my circuit design thread. this is my first time programming a pic, actually any ic for that matter.

    the website said that when a button is pressed on the transmitter the corresponding relay (for programmings sake) will turn on, and if another is pressed it will turn on as well, then if the same corresponding button is pressed it will turn off, everything works separately.

    what i want it to do is, on power up, relay 1 by default is on and 2 and 3 are off. then for example if button 3 is pressed, relay 1 will turn off and relay 3 will turn on. i want only 1 relay to stay on at a time

    the code is written in c, (which i haven't learned yet) and i can't seem to figure out how to change what i want done, can someone please help me on that?

    also on page 16 of my thread, pencil said that because of the type of mosfet used, the operation of the uc must be changed, how exactly would i do that? just reverse the pin's output?

    thank you in advanced!
    seesoe

    Code ( (Unknown Language)):
    1. //---------------------------------
    2. // Receiver for RF remote control project
    3. // (c) www.CoolCircuit.com
    4. //---------------------------------
    5. #include<pic.h>
    6. #include"delay.h"
    7.  
    8. __CONFIG(XT&MCLRDIS&WDTDIS);
    9.  
    10. #define Header    0x20
    11. #define RX  GP3
    12. #define out1 GP0
    13. #define out2 GP1
    14. #define out3 GP2
    15.  
    16. unsigned char RXREG[3];
    17. unsigned char toggle=0x00;
    18. unsigned char old_toggle=0x00;
    19. #define Channel RXREG[1]
    20.  
    21. bit get_data(unsigned char *buff);
    22.  
    23.  
    24. bit rx_bit;
    25.  
    26. void main()
    27. {
    28.    
    29.     DelayBigUs(580);
    30.     GPIO=0x00;
    31.     TRIS=0B00001000;
    32.     OPTION=0x03;    
    33.    
    34.     while(1)
    35.     {    
    36.         while(get_data(RXREG));
    37.         if (RXREG[2]==(RXREG[0] ^ RXREG[1]))
    38.         {
    39.             if (RXREG[0]==Header)
    40.             {
    41.                 toggle = RXREG[1] & 0x80;
    42.                 if (toggle!=old_toggle)
    43.                 {
    44.                     old_toggle=toggle;
    45.                     RXREG[1]=RXREG[1] & 0x03;
    46.                     if (RXREG[1]==0x01) out1=!out1;
    47.                     if (RXREG[1]==0x02) out2=!out2;
    48.                     if (RXREG[1]==0x03) out3=!out3;
    49.                 }
    50.             }
    51.         }
    52.         //DelayMs(50);
    53.     }
    54. }    
    55.  
    56.  
    57. bit get_data(unsigned char *buff)
    58. {
    59.     unsigned char i,j,T0,count;    
    60.    
    61.     i=35;        
    62.     count=0;    
    63.     OPTION=0x00;    // pre scaler = 2 for counting long time
    64.  
    65.     while(--i)    // wait preamble
    66.     {            
    67.          NOP();
    68.          NOP();
    69.          NOP();
    70.          while(RX);        
    71.          TMR0=0;
    72.          NOP();
    73.          NOP();
    74.          NOP();
    75.          while(!RX);
    76.          T0=TMR0;
    77.          if (T0==0xFF) return 1;      // error
    78.          if ((T0>=198) && (T0<=218))      // 396-432 uS it OK.  
    79.          {
    80.             count++;
    81.             if ((count>=1)|| (i==0)) break;
    82.          }        
    83.     }
    84.    
    85.     if (i==0) return 1; // error                
    86.        
    87.     OPTION=0x03;    // prescaler = 16
    88.     //OPTION=0x04;    // prescaler = 32
    89.     T0=0;
    90.     while (!((T0>=94) && (T0<=114)))         // 1504 - 1824 uS it OK. syn bit for 4Te or 1664 uS
    91.     //while (!((T0>=158) && (T0<=180)))         // 5056 - 5760 uS it OK. syn bit for 4Te or 5416=5mS+ (4*416uS) uS
    92.     {
    93.         NOP();
    94.         NOP();
    95.          NOP();
    96.         while(RX);    // wait syn
    97.         TMR0=0;
    98.         NOP();
    99.         NOP();
    100.         NOP();
    101.          NOP();
    102.         while(!RX);
    103.         T0=TMR0;    
    104.     }    
    105.        
    106.     while(RX);             //wait start bit go low
    107.     DelayBigUs(580);     // delay 624 uS before sampling (1.5Te)
    108.    
    109.     for (j=0;j<3;j++)
    110.     {
    111.       i=8;
    112.       buff[j]=0;
    113.       while(i--)
    114.       {
    115.         buff[j]=buff[j]<<1;
    116.         rx_bit=RX;    // sampling
    117.         buff[j]=buff[j] | rx_bit;            
    118.        
    119.         if (rx_bit==0)
    120.            while(!RX);    
    121.         else
    122.            while(RX);
    123.         DelayBigUs(580);     // delay 7500 uS before sampling        
    124.        
    125.       }
    126.     }
    127.    
    128.     if (rx_bit==0)
    129.         if (!RX) return 1; // error (no stop bit found)
    130.     else
    131.         if (!RX) return 1; // error (no stop bit found)
    132.        
    133.     return 0;
    134. }
     
  2. Pencil

    Active Member

    Dec 8, 2009
    271
    38
    Additional information attached.

    Left is original original schematic.
    Right is OP's new schematic.
     
    seesoe likes this.
Loading...