Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC to PIC interfacing by RS485 by CCS C

Status
Not open for further replies.

kaSva

Junior Member level 1
Joined
Nov 26, 2013
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
136
Hello,

I need "PIC to PIC interfacing by RS485 in CCS C compiler (using RS485.c)" codes and schematics. Can you share with me?
 

The term RS485 such as RS232 refers to the electric standard levels at which data can be sent at the physical layer. Therefore, you can take a search for UART based examples using this compiler. Right here on forum there are a lot applied to the most varied applications.
 

RS485 between two PIC problem!

Hello i am trying to communicate two pic.Its works on PROTEUS correctly.But this system didn't work in real. What's the problem please help me!

System doing this job:

From Master PIC to Slave PIC;

when d2 high, send 82.34 to Slave
when d3 high send 25.36 to Slave
when d4 high send 12.56 to Slave

Slave PIC is add 10.00 to comming data and show total data on the GLCD. Example: Master 82.34 send, we will see 92.34 on the GLCD.But when i operate the system.GLCD shows 0.00.So when Master's d2,d3,d4 pins anyone be high by me,GLCD shows 10.00

Sorry about my english :)

MASTER PIC: 16F877A

Code:
#INCLUDE <16f877.H>
#USE DELAY (CLOCK=4000000)
#use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7,stop=1,parity=n)
#include <input.c> 
#use fast_io (b)
#use fast_io (d)
#define use_portb_lcd true
#INCLUDE <LCD420.c>
#define re pin_d0
#define de pin_d1
float x=82.34,y=25.36,z=12.56;
int gb=0;
//
void main()
{
set_tris_b(0x00);
output_b(0x00);
set_tris_d(0x00);
output_d(0x00);
output_high(re);
output_high(de);
delay_ms(50);
lcd_init();
printf(lcd_putc,"\fBilgi: ");

while (1)
{



if(input(pin_d2))
{
   delay_ms(10);
   printf(lcd_putc,"\fBilgi:%f ",x);
   while(input(pin_d2));
   printf("%f",x);
   
}

if(input(pin_d3))
{
   delay_ms(10);
   printf(lcd_putc,"\fBilgi:%f ",y);
   while(input(pin_d3));
   printf("%f",y);
   
}

if(input(pin_d4))
{
   delay_ms(10);
   printf(lcd_putc,"\fBilgi:%f ",z);
   while(input(pin_d4));
   printf("%f",z);
   
}









}
}

SLAVE PIC: 18F4685

Code:
#INCLUDE <18F4685.H>
#USE DELAY (CLOCK=4000000)
#use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7,stop=1,parity=n)
#include <input.c> 
#use fast_io (d)

#include <T6963C.c>
#INCLUDE <stdlib.h>
#define re pin_d0
#define de pin_d1

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES PUT                      //Power Up Timer
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOPBADEN                 //PORTB pins are configured as digital I/O on RESET
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#DEFINE fast_glcd


char gelen_bilgi[10],x_str[10];
int sayac;
float x=0;
//
void main()
{
set_tris_d(0x00);
output_d(0x00);

output_low(re);
output_low(de);

glcd_init(240,128); // Grafik LCD ektran hazırlanıyor
glcd_WriteByte(1, (LCDModeSet|LCDMode_XOR)); // Grafik LCD ekran XOR moda göre ayarlanıyor
glcd_WriteByte(1, (LCDDispMode|LCDDisp_TXT|LCDDisp_GRH)); // Grafik LCD ekran hem metin hem grafik modunda çalışacak şekilde ayarlanıyor

sprintf(x_str,"Bilgi: %f",x);//float to string işlemi gerçekleştiriliyor
glcd_text57(60,55,x_str,2,1);//voltaj_str değeri ekrana yazdırılıyor

//
while (1)
{


   for(sayac=0;sayac<5;sayac++)
      {
         gelen_bilgi[sayac]=getc();
      }




x = atof(gelen_bilgi);

x=x+10;

glcd_init(240,128); // Grafik LCD ektran hazırlanıyor
glcd_WriteByte(1, (LCDModeSet|LCDMode_XOR)); // Grafik LCD ekran XOR moda göre ayarlanıyor
glcd_WriteByte(1, (LCDDispMode|LCDDisp_TXT|LCDDisp_GRH)); // Grafik LCD ekran hem metin hem grafik modunda çalışacak şekilde ayarlanıyor

sprintf(x_str,"Bilgi: %f",x);//float to string işlemi gerçekleştiriliyor
glcd_text57(60,55,x_str,2,1);//voltaj_str değeri ekrana yazdırılıyor

}}

CIRCUIT SCHEMATIC:

vhbx1h.jpg




DURING SIMULATION:

2jenxoi.png
 

I recommend you to use rda or rda2 interrupt which differs uart to uart. Otherwise you can not sencroise communication. Here is an example.

Code:
char start_byte =  '<';
char stop_byte  =  '>';
#INT_RDA2
void serihaberlesme_kesmesi () 
{
   buffer[1]=fgetc(RS485);
   if(buffer[1]==start_byte)
   {
      buffer[1]=1;
      disable_interrupts(INT_RDA2);
      data_got=1; 
   }
               
}

void main()
{
   // Set I/O states of the ports
   //           76543210
   set_tris_a(0b00000000);
   set_tris_b(0b11000000);
   set_tris_c(0b00000000);
   set_tris_d(0b00000000);
   set_tris_e(0b00000000);
   set_tris_f(0b11110000);
   set_tris_g(0b11100100);

   

   set_pin_states(); //bütün motorları durdurur
   set_adress();     //jumperlara göre adresini algılar
   output_high(LED); //debug ledini yakar
   enable_interrupts(global);
   enable_interrupts(INT_RDA2);
   enable_interrupts(INT_TIMER2);
   enable_interrupts(INT_TIMER1);
while(true)
   {
      if(data_got==1)
      {
         data_got=0;  
            for(int i=2;i<=10;i++)
            {
               buffer[i]=getc();
            }
            if(buffer[10]==stop_byte)
            {
               check_data();
            }
          clear_interrupt(INT_RDA2);
          enable_interrupts(INT_RDA2);
       }
    }
 }

I hope this will help you.
 
Last edited by a moderator:

Why you are using rs485?
Are your both pic's on the same board?
If on the same board you can simply use rs232 or even I2C for sending data.

you can receive data on the slave side using serial interrupts.
you can also use modbus drives for sending data.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top