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 charachter receive problem

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



Joined: 21 Apr 2007
Posts: 44

View user's profile Send private message

rs232 charachter receive problem
PostPosted: Sat Jun 02, 2007 11:42 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Jun 03, 2007 12:19 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Jun 03, 2007 6:50 am     Reply with quote

I have checked every thing a number of times...
No good so far.

Thanks any way.
Ttelmah
Guest







PostPosted: Sun Jun 03, 2007 7:30 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Jun 03, 2007 10:52 am     Reply with quote

I am doing it in Proteus.
AdamkT1



Joined: 21 Apr 2007
Posts: 44

View user's profile Send private message

PostPosted: Sun Jun 03, 2007 11:06 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Jun 03, 2007 11:33 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Jun 03, 2007 11:52 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Jun 03, 2007 11:57 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Jun 03, 2007 8:37 pm     Reply with quote

Thank you all for the suggestions.
I shall post the results, hopefully, soon.

Adam
mrpicing



Joined: 22 Oct 2005
Posts: 20

View user's profile Send private message

PostPosted: Wed Jun 13, 2007 12:09 am     Reply with quote

set the port c direction by "set_tris_c(0x80);"
and then see the results
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