Wireless Data Transmission

General discussion on mikroC.
Post Reply
Author
Message
PIGBAOBAO
Posts: 7
Joined: 16 Oct 2010 17:28

Wireless Data Transmission

#1 Post by PIGBAOBAO » 31 Oct 2010 04:29

Hi everyone,

I am doing a wireless project by using RF module (transmitter and receiver - 315MHz) and PIC16F877A (Mikro-c compiler). Now I was developed a program and simulated successful for my RF receiver part. Below is my receiver side program;


// LCD module connections
sbit LCD_RS at RD4_bit;
sbit LCD_EN at RD5_bit;
sbit LCD_D4 at RD0_bit;
sbit LCD_D5 at RD1_bit;
sbit LCD_D6 at RD2_bit;
sbit LCD_D7 at RD3_bit;
sbit LCD_RS_Direction at TRISD4_bit;
sbit LCD_EN_Direction at TRISD5_bit;
sbit LCD_D4_Direction at TRISD0_bit;
sbit LCD_D5_Direction at TRISD1_bit;
sbit LCD_D6_Direction at TRISD2_bit;
sbit LCD_D7_Direction at TRISD3_bit;
// End LCD module connections

#define click_button RA1

unsigned int num;
char string1[]= "Welcome";
char string2[]= "Final Year Project";
char string3[]= "Wireless Data Transmission";
char string4[]= "Thank You";

char *string;

void Move_Delay() { // Function used for text moving
Delay_ms(500); // You can change the moving speed here
}


void main() {
int i=0;
TRISA = 0xFF; //configure PORTA as input
TRISB = 0xf0; //configure PORTB as input
PORTC = 0; //LED
TRISC = 0;
TRISD = 0;
PORTD = 0x00;
TRISD = 0x00;

Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,3,"Wireless Data");
Lcd_Out(2,4,"Transmission");
Delay_ms(3000);
Lcd_Cmd(_LCD_CLEAR); // Clear display

while(1)
{
if((portb.f0==0)&&(i==0))
{
Lcd_Cmd(_lcd_clear);
Lcd_Out(1,7,string1);
i++;
}
if((portb.f0==0)&&(i==1))
{
Lcd_Cmd(_lcd_clear);
Lcd_Out(1,1,string2);
i++;
}
if((portb.f0==0)&&(i==2))
{
Lcd_Cmd(_lcd_clear);
Lcd_Out(1,1,string3);
i++;
}
if((portb.f0==0)&&(i==3))
{
Lcd_Cmd(_lcd_clear);
Lcd_Out(1,1,string4);
i=0;
}
}
}


But, the problem is I was confused and not understand about how is a transmitter program should be i used for make the receiver part operate by using RF since the Transmitter part cannot be shown how it work if simulated in Proteus Professional. Can you give me some suggestion or idea about my problem and if can give me a example of transmitter based on my program above?

On the other hand, could my project work perfectly without using UART_write or UART_read (UART) :D in transmitter and receiver program??

Thanks for your help, I am really appreciate it! :D

KaranSoin
Posts: 130
Joined: 07 May 2010 22:27
Location: Melbourne, Australia

Re: Wireless Data Transmission

#2 Post by KaranSoin » 01 Nov 2010 09:34

Which RF modules are you using ? Lot of the RF modules have UART integrated into them, others you have to use a special decoder chip.

PIGBAOBAO
Posts: 7
Joined: 16 Oct 2010 17:28

Re: Wireless Data Transmission

#3 Post by PIGBAOBAO » 01 Nov 2010 11:03

I have using CYTRON product RF Transmitter and Receiver (315MHz).

What i mean is am i necessary write a program that have include the uart ?

I briefly explain what is my project going to. It is a simple wireless project, i just need to pressed a button and this digital signal will be transmit to receiver and shown the charater i have been set on the LCD display.

I was trouble in writing code to perform this function. Hope you all can help.

KaranSoin
Posts: 130
Joined: 07 May 2010 22:27
Location: Melbourne, Australia

Re: Wireless Data Transmission

#4 Post by KaranSoin » 02 Nov 2010 13:34

Yes, you need UART to do the data transmission. Not using the UART may not be worth the effort. So what I understand is that you have 4 messages on the transmitter side, and you want send each of them to the receiver side one by one on press of a button, and display them on an LCD attached to the receiver side ? Do you have a schematics of your circuit ?


Regards

PIGBAOBAO
Posts: 7
Joined: 16 Oct 2010 17:28

Re: Wireless Data Transmission

#5 Post by PIGBAOBAO » 07 Dec 2010 16:08

Hi friend,

Sorry for late reply. Ya you are right.
Now my problem is when i was pressed the button at transmitter side but the string cannot show a LCD at receiver side.
Here is my trasnmitter coding, receiver coding and my schematic diagram (proteus).
schematic.png
schematic.png (65.96 KiB) Viewed 7097 times
Transmitter side....

Code: Select all

  #define   click_button   RA1

   char string1[]= "Welcome";
  char string2[]= "Final Year";
  char string3[]= "Project";
  char string4[]= "Wireless Data";
  char string5[]= "Transmission";
  char string6[]= "Thank You";
  unsigned int i;

 void main()
 {
     int k=0,m=0;
  ADCON1 = 0;               //configure PortA as digital I/O
  TRISA = 0x3F;             //configure PORTA as input
  TRISB = 0x0f;             //configure PORTB as input
  TRISC = 0x80;             //configure pin7 as input(RX), pin6 as output(TX)
   portb.f4=1;
  Usart_Init(9600);               // Initialize UART module at 9600 bps
 // Delay_ms(100);                  // Wait for UART module to stabilize


    while(1)
    {
      if ((click_button==1)&&(k==0))
      {
         m=strlen(string1);
        for(i=0;i<m;i++)
        {
        usart_write(string1[i]);

      //  Delay_ms(1000);
        }
         k++;
      }
        if ((click_button==1)&&(k==1))
      {
       m=strlen(string2);
        for(i=0;i<m;i++)
        {
        usart_write(string2[i]);

      //  Delay_ms(1000);
        }
         k++;
      }
       if ((click_button==1)&&(k==2))
      {
       m=strlen(string3);
        for(i=0;i<7;i++)
        {
        usart_write(string3[i]);

      //  Delay_ms(1000);
        }
          k++;
      }
       if ((click_button==1)&&(k==3))
      {
       m=strlen(string4);
        for(i=0;i<7;i++)
        {
        usart_write(string4[i]);

      //  Delay_ms(1000);
        }
         k++;
      }
       if ((click_button==1)&&(k==4))
      {
       m=strlen(string5);
        for(i=0;i<7;i++)
        {
        usart_write(string5[i]);

      //  Delay_ms(1000);
        }
         k++;
      }
       if ((click_button==1)&&(k==5))
      {
       m=strlen(string6);
        for(i=0;i<7;i++)
        {
        usart_write(string6[i]);

      //  Delay_ms(1000);
        }
        k=0;
      }


      
      
}
}
This is receiver coding...

Code: Select all

// LCD module connections
sbit LCD_RS at RD4_bit;
sbit LCD_EN at RD5_bit;
sbit LCD_D4 at RD0_bit;
sbit LCD_D5 at RD1_bit;
sbit LCD_D6 at RD2_bit;
sbit LCD_D7 at RD3_bit;

sbit LCD_RS_Direction at TRISD4_bit;
sbit LCD_EN_Direction at TRISD5_bit;
sbit LCD_D4_Direction at TRISD0_bit;
sbit LCD_D5_Direction at TRISD1_bit;
sbit LCD_D6_Direction at TRISD2_bit;
sbit LCD_D7_Direction at TRISD3_bit;
// End LCD module connections

#define   click_button   RA1


unsigned int num;
char string1[]= "Welcome";
char string2[]= "Final Year";
char string3[]= "Project";
char string4[]= "Wireless Data";
char string5[]= "Transmission";
char string6[]= "Thank You";


char *string;

void Move_Delay() { // Function used for text moving
Delay_ms(500); // You can change the moving speed here
}

 void main() {

  int i=0;
  ADCON1= 0x06;             //configure PortA as digital I/O

  TRISA = 0xf3;             //configure PORTA as input
  TRISB = 0x00;             //configure PORTB as output
  TRISC = 0b10111111;             //configure pin7 as input(RX), pin6 as output(TX)
  PORTD = 0x00;             //configure PORTD as output
  TRISD = 0x00;

  UART1_Init(9600);              // Initialize UART module at 9600 bps
  Delay_ms(100);                 // Wait for UART module to stabilize


Lcd_Init(); // Initialize LCD

Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,3,"Wireless Data");
Lcd_Out(2,3,"Transmission");
Delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR); // Clear display

while(1)
{

if((UART1_Data_Ready())&&(i==0))      // If data is received through UART
{
string = UART1_Read();
Lcd_Cmd(_lcd_clear);
Lcd_Out(1,6,string1);
Delay_ms(1000);
i++;
}
if((UART1_Data_Ready())&&(i==1))      // If data is received through UART
{
string = UART1_Read();
Lcd_Cmd(_lcd_clear);
Lcd_Out(1,4,string2);
Lcd_out(2,6,string3);
Delay_ms(1000);
i++;
}
if((UART1_Data_Ready())&&(i==2))
{
string = UART1_Read();
Lcd_Cmd(_lcd_clear);
Lcd_Out(1,3,string4);
Lcd_out(2,3,string5);
Delay_ms(1000);
i++;
}
if((UART1_Data_Ready())&&(i==3))
{
string = UART1_Read();
Lcd_Cmd(_lcd_clear);
Lcd_Out(1,4,string6);
Delay_ms(1000);
i=0;
}
}
}
Sir I need your help...Thank!

KaranSoin
Posts: 130
Joined: 07 May 2010 22:27
Location: Melbourne, Australia

Re: Wireless Data Transmission

#6 Post by KaranSoin » 11 Dec 2010 23:49

Ok, there could be whole bunch of things that could be troublesome here, lets start with schematics:

- on ur Xmitter side, the MCLR pin is floating, unless u have specified it to be a I/O port in the CONFIG WORD, leaving it floating is never a good idea, ur Xmitter side might be constantly getting into a reset state.

- I cant make out from the photo of the schematics, but the caps on the Xtal seems to be either 1uF or 1 nF, either of the value seems high. For 16-20 Mhz Xtal, they sould be around 10-20 pF.

- The four LEDs on the data bus of the LCD, if u r only using them in the proteus simulator for debugging purposes, then they MAY work, but if u have them in the actual circuit, they will pull too much current, (specially without any current limiting resistors on them)


XMITTER CODE:

- the RA1, you are checking for when RA1 == 1, which means that when the button is in "un-pressed" state (which means all the time). Your button is pulled high, means it will give a logical 0 when depressed.
- your code does not take care of the button release logic. At the moment it will keep transmitting all 4 messages in a cycle continuously.
- No switching debouncing in the code (u r better of googling abt what that is on the internet)

try this code :

Code: Select all

#define   click_button   RA1


char *Strings[] =
{
  "Welcome",
  "Final Year",
  "Project",
  "Wireless Data",
  "Transmission",
  "Thank You"
};
  unsigned int i;

void main()
{
     int k=0;
  ADCON1 = 0;               //configure PortA as digital I/O
  TRISA = 0x3F;             //configure PORTA as input
  TRISB = 0x0f;             //configure PORTB as input
  TRISC = 0x80;             //configure pin7 as input(RX), pin6 as output(TX)
   portb.f4=1;              //**the way the LED is connected in the schematics, u need to do portb.f4 = 0 to switch it on**//
  UART1_Init(9600);         // Initialize UART module at 9600 bps
 Delay_ms(100);           // Wait for UART module to stabilize

   i  = 0 ;
    while(1)
    {
      if(Button(PORTA,1,20,0))
      {
        UART1_Write_Text(Strings[i++]);
        UART1_Write(13);//Xmit CR after every msg so the receiver can detect an end of msg
        if(i==6)
          i = 0;
      }
    }
}

RECEIVER :

- you dont need to store the string on the receiver side because you are receiving them from the wireless receiver

Code: Select all

// LCD module connections
sbit LCD_RS at RD4_bit;
sbit LCD_EN at RD5_bit;
sbit LCD_D4 at RD0_bit;
sbit LCD_D5 at RD1_bit;
sbit LCD_D6 at RD2_bit;
sbit LCD_D7 at RD3_bit;

sbit LCD_RS_Direction at TRISD4_bit;
sbit LCD_EN_Direction at TRISD5_bit;
sbit LCD_D4_Direction at TRISD0_bit;
sbit LCD_D5_Direction at TRISD1_bit;
sbit LCD_D6_Direction at TRISD2_bit;
sbit LCD_D7_Direction at TRISD3_bit;
// End LCD module connections

#define   click_button   RA1


void main() {

int Col;
int Row
  int i=0;
  ADCON1= 0x06;             //configure PortA as digital I/O

  TRISA = 0xf3;             //configure PORTA as input
  TRISB = 0x00;             //configure PORTB as output
  TRISC = 0b10111111;             //configure pin7 as input(RX), pin6 as output(TX)
  PORTD = 0x00;             //configure PORTD as output
  TRISD = 0x00;

  UART1_Init(9600);              // Initialize UART module at 9600 bps
  Delay_ms(100);                 // Wait for UART module to stabilize


Lcd_Init(); // Initialize LCD

Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,3,"Wireless Data");
Lcd_Out(2,3,"Transmission");
Delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR); // Clear display


Col = 1;
Row = 1;
while(1)
{
 if((UART1_Data_Ready())      //if data available
 {
    c = UART1_Read();     //read the character
    if(c == 13)           // if a CR means end of msg, move 1,1 on LCD
    {
       Col = 1;
       Row = 1;
    }
    else          //else keep printign the msg
    {
      Lcd_Chr(Row,Col,c);
      Col++;                 //move to next column
      if(Col == 17)          //if horizontal limit reached
      {
         Col = 1;            //then roll over
         Row++;
         if(Row == 3)      //if vertical limit reached
         {
            Row = 1;       //then roll over
         }
      }
    }
 }
}
I have'nt tried all this code on sim, so may need some tweeking.


Regards

mirrayhan08
Posts: 7
Joined: 26 Aug 2016 22:37

Re: Wireless Data Transmission

#7 Post by mirrayhan08 » 20 Dec 2016 18:54

Hi Guys,
I am trying to figure out how to transmit and receive a string then display it to LCD.

I did some code and now it is working. But, does not work as I expected. Data transmission does not stop. Please check the attached project files.

It will be appreciated if anyone helps me to solve this problem.
Check the attached flow chart you will get the idea what actually I wanted.

Thank You
Mir Mehedi
Attachments
FlowChart.jpg
FlowChart.jpg (107.09 KiB) Viewed 4843 times
UART - TEST.zip
(156.72 KiB) Downloaded 178 times

Post Reply

Return to “mikroC General”