View previous topic :: View next topic |
Author |
Message |
AdamkT1
Joined: 21 Apr 2007 Posts: 44
|
rs232 charachter receive problem |
Posted: Sat Jun 02, 2007 11:42 pm |
|
|
I am having troubles in receiving charachter from PC using rs232 interface.
I do not receive the charachter which I send from windows hyper terminal.
I shall appreciate any help.
Code: |
#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include <lcd.c>
#define KEYHIT_DELAY 500 // in milliseconds
char timed_getc()
{
long timeout;
char retval;
timeout=0;
while(!kbhit() && (++timeout< (KEYHIT_DELAY*100)))
delay_us(10);
if(kbhit())
retval = getc();
else
retval = 0;
return(retval);
}
void main()
{
char k;
delay_ms(200);
lcd_init();
while (TRUE)
{
k=timed_getc();
if (k!=0)
{
lcd_putc(k);
}//end if
}
}//end main |
|
|
|
inservi
Joined: 13 May 2007 Posts: 128
|
|
Posted: Sun Jun 03, 2007 12:19 am |
|
|
Hello,
Your code look to be ok. Did you controlled the speed, data length, polarity... ?
dro _________________ in médio virtus |
|
|
AdamkT1
Joined: 21 Apr 2007 Posts: 44
|
|
Posted: Sun Jun 03, 2007 6:50 am |
|
|
I have checked every thing a number of times...
No good so far.
Thanks any way. |
|
|
Ttelmah Guest
|
|
Posted: Sun Jun 03, 2007 7:30 am |
|
|
You say 'through RS232'. How have you got this connected?. You do realise that a hardware buffer/inverter, is needed to ninterface the PIC to the PC?.
Best Wishes |
|
|
AdamkT1
Joined: 21 Apr 2007 Posts: 44
|
|
Posted: Sun Jun 03, 2007 10:52 am |
|
|
I am doing it in Proteus. |
|
|
AdamkT1
Joined: 21 Apr 2007 Posts: 44
|
|
Posted: Sun Jun 03, 2007 11:06 am |
|
|
Can you guide me to any link for circuit diagram / schematic .
The circuit for sending charachter from PC to PIC.
Thanks for the reply.
Adam |
|
|
caduhitec
Joined: 06 Feb 2007 Posts: 3
|
|
Posted: Sun Jun 03, 2007 11:33 am |
|
|
hi dear,
remember that pic has only two caracters buffer, if you send more then two chars and the the pic not retrieve the chars from the buffer then comunication between PC and pic will stop. It´s a good idea use the RDA interrupt.
Cadu. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun Jun 03, 2007 11:52 am |
|
|
AdamkT1 wrote: | Can you guide me to any link for circuit diagram / schematic .
The circuit for sending charachter from PC to PIC. | The most common IC used for this is the MAX232. It is very simple to use. Check the datasheet at www.maxim-ic.com
Quote: | remember that pic has only two caracters buffer, if you send more then two chars and the the pic not retrieve the chars from the buffer then comunication between PC and pic will stop. | A nice addition to the given code would be to add the ERRORS directive in the #use RS232 line. This way you will still loose characters but at least the hardware UART will not be blocked anymore by receive buffer overflows.
Quote: | It´s a good idea use the RDA interrupt. | This is true, but with the simple getc() implementation not working there is a more basic (hardware) related problem. Interrupts will not solve this and only make things more complicated. |
|
|
rberek
Joined: 10 Jan 2005 Posts: 207 Location: Ottawa, Canada
|
|
Posted: Sun Jun 03, 2007 11:57 am |
|
|
You still need to put in an RS232 transceiver, like the MAX232, in Proteus. Just as Ttelmah pointed out.
r.b. |
|
|
AdamkT1
Joined: 21 Apr 2007 Posts: 44
|
|
Posted: Sun Jun 03, 2007 8:37 pm |
|
|
Thank you all for the suggestions.
I shall post the results, hopefully, soon.
Adam |
|
|
mrpicing
Joined: 22 Oct 2005 Posts: 20
|
|
Posted: Wed Jun 13, 2007 12:09 am |
|
|
set the port c direction by "set_tris_c(0x80);"
and then see the results |
|
|
|