View previous topic :: View next topic |
Author |
Message |
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
How to relocate the software UART code |
Posted: Wed Apr 21, 2004 6:00 pm |
|
|
Hi all
Is it possible to specify the code location for the software UART? I've tried using the #org directive right before #use r232, but the compiler still puts the code wherever it pleases. Thanks. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Apr 21, 2004 9:20 pm |
|
|
Quote: | Is it possible to specify the code location for the software UART? | You can do it by putting the "Default" parameter at the
end of your #org statement. This tells the compiler to
put internal library code in the #org'ed segment.
You can restore the compiler behavior back to normal
by putting a "#org Default" statement by itself after
after your #org'ed code. This will tell the compiler
that it's OK to put library functions in low ROM again.
In the example below, the software USART code for
getc and putc is in the 0x1800 ROM segment.
The library code for delay_ms is at 0x0004.
This was tested with PCM vs. 3.190.
Code: | #include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
//======================================
#org 0x1800, 0x1FFF default
char my_function(char c)
{
// Specify a software USART.
#use rs232(baud = 9600, xmit=PIN_B1, rcv=PIN_B0)
char retval;
putc(c);
retval = getc();
return(retval);
}
#org default // Allow library code to be in low ROM again
//================================
void main ()
{
delay_ms(1);
my_function(0x55);
while(1);
}
|
|
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Fri Apr 23, 2004 2:17 am |
|
|
Thank you. The key was to put the #use statement inside the function. |
|
|
|