|
|
View previous topic :: View next topic |
Author |
Message |
bright
Joined: 24 Apr 2011 Posts: 14
|
Using strcmp function and transmitting string between 2 pics |
Posted: Wed Nov 02, 2011 7:49 pm |
|
|
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
|
|
Posted: Wed Nov 02, 2011 8:08 pm |
|
|
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
|
|
Posted: Wed Nov 02, 2011 8:57 pm |
|
|
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
|
|
Posted: Wed Nov 02, 2011 10:44 pm |
|
|
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 |
|
|
|
|
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
|