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 support@ccsinfo.com

Need help in XBEE with PIC!!

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



Joined: 22 Jan 2013
Posts: 7

View user's profile Send private message

Need help in XBEE with PIC!!
PostPosted: Tue Jan 22, 2013 11:41 am     Reply with quote

Hi everyone,

I know how to connect XBEE in point to point but I don't know how to use it with PIC16f877A. I've constructed my board with 3.3V to PIC and also XBEE. XBEE connection will be vcc, rx, tx, and gnd.
Here is my test code for both transmitter and receiver.
The xbee is not working. I'm wondering why is it happen.
Hope anyone can give me guide lines. Thanks in advance.
Anyone can show me coding example i will modify myself.
I'm using CCS c-compiler. thanks.

Transmitter:
Code:

#include <16f877a.h>
#fuses HS,NOLVP,NOWDT,NOPROTECT,NOBROWNOUT       
#use delay(clock=20000000)       // 20 MHz crystal on PCB
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,bits=8, parity=N)    // you can use any pins for software uart...
#include <stdlib.h>
 

void main()
{
   while (TRUE)
   {
      if (input(PIN_A2)==1)
      {
         output_high(PIN_B0);
         printf("a"); //sends signal a
       }
       else
       {
         output_low(PIN_B0);
         printf("b"); //sends signal b
       }
       
   }
}


Receiver:
Code:

#include <16f877a.h>
#fuses HS,NOLVP,NOWDT,NOPROTECT,NOBROWNOUT       
#use delay(clock=20000000)       // 20 MHz crystal on PCB
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,bits=8, parity=N)   
#define LED_0 PIN_B0

#include <stdlib.h>

char x;

void main() {
   while (TRUE) {
       if (kbhit()) {
         x = getc();
       }
       if (x=='a'){
         output_high(LED_0);
         
       }
       else{
         output_low(LED_0);
         
       }
   }
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19467

View user's profile Send private message

PostPosted: Tue Jan 22, 2013 12:55 pm     Reply with quote

First thing. Change your PIC......

The 16F877a, is not rated to operate below 4.0v. The LF, is rated down to 3.3v, but at 10MHz max.

Big problem.

Second, add errors to the slave RS232 definition. This must be used when the hardware UART is used, unless you handle errors yourself. Without this the UART can get locked.

Other comment, you only need to change the LED's, when a character has been read. No point in continuously setting them.

Best Wishes
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Tue Jan 22, 2013 2:44 pm     Reply with quote

in case you are wondering... you could use a 16f887... its a pin by pin drop-in replacement.

also, if you are like me and have PCM, its compatible with your compiler.... (you need a diferent version of CCS for 18 series)

G.
_________________
CCS PCM 5.078 & CCS PCH 5.093
Ttelmah



Joined: 11 Mar 2010
Posts: 19467

View user's profile Send private message

PostPosted: Wed Jan 23, 2013 9:35 am     Reply with quote

It's still not rated for 20MHz at 3.3v though.:
20Mhz operation requires 4.5v min on this chip.
To go to 20MHz on a pin/compiler compatible chip, you need something like the PIC16F1937.

Best Wishes
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Wed Jan 23, 2013 12:20 pm     Reply with quote

.... indeed it does not run at 20MHz on 3.3V but it does run at a lower frequencies unlike the 877A' which requires the 'LF' variant.

in light of the current code posted, and that he is using 9600 baud rates, i really dont think he _needs_ 20MHz operation...

also, since he was using a 877A, the 887 would be a very smooth transition...

G.
_________________
CCS PCM 5.078 & CCS PCH 5.093
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