CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Using strcmp function and transmitting string between 2 pics

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
bright



Joined: 24 Apr 2011
Posts: 14

View user's profile Send private message

Using strcmp function and transmitting string between 2 pics
PostPosted: Wed Nov 02, 2011 7:49 pm     Reply with quote

Guys, I have been trying to send a string from 1 pic16f722 to another and then display it on the 16x2 LCD. Can you please help guys. I have included the codes I have used in the transmitting pic and on the receiving pic.

The Receiver code:
Code:

#include <16F722.h>
#fuses INTRC_IO, NOWDT, NOBROWNOUT, PUT, NOMCLR
#use delay(clock=2000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, BITS =8, PARITY=n, stop=1)

#include <string.h>
#include <lcd.c>

//================================
void main()
{

   char string[30];
   char name[30];
   lcd_init();
   strcpy(name, "BRIGHT");
   while(1)
   {
      gets(string);   
      if(strcmp(string, name));
      {
         delay_ms(250);
         lcd_putc("GOOD");
      }
   }
}


The transmitter code:
Code:

#include <16F722.h>
#fuses INTRC_IO, NOWDT, NOBROWNOUT, PUT, NOMCLR
#use delay(clock=2000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, BITS =8, PARITY=n, stop=1)

//================================
void main()
{
   while(1)
     {
      printf("BRIGHT");
   }

}
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Nov 02, 2011 8:08 pm     Reply with quote

some ideas...

You should always add 'errors' to both use RS232(...) declarations...

Also, you might want to add a delay in the transmit program otherwise it'll send BRIGHTBRIGHTBRIGHT and the receiving unit might not sync up with it.

And in the IF statement you might like to say 'bad' or blank the LCD when the wrong data comes through.
bright



Joined: 24 Apr 2011
Posts: 14

View user's profile Send private message

PostPosted: Wed Nov 02, 2011 8:57 pm     Reply with quote

I tried that and it is still not displaying anything on the LCD display.
andrewg



Joined: 17 Aug 2005
Posts: 316
Location: Perth, Western Australia

View user's profile Send private message Visit poster's website

PostPosted: Wed Nov 02, 2011 10:44 pm     Reply with quote

gets is waiting for a carriage return, so the sending code should be:
Code:
printf("BRIGHT\r");
Having said that, I would never use gets, as there is a risk it will overflow the receiving buffer and corrupt memory.

...Edited to change newline (\n) to carriage return (\r) based on feedback from PCM Programmer (thanks!). I did not, and still haven't, checked the precise behaviour of gets(), because I never use it. I would strongly recommend you do your own parsing using getc().
_________________
Andrew
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group