wireless communication between two pic16f877a using uart interface

Thread Starter

syed naqvi

Joined Jun 9, 2014
1
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:

Rich (BB code):
// Lcd pinout settings
sbit LCD_RS at RD0_bit;
sbit LCD_EN at RD1_bit;
sbit LCD_D4 at RD2_bit;
sbit LCD_D5 at RD3_bit;
sbit LCD_D6 at RD4_bit;
sbit LCD_D7 at RD5_bit;
// Pin direction
sbit LCD_RS_Direction at TRISD0_bit;
sbit LCD_EN_Direction at TRISD1_bit;
sbit LCD_D4_Direction at TRISD2_bit;
sbit LCD_D5_Direction at TRISD3_bit;
sbit LCD_D6_Direction at TRISD4_bit;
sbit LCD_D7_Direction at TRISD5_bit;
unsigned long ADRead, ADRead2, tlong;
sbit SW1 at RB0_bit;
 sbit SW2 at RB1_bit;
  sbit SW3 at RB2_bit;
    sbit Led at RB6_bit;
    sbit input at RB7_bit;

    sbit rw0 at RA0_bit;
    sbit rw1 at RA1_bit;
    sbit rw2 at RA2_bit;

        sbit TXx at RC6_bit;
        sbit RXx at RC7_bit;
void main() {
     Lcd_Init();
     Lcd_Cmd(_LCD_CURSOR_OFF);
      PORTA = 0x00000000;
      TRISA = 0;
      PORTB = 0;
      TRISB = 0;
     UART1_Init(2400); // Initialize UART module at 2400 bps
     Delay_ms(100); // Wait for UART module to stabilize
   ADCON1 = 0x0E;
   ADC_Init();
     while (1) {

           ADRead = (ADC_Get_Sample(0) * 500)>> 10;
            if (ADRead>10)  {SW1=1;  SW2=1;  SW3=0;
                                                       //******* TX COMMUNICATION  ********//
          // PORTB.F1=0xFF;             //LED blink at portB RB0
          Delay_ms(1000);

          Lcd_Cmd(_LCD_CLEAR);
          Lcd_Out(1,1,"Sending");
          Delay_ms(100);


         UART1_Write(PORTA); // and send data via UART
         Delay_ms(500);
                             }
     else { Lcd_Out(1, 1, "Not Sending"); SW1=0;  SW2=0;  SW3=1;}

                }

}


Reciever Side Code:

// Lcd pinout settings
sbit LCD_RS at RD0_bit;
sbit LCD_EN at RD1_bit;
sbit LCD_D4 at RD2_bit;
sbit LCD_D5 at RD3_bit;
sbit LCD_D6 at RD4_bit;
sbit LCD_D7 at RD5_bit;

// Pin direction
sbit LCD_RS_Direction at TRISD0_bit;
sbit LCD_EN_Direction at TRISD1_bit;
sbit LCD_D4_Direction at TRISD2_bit;
sbit LCD_D5_Direction at TRISD3_bit;
sbit LCD_D6_Direction at TRISD4_bit;
sbit LCD_D7_Direction at TRISD5_bit;

unsigned long ADRead, ADRead2, tlong;
sbit SW1 at RB0_bit;
 sbit SW2 at RB1_bit;
  sbit SW3 at RB5_bit;
    sbit Led at RB6_bit;
    sbit input at RB7_bit;

    sbit rw0 at RA0_bit;
    sbit rw1 at RA1_bit;
    sbit rw2 at RA2_bit;
      sbit TXx at RC6_bit;
       sbit RXx at RC7_bit;
        char uart_rd;
void main() {

     PORTA = 0x00000000;
     TRISA = 0;
     PORTB = 0;
     TRISB = 0;
      Lcd_Init();
      Lcd_Cmd(_LCD_CLEAR);
      Lcd_Cmd(_LCD_CURSOR_OFF);


    UART1_Init(2400); // Initialize UART module at 9600bps
    Delay_ms(100); // Wait for UART module to stabilize
  
  while(1)
  {
    // Endless loop
    if (UART1_Data_Ready())
    { // If data is received,
       PORTA= UART1_Read(); // read the received data,
       PORTB.F0=0x01;
       Delay_ms(100);

      Lcd_Out(1,1,"Receiving");
      Delay_ms(100);
    }
   }
 }
 
Last edited by a moderator:

MrChips

Joined Oct 2, 2009
30,824
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.
 
Top