Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] Wireless communication via UART pic16f877a help

Status
Not open for further replies.

kwdckperera

Newbie level 6
Joined
Mar 15, 2013
Messages
11
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,353
Hello all,

I am doing a simulation of sending analog voltage from one place to another place via RF modules. This voltage is an output from a sensor. I am using 2 pic16f877a micro-controllers and RF transmitter and a receiver.

My transmitting side works perfectly fine. It reads the analog voltage, convert it in to digital and then to a string, and sends it through transmitter. (there is a display for reading the voltage too). My problem is with the receiving side. I can only print receiving characters on to display. I can not make a string from them. What i want is make a string from receiving data. Once new data has arrived string has to be modified according to new data. The received data (string) must be shown on the display.

Following is my code and proteus simulation. I used MikroC for coding. Please help me with receiving side code.
Thanks:)

Transmitting side (works fine)
Code:
sbit LCD_RS at RD2_bit;    // Lcd module connections
sbit LCD_EN at RD3_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;
sbit LCD_RS_Direction at TRISD2_bit;
sbit LCD_EN_Direction at TRISD3_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;

void main() {
      int analog_value = 0;                // define intiger "analog_value" with initial value of 0
      int value = 0;
      char buf [7];
      
      TRISA.f0=1;                        // define AN0 pin as input
      ADCON1 = 0;                        // set all pinns in register A as analog inputs with refference to VDD
      
      Lcd_Init();
      Lcd_Cmd(_LCD_CLEAR);
      Lcd_Cmd(_LCD_CURSOR_OFF);
      
      UART1_Init(9600);                       // Initialize UART module at 9600 bps
      Delay_ms(100);

      while(1)
      {
           analog_value = ADC_Read(0);
           value = (int)((analog_value/204.6)*1000);
           intToStr(value,buf);
           ltrim(buf);
           UART1_write_text(buf);
           Lcd_Out(1,1,buf);
           
           Delay_ms(5000);
      }
}


Receiving side (where the help is needed)
Code:
sbit LCD_RS at RD2_bit;    // Lcd module connections
sbit LCD_EN at RD3_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;
sbit LCD_RS_Direction at TRISD2_bit;
sbit LCD_EN_Direction at TRISD3_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
char value ;

void main() {

     Lcd_Init();
     Lcd_Cmd(_LCD_CLEAR);
     Lcd_Cmd(_LCD_CURSOR_OFF);

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


     while (1) {                            // Endless loop
            if (UART1_Data_Ready()== 1)
            {
              value = UART1_Read();   // read the received data,
              Lcd_chr_CP(value);
            }

            }
    }
 

Attachments

  • simulation.rar
    77.7 KB · Views: 105

Use

Code C - [expand]
1
UART1_Read_Text()

at the receiving side. Don't forget to use

Code C - [expand]
1
UART1_Write_Text()

at the transmitting side with the delimiter. If you want to send 123.45678 then send it as "123.45678\r\n" and at the receiver end check for the delimiter \r\n.
 
  • Like
Reactions: rado

    rado

    Points: 2
    Helpful Answer Positive Rating
Use

Code C - [expand]
1
UART1_Read_Text()

at the receiving side. Don't forget to use

Code C - [expand]
1
UART1_Write_Text()

at the transmitting side with the delimiter. If you want to send 123.45678 then send it as "123.45678\r\n" and at the receiver end check for the delimiter \r\n.

i used "inttostr" command to convert number into an text. How to put "\r\n" at the end of this?
Can you show me the code, how to do this?
I also appriciate if you can give me the receiving side command too.

Thanks
 

Use


Code C - [expand]
1
strcat() or strncat()

Read mikroC help file.

I tried but no luck.

at transmit side i put,
Code:
char *res;  // at the beginning

res = strcat(buf, "\r\n");
ltrim(buf);
UART1_write_text(res);
Lcd_Out(2,1,res);
>>>>>>>>>>> nothing on lcd

at receiving side i put,
Code:
char *output; // at the beginning

UART1_Read_Text(output,"/r/n", 255); // instead of UART1_read
Lcd_Out(2,1,output);
>>>>>>>>> nothing on lcd
please help
 


Code C - [expand]
1
UART1_Read_Text(output,"\r\n", 15);

no luck, output is
Untitled.jpg
 

A popular C fault: Storing data to a nowhere-string
Code:
char *output; // at the beginning

UART1_Read_Text(output,"/r/n", 255); // instead of UART1_read
Lcd_Out(2,1,output);

Instead of a pointer, define s string variable, e.g.
Code:
char output[16];
 

A popular C fault: Storing data to a nowhere-string
Code:
char *output; // at the beginning

UART1_Read_Text(output,"/r/n", 255); // instead of UART1_read
Lcd_Out(2,1,output);

Instead of a pointer, define s string variable, e.g.
Code:
char output[16];

there is nothing on the receiving side then. (also there are two $ marks on transmitting side too)
Can you give me the full code please? I am new for programming and greatly appriciate your help.
Thanks
 

Try this. Zip and post your mikroC project files + Proteus file. I just don't have time to create a new project. Have you read mikroC help regarding minimum array size to be used with

Code C - [expand]
1
IntToStr() or FloatToStr()

functions?
 

Attachments

  • simulation rev1.rar
    1 KB · Views: 95
Try this. Zip and post your mikroC project files + Proteus file. I just don't have time to create a new project. Have you read mikroC help regarding minimum array size to be used with

Code C - [expand]
1
IntToStr() or FloatToStr()

functions?

working perfect. Thanks
Untitled.jpg
Any idea on how to limit dcimal places on float?
for an example i prefer 2.333 instead of 2.33341.
(i tried sprintf but it is not available for pic 16f877a)
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top