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

replace built in rs232(), getc() and putc() functions

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



Joined: 25 Mar 2015
Posts: 2

View user's profile Send private message

replace built in rs232(), getc() and putc() functions
PostPosted: Tue Mar 31, 2015 8:20 am     Reply with quote

Hi,

I try to replace the built in #use rs232(), getc() and putc() functions

my rs232() looks like :
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7);

Regarding the PIC datasheet, I've started with :
Code:

#byte TRISC       = getenv("SFR:TRISC")
#bit TC0       = TRISC.0
#bit TC1       = TRISC.1
#bit TC2       = TRISC.2
#bit TC3       = TRISC.3
#bit TC4       = TRISC.4
#bit TC5       = TRISC.5
#bit TC6       = TRISC.6
#bit TC7       = TRISC.7

#bit SPEN      = RCSTA.7

void my_rs232(int16 bds)
{
   SPEN = 1;
   TC6  = 0;
   TC7  = 1;

}

void my_putc(char c)
{
}

char my_getc()
{
}


after that, I can't understand what to do.

Anyone can help me ?

Thanks a lot
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Tue Mar 31, 2015 8:30 am     Reply with quote

Why?
Ttelmah



Joined: 11 Mar 2010
Posts: 19372

View user's profile Send private message

PostPosted: Tue Mar 31, 2015 8:57 am     Reply with quote

Honestly for standard serial I/O there is no reason to change them. If you dismantle the code it is as efficient as it can be.

However if (for instance) you want to do this because you are using another UART chip for example, then the compiler does actually allow you to use other functions to replace it's calls.
In general though, just use the functions you have.

Where currently you call 'getc', call 'my_getc' instead. Where you use putc, use 'my_putc' instead. For printf, use printf(my_putc... etc..

There is a lot more you need to do in the functions though. The putc, needs to test if the UART has space, and only when it has, write the character. The getc, needs a 'kbhit' equivalent, to check if a character is available, and when it is, need to read this from the UART. Your #USE RS232, _should_ have the ERRORS declaration (this should _always be included when using the hardware UART, unless you are clearing errors yourself - without this the UART can become hung_). It really should be the default, and is silly that it isn't. Your getc equivalent is going to need the code for this (check the error bits, and if set, read a character, disable the UART, and re-enable the UART).

Also just look at the assembler for getc/putc. You'll see what CCS do.

The way to replace the calls, is with:
Code:

#use rs232( CALL_PUTC=myputc,  CALL_GETC=mygetc,  CALL_KBHIT=mykbhit )


But honestly I have to say 'don't do this unless you have a very good reason to do it'.
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