RS485 communication with computer

Thread Starter

Kei-Ki-Kun

Joined Oct 17, 2014
2
Hi
I use Pic16f877a to communicate with computer through COM port.But I only can send "hello" to computer but cannot received any signal from computer.I write program by CCS C and Proteus for simulation.So anyone can help me

#include <16f877a.h>
#device pic16f877*=16 adc=10
#fuses hs,nowdt,noprotect,nolvp,brownout
#use delay(clock=20mhz)
#use rs232(baud=9600,parity=N,xmit=pin_c6,rcv=pin_c7,bits=8)

#byte portB=0x06
#byte portC=0x07
#byte portD=0x08

char datareceive='0';
#int_rda
void rda_isr()
{
output_high(pin_d0);
output_high(pin_d5);
datareceive = getc();
if(datareceive=='1')
output_low(pin_b0);
if(datareceive=='2')
output_low(pin_b1);
if(datareceive=='3')
output_low(pin_b2);

}


void main()
{
set_tris_d(0x00);
set_tris_b(0x00);
portb=0xff;
portd=0x00;
enable_interrupts(int_rda);
enable_interrupts(global);
printf("hello");
printf("hello");
while(1);
}
 

Attachments

Chalma

Joined May 19, 2013
54
Greetings Kei,

not sure if this is what you need but basically your program above is only good for sending the text "hello" through the communication and showing up on hyperterminal (or whatever port reading program you are using). It is much more complex than that. you need to setup routines to check the buffer for data and tell the micro what to do with the said data as well.
Code:
byte get_char(void)
{
  byte c;

  if(S_BUFFER_HEAD == S_BUFFER_TAIL)
  {
  //return(0xff);  /* buffer empty */
  }
  if(S_BUFFER_HEAD > 16){S_BUFFER_HEAD = 0;}
   while(!RI);
  c = S_BUFFER[S_BUFFER_HEAD];
  S_BUFFER_HEAD++;
   new_cmd_recieved=1;
  return(c);

}
above is a function I use alot to check if there is a character in the buffer. I would do a google search and try to find examples that pertain to your project. There are also really good books on amazon that walk you through this. Good luck with your project
 

MaxHeadRoom

Joined Jul 18, 2013
28,617
In most cases TX out of the 877 is done outside of an interrupt, the RX however is normally activated on receipt of a character in the input buffer.
I assembler so I cannot help with the code.
Max.
 
Top