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

Serial Communication between 2 PIC16F877a

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



Joined: 11 Feb 2016
Posts: 4
Location: Pakistan

View user's profile Send private message

Serial Communication between 2 PIC16F877a
PostPosted: Thu Feb 11, 2016 10:21 am     Reply with quote

Hi friends,
I am a new in MCU programming and I use CCS C compiler. Friends I want to communicate between two PIC16F877A MCU using serial port with serial interrupt but I can’t do it.
Please help me in this regard. It’s more easy for me if share with Proteus circuit.

Thanks
_________________
When we give cheerfully and accept gratefully, everyone is blessed
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Thu Feb 11, 2016 11:36 am     Reply with quote

Hi,

Please post the code that you can't get to work, and we'll help you get it running. This is easier for us, and is a much better way for you to learn than just giving you a piece of code!
_________________
John

If it's worth doing, it's worth doing in real hardware!
temtronic



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

View user's profile Send private message

PostPosted: Thu Feb 11, 2016 12:04 pm     Reply with quote

Obvious place to start is with the ex_sisr that CCS supplies in the examples folder but HOW you connect to 2 PICs is very important !
You don't specify if you want full duplex, half duplex, single wire, or ??? it is possible to connect both PICs without any logic level translation( no MAX232) but we'd need more information from you.


Jay
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Fri Feb 12, 2016 2:44 am     Reply with quote

Like others have said, we need more info.

See the sticky about Proteus on this forum.

I'd begin by getting each device to talk to a PC, (will need a MAX232 which you can remove later if you don't need it).

Jay suggests using one of the CCS supplied examples as a good starting point.

Mike
kookee



Joined: 11 Feb 2016
Posts: 4
Location: Pakistan

View user's profile Send private message

PostPosted: Fri Feb 12, 2016 11:04 am     Reply with quote

Thanks for reply
I connect
TX of PIC#1 to RX of PIC#2
RX of PIC#1 to TX of PIC#2

with 20MHz clock and RS232 setting is
Code:
#use rs232(baud=9600, xmit=PIN_C6,rcv=PIN_C7)

My code for both PICs are under please. and i use CCS C compiler 4.114.
Code:

/* USE FOR PIC # 1*/

#include <main.h>
#include "Flex_LCD420.C"

#define BUFFER_SIZE 32
BYTE buffer[BUFFER_SIZE];
BYTE next_in = 0;
BYTE next_out = 0;

#int_rda
void serial_isr() {
   int t;

   buffer[next_in]=getc();
   t=next_in;
   next_in=(next_in+1) % BUFFER_SIZE;
   if(next_in==next_out)
     next_in=t;           // Buffer full !!
}

#define bkbhit (next_in!=next_out)

BYTE bgetc() {
   BYTE c;

   while(!bkbhit) ;
   c=buffer[next_out];
   next_out=(next_out+1) % BUFFER_SIZE;
   return(c);
}

void main()
{
  lcd_init();                   
//  setup_adc_ports( RA0_RA1_RA3_ANALOG );    // set AN0, AN1 & AN3 as a Analog
//  setup_adc(ADC_CLOCK_INTERNAL);

  lcd_gotoxy(1,1);
  printf(lcd_putc,"ASDF");
  printf("CAN I READ IT");
 
  while(true)
  {
    output_toggle(LED);
    delay_ms(DELAY);
    printf("H");
  }
}

Code:

/* USE FOR PIC # 2 */

#include <main.h>    //PIC2
#include "Flex_LCD420.C"

#define BUFFER_SIZE 32
BYTE buffer[BUFFER_SIZE];
BYTE next_in = 0;
BYTE next_out = 0;

#int_rda
void serial_isr()
{
  int t;
  buffer[next_in]=getc();
  t=next_in;
  next_in=(next_in+1) % BUFFER_SIZE;
  if(next_in==next_out)
    next_in=t;           // Buffer full !!
  //lcd_gotoxy(3,3);
  //printf(lcd_putc,"RS232 Read %d",buffer);   
}

#define bkbhit (next_in!=next_out)

BYTE bgetc()
{
   BYTE c;
   while(!bkbhit) ;
   c=buffer[next_out];
   next_out=(next_out+1) % BUFFER_SIZE;
   return(c);
}

void main()
{
  lcd_init();                   
//  setup_adc_ports( RA0_RA1_RA3_ANALOG );    // set AN0, AN1 & AN3 as a Analog
//  setup_adc(ADC_CLOCK_INTERNAL);
  lcd_gotoxy(1,1);
  printf(lcd_putc,"ASDF");
  delay_ms(100);
  //printf("CAN I READ IT");
  while(true)
  {
    //lcd_gotoxy(2,2);
    //printf(lcd_putc,"RS232 Read");
    output_toggle(LED);
    delay_ms(DELAY); 
    lcd_gotoxy(1,1);
    printf(lcd_putc,"1232456"); //%c",bgetc());
  }
}

_________________
When we give cheerfully and accept gratefully, everyone is blessed
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Fri Feb 12, 2016 12:22 pm     Reply with quote

Please use the code button, it preserves the formatting and makes code easier to read.

A simple guide as to what's supposed to happen would help.
Also you're not telling us what you can/cannot see.

Like I said before it's simpler to start by getting each processor to talk/listen to a PC via a MAX232 chip.
That way you get a better feel for what's going on.
You can send known signals to the PIC and see what it does with them, and monitor what's coming back, (assuming it's all in ASCII).

Mike
kookee



Joined: 11 Feb 2016
Posts: 4
Location: Pakistan

View user's profile Send private message

PostPosted: Fri Feb 12, 2016 1:17 pm     Reply with quote

Mike Walne wrote:
Please use the code button, it preserves the formatting and makes code easier to read.

A simple guide as to what's supposed to happen would help.
Also you're not telling us what you can/cannot see.

Like I said before it's simpler to start by getting each processor to talk/listen to a PC via a MAX232 chip.
That way you get a better feel for what's going on.
You can send known signals to the PIC and see what it does with them, and monitor what's coming back, (assuming it's all in ASCII).

Mike


thanks

i test my code in Proteus.
in it PIC 1 send data but PIC 2 not show it on LCD
_________________
When we give cheerfully and accept gratefully, everyone is blessed
temtronic



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

View user's profile Send private message

PostPosted: Fri Feb 12, 2016 1:33 pm     Reply with quote

Proteus is BUSTED !!!

get real hardware, wire it up,test, report back

No one here wants to FIX busted Proteus

Jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Feb 12, 2016 8:46 pm     Reply with quote

This schematic shows the serial pin connections between the two PICs:
https://electrosome.com/wp-content/uploads/2014/09/PIC-to-PIC-
Communication-UART-Circuit-Diagram.jpg
Tx on the first PIC goes to Rx on the 2nd PIC, etc. The DIP switch on
the first PIC is read by a program and the value is sent by serial to the
2nd PIC. The 2nd PIC displays the DIP switch setting on the LEDs.

There are no MAX232A chips in the circuit, so this schematic is only for
short range - basically, two boards on your workbench.
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