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

two pic commnicate with PC via RS232?

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



Joined: 23 May 2007
Posts: 22

View user's profile Send private message

two pic commnicate with PC via RS232?
PostPosted: Sun Jun 17, 2007 7:25 pm     Reply with quote

when I use two pic commnicate with PC via RS232,one is 16F877,the other is 18F4523.when I

connect the Oscillator with the pics,they work as following

16F877 18F4523 results

4M 10M NO
4M 4M NO
share the same 4M Oscillator,they work well.

Can I use the Oscillator separately?
arunb



Joined: 08 Sep 2003
Posts: 492
Location: India

View user's profile Send private message Send e-mail

re:
PostPosted: Sun Jun 17, 2007 7:29 pm     Reply with quote

You mean the PICs are sharing an oscillator ??

Dont' know if that is a good idea, but yes you can run the PICs using different oscillators, but keep in mind the max osc. requirements for the PICs,

For serial connection to work, the baud rates of both the PICs must be the same ...


thanks
arunb
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jun 17, 2007 8:14 pm     Reply with quote

Post your #use rs232() statement for each PIC.
Also post the #use delay() and #fuses statements for each PIC.
stefsun



Joined: 23 May 2007
Posts: 22

View user's profile Send private message

PostPosted: Sun Jun 17, 2007 8:59 pm     Reply with quote

The 16F877 and the 18F4523's PIN25(TX) and PIN26(RX) connect each other.they reply according to PC'instruction separately.

the 16F877 code is

Code:

#include <16F877.h>                             // PICF4523 header file
#device ADC=10                                   // 12 bits ADC
#use delay(clock=4000000)                        // for 10Mhz crystal
#fuses XT, NOWDT, NOPROTECT, NOLVP               // for debug mode

#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, PARITY=N,BITS =8,stream=MYPC)


void main(void)
{
       
         int8 c=0;
         SET_TRIS_C( 0xFF );                              
   while(1)
      {

               while(!kbhit())
                  delay_us(10);
               
               if(kbhit())
                        {   
                           c=fgetc(MYPC);
                              if(2==c)
                                 {
                                    //putc(c);
                                    
                                    printf("877 is ready\n");
                           
                                    SET_TRIS_C( 0x8F );                                       }
                              else
                                    SET_TRIS_C(0XFF);                                 }
               
      }

}





the 18F4523 code is

Code:


#include <18F4523.h>                             // PICF4523 header file
#device ADC=12                                   // 12 bits ADC
#use delay(clock=4000000)                        // for 4Mhz crystal
#fuses XT, NOWDT, NOPROTECT, NOLVP               // for debug mode

#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, PARITY=N,BITS =8,stream=MYPC)


void main(void)
{
       
         int8 c=0;
         SET_TRIS_C( 0xFF );                              
   
   while(1)
      {

               while(!kbhit())
                  delay_us(10);
               
               if(kbhit())
                        {   
                           c=fgetc(MYPC);
                              if(1==c)
                                 {
                                    //putc(c);
                                    
                                    printf("4523 is ready\n");
                           
                                    SET_TRIS_C( 0x8F );                                             }
                              else
                                    SET_TRIS_C( 0xFF );                                       }
               
      }

}
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