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

RS232 Bidireccional

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



Joined: 12 May 2004
Posts: 4

View user's profile Send private message

RS232 Bidireccional
PostPosted: Mon May 30, 2005 5:16 am     Reply with quote

I am having a problem with RS232 communication.This is the program I have used for test:

Code:

#include <16F874.h>
#use delay(clock=4194304)     
#fuses HS, NOWDT, NOPROTECT, NOPUT, NOBROWNOUT, NOLVP
#use RS232(BAUD=9600,BITS=8,PARITY=N,XMIT=PIN_C6,RCV=PIN_C7)

void main()
{
   int i=0;
   
   printf("Press any key...\n");
   getc();

   do{
      i=0;
      for(i=1;i<11;i++)
      printf("%d \r\n",i);

   }while(true);
}


If the first "printf" and the "getc" are commented,program works properly,sending data to PC; but with this two lines,the program stops at this point,ignoring key pression.Connections seem to be well.
The program I am using is Windows hyperterminal.
Thank you for your help.
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

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

Re: RS232 Bidireccional
PostPosted: Mon May 30, 2005 7:37 am     Reply with quote

Deiphos wrote:
I am having a problem with RS232 communication.This is the program I have used for test:

Code:

#include <16F874.h>
#use delay(clock=4194304)     
#fuses HS, NOWDT, NOPROTECT, NOPUT, NOBROWNOUT, NOLVP
#use RS232(BAUD=9600,BITS=8,PARITY=N,XMIT=PIN_C6,RCV=PIN_C7)

void main()
{
   int i=0;
   
   printf("Press any key...\n");
   getc();

   do{
      i=0;
      for(i=1;i<11;i++)
      printf("%d \r\n",i);

   }while(true);
}



It is "DO"ing exactly what you told it to "DO". Look closely at where you have place the "do{" statement relative to your first printf and getc.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
Guest








PostPosted: Mon May 30, 2005 8:31 am     Reply with quote

Yes,Ok.The program is waiting for a keyboard input to continue.The problem is that when I press a key,it doesn't continue.
Ttelmah
Guest







PostPosted: Mon May 30, 2005 9:32 am     Reply with quote

Realistically, the 'most likely' problem is a connection. Do you have a method to test the signal at pin C7?. It should idle 'high', and drop as soon as a character is sent.
Add 'errors' to your #use RS232 statement, otherwise if the signal line floats low, the UART can get 'hung up'.
What you post should work, if the line drops at the PIC whan a character is sent, and is sitting high when the PC is not transmitting.

Best Wishes
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

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

PostPosted: Mon May 30, 2005 9:36 am     Reply with quote

Tested on board with PIC16F877A and 20MHz xtal.

Prints your text "Press any key..." then pauses at the getc() line. I press a key then it starts spitting out the numbers 1 to 10 over and over as ASCII with CRLF pair.

I suggest you check your RS232 port wiring. Use an oscilloscope on your RCV pin to see if you are getting data.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
Mark



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

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

PostPosted: Mon May 30, 2005 10:28 am     Reply with quote

You should also assign a variable to the return value of the getc(). Although probably not the problem in your case but it is possible that optimizations on some compilers could ignore the function and it is just good coding.
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