|
|
View previous topic :: View next topic |
Author |
Message |
Deiphos
Joined: 12 May 2004 Posts: 4
|
RS232 Bidireccional |
Posted: Mon May 30, 2005 5:16 am |
|
|
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
|
Re: RS232 Bidireccional |
Posted: Mon May 30, 2005 7:37 am |
|
|
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
|
|
Posted: Mon May 30, 2005 8:31 am |
|
|
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
|
|
Posted: Mon May 30, 2005 9:32 am |
|
|
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
|
|
Posted: Mon May 30, 2005 9:36 am |
|
|
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
|
|
Posted: Mon May 30, 2005 10:28 am |
|
|
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. |
|
|
|
|
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
|