![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
Grokiff
Joined: 25 Mar 2015 Posts: 2
|
replace built in rs232(), getc() and putc() functions |
Posted: Tue Mar 31, 2015 8:20 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Tue Mar 31, 2015 8:30 am |
|
|
Why? |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19372
|
|
Posted: Tue Mar 31, 2015 8:57 am |
|
|
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'. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|