PhilB
Joined: 08 Feb 2006 Posts: 2
|
Pic-Pic Communication |
Posted: Wed Feb 08, 2006 1:09 pm |
|
|
Hello all. I am trying my hand at some pic-pic communication using two 16f877 microchips. The send pic will send a string of characters that begin with a $ and is 21 characters long, + 1 for null. I was initially going to use a fgets() procedure to obtain the string in the receiving pic. Browsing the forum, I noticed that most suggest using the get_string() command instead.
My first question is: Can get_string() delineate between two rs-232 streams? The receive pic has two setup, one for pic-pic, the other for pc-pic.
Secondly, when I include input.c I continuously get compiler errors of the sort:
Code: | *** Error 48 "C:\Phil\PICC\drivers\input.c" Line 14(6,10): Expecting a (
*** Error 43 "C:\Phil\PICC\drivers\input.c" Line 14(13,14): Expecting a declaration
*** Error 43 "C:\Phil\PICC\drivers\input.c" Line 14(14,15): Expecting a declaration
*** Error 43 "C:\Phil\PICC\drivers\input.c" Line 14(16,17): Expecting a declaration
*** Error 48 "C:\Phil\PICC\drivers\input.c" Line 17(10,15): Expecting a (
*** Error 43 "C:\Phil\PICC\drivers\input.c" Line 21(4,6): Expecting a declaration
*** Error 43 "C:\Phil\PICC\drivers\input.c" Line 21(6,7): Expecting a declaration
*** Error 48 "C:\Phil\PICC\drivers\input.c" Line 21(7,12): Expecting a (
|
Thirdly, if I do get get_string() to work properly...what is the best interupt routine to use with it? #int_RDA, or #int_EXT (I have enough resources to use an enable pin).
Anyways, here is my code. My compiler is: CCS PCM C Compiler, Version 3.202.
Code: |
#include <16F877.h>
#fuses HS, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
#use Delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, stream=sender, ERRORS)
#use rs232(baud=9600,parity=N,xmit=PIN_B6,rcv=PIN_B5, stream=PC,bits=8, ERRORS)
#include <input.c>
#define STRING_SIZE 22 // Allow up to 22 chars max (and 0 at end)
char input_str[STRING_SIZE];
char start;
boolean found_start;
#int_RDA
void RDA_isr(void) {
if (fgetc(sender) == 0x24) { // 0x24 == $
get_string(input_str,STRING_SIZE);
found_start = TRUE;
}
}
main()
{
enable_interrupts(INT_RDA);
enable_interrupts(global);
found_start = FALSE;
while(1) {
if (found_start) {
fprintf(PC,"Received: %s\n\r", input_str);
found_start = FALSE;
}
}
}
|
Thanks for any help! |
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Feb 08, 2006 1:24 pm |
|
|
Don't do that. Use EX_SISR.C to create an interrupt-driven receive
buffer. Then in main(), create a loop which will use bkbhit() to see if
a char is available in the buffer. If so, then use bgetc() to get the char
from the buffer. Then use other code in main() to process the chars. |
|