wireless communication between two pic16f877a using uart interface

Discussion in 'Embedded Systems and Microcontrollers' started by syed naqvi, Jun 9, 2014.

  1. syed naqvi

    Thread Starter New Member

    Jun 9, 2014
    1
    0
    hi
    im trying to do wireless transmission between two pic16f877a microcontrollers using uart interface. the rf module used is of 433 MHz, antenna length is 34cm and baud rate is set to 2400 bps.

    when the output port of transmitter side µc gets high logic value, the led connected to this output port glows. RF Tx now has to transmit to Rx the high logic value 1, the µc on reciever side in turn glows led connected to it.
    wired communication is doing good but problem occurs with wireless transmission. infact nothing happens when tried to transmit wirelessly.
    plz some one help me.give any suggestion, any tip to do wireless transmission.
    code in mikroc is given below.

    Transmitter side code:

    Code ( (Unknown Language)):
    1.  
    2. // Lcd pinout settings
    3. sbit LCD_RS at RD0_bit;
    4. sbit LCD_EN at RD1_bit;
    5. sbit LCD_D4 at RD2_bit;
    6. sbit LCD_D5 at RD3_bit;
    7. sbit LCD_D6 at RD4_bit;
    8. sbit LCD_D7 at RD5_bit;
    9. // Pin direction
    10. sbit LCD_RS_Direction at TRISD0_bit;
    11. sbit LCD_EN_Direction at TRISD1_bit;
    12. sbit LCD_D4_Direction at TRISD2_bit;
    13. sbit LCD_D5_Direction at TRISD3_bit;
    14. sbit LCD_D6_Direction at TRISD4_bit;
    15. sbit LCD_D7_Direction at TRISD5_bit;
    16. unsigned long ADRead, ADRead2, tlong;
    17. sbit SW1 at RB0_bit;
    18.  sbit SW2 at RB1_bit;
    19.   sbit SW3 at RB2_bit;
    20.     sbit Led at RB6_bit;
    21.     sbit input at RB7_bit;
    22.  
    23.     sbit rw0 at RA0_bit;
    24.     sbit rw1 at RA1_bit;
    25.     sbit rw2 at RA2_bit;
    26.  
    27.         sbit TXx at RC6_bit;
    28.         sbit RXx at RC7_bit;
    29. void main() {
    30.      Lcd_Init();
    31.      Lcd_Cmd(_LCD_CURSOR_OFF);
    32.       PORTA = 0x00000000;
    33.       TRISA = 0;
    34.       PORTB = 0;
    35.       TRISB = 0;
    36.      UART1_Init(2400); // Initialize UART module at 2400 bps
    37.      Delay_ms(100); // Wait for UART module to stabilize
    38.    ADCON1 = 0x0E;
    39.    ADC_Init();
    40.      while (1) {
    41.  
    42.            ADRead = (ADC_Get_Sample(0) * 500)>> 10;
    43.             if (ADRead>10)  {SW1=1;  SW2=1;  SW3=0;
    44.                                                        //******* TX COMMUNICATION  ********//
    45.           // PORTB.F1=0xFF;             //LED blink at portB RB0
    46.           Delay_ms(1000);
    47.  
    48.           Lcd_Cmd(_LCD_CLEAR);
    49.           Lcd_Out(1,1,"Sending");
    50.           Delay_ms(100);
    51.  
    52.  
    53.          UART1_Write(PORTA); // and send data via UART
    54.          Delay_ms(500);
    55.                              }
    56.      else { Lcd_Out(1, 1, "Not Sending"); SW1=0;  SW2=0;  SW3=1;}
    57.  
    58.                 }
    59.  
    60. }
    61.  
    62.  
    63. Reciever Side Code:
    64.  
    65. // Lcd pinout settings
    66. sbit LCD_RS at RD0_bit;
    67. sbit LCD_EN at RD1_bit;
    68. sbit LCD_D4 at RD2_bit;
    69. sbit LCD_D5 at RD3_bit;
    70. sbit LCD_D6 at RD4_bit;
    71. sbit LCD_D7 at RD5_bit;
    72.  
    73. // Pin direction
    74. sbit LCD_RS_Direction at TRISD0_bit;
    75. sbit LCD_EN_Direction at TRISD1_bit;
    76. sbit LCD_D4_Direction at TRISD2_bit;
    77. sbit LCD_D5_Direction at TRISD3_bit;
    78. sbit LCD_D6_Direction at TRISD4_bit;
    79. sbit LCD_D7_Direction at TRISD5_bit;
    80.  
    81. unsigned long ADRead, ADRead2, tlong;
    82. sbit SW1 at RB0_bit;
    83.  sbit SW2 at RB1_bit;
    84.   sbit SW3 at RB5_bit;
    85.     sbit Led at RB6_bit;
    86.     sbit input at RB7_bit;
    87.  
    88.     sbit rw0 at RA0_bit;
    89.     sbit rw1 at RA1_bit;
    90.     sbit rw2 at RA2_bit;
    91.       sbit TXx at RC6_bit;
    92.        sbit RXx at RC7_bit;
    93.         char uart_rd;
    94. void main() {
    95.  
    96.      PORTA = 0x00000000;
    97.      TRISA = 0;
    98.      PORTB = 0;
    99.      TRISB = 0;
    100.       Lcd_Init();
    101.       Lcd_Cmd(_LCD_CLEAR);
    102.       Lcd_Cmd(_LCD_CURSOR_OFF);
    103.  
    104.  
    105.     UART1_Init(2400); // Initialize UART module at 9600bps
    106.     Delay_ms(100); // Wait for UART module to stabilize
    107.  
    108.   while(1)
    109.   {
    110.     // Endless loop
    111.     if (UART1_Data_Ready())
    112.     { // If data is received,
    113.        PORTA= UART1_Read(); // read the received data,
    114.        PORTB.F0=0x01;
    115.        Delay_ms(100);
    116.  
    117.       Lcd_Out(1,1,"Receiving");
    118.       Delay_ms(100);
    119.     }
    120.    }
    121.  }
    122.  
    123.  
     
    Last edited by a moderator: Jun 9, 2014
  2. MrChips

    Moderator

    Oct 2, 2009
    12,449
    3,364
    It would help if your provided the make and model numbers of the RF modules.

    If both transmitter and receiver modules expect high logic to transmit and receive, you will have to invert the logic with transistors or logic inverters.
     
  3. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
Loading...