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

RS-232

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



Joined: 04 Jul 2005
Posts: 9

View user's profile Send private message

RS-232
PostPosted: Mon Jul 04, 2005 1:55 pm     Reply with quote

I am trying to receive data serially over RS-232 through LAB VIEW.

Lab view sends 3 bytes plus a termination character (0D ) at the end to PIC16f876 controller. Some how i am not able to read that termination character (0D) using getc().

Is it necessary for me to send a carriage return and a line feed at the end to read the 4th termination character?

Any ideas?

Noman Younus
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 04, 2005 2:08 pm     Reply with quote

getc() does not do any filtering or exclusion of characters.

See the test program below. It receives a character with getc()
and then displays it as a hex value in the terminal window.
When I type "ABCD" into my terminal program and press
the Enter key on my PC, I get the following output:
Code:

A  41
B  42
C  43
D  44
  0D

Code:
#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
//========================

void main()
{
char c;

while(1)
  {
   c = getc();
   printf("  %X\n\r", c);
  }
}
younus_noman



Joined: 04 Jul 2005
Posts: 9

View user's profile Send private message

PostPosted: Mon Jul 04, 2005 2:37 pm     Reply with quote

Thanks for your quick reply..

I tried the above code before and i am able to display the hex value.

but when i say printf("ABCD \r\n") it displays ABCD on the hyper terminal whereas if i say printf("ABCD") without using the line feed and carriage return then it just displays ABC i.e. it chops of the last byte and i am not sure y it does that

I also did PIC to PIC commnication and displayed the recevied data on my LCD.

MASTER PIC sends---- printf("ABCD \n\r);
SLAVE PIC receives and displays ABCD

If i receive 6 bytes it displays ABCDAB (using getchar)


Thanks

Noman Younus
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Mon Jul 04, 2005 2:42 pm     Reply with quote

You must have a while(1) in your main. Most likely you do not, just the printf and nothing after that. What happens is that main finishes and there is a hidden sleep instruction in there. The last byte of data is still in the transmit buffer when the pic goes to sleep. Post your program if you don't understand what I am talking about.
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