|
|
View previous topic :: View next topic |
Author |
Message |
Rune Guest
|
#use rs232 with two TX lines |
Posted: Wed Dec 04, 2002 2:23 am |
|
|
Hi
Is it possible to define to TX pins with the #use RS232 macro?
I would like to send the same information on both pins, but I will only receive data on one pin.
Ex. #use rs232(baud=9600, xmit=pin_c6,pin_c7, rcv=pin_c5)
Have anyone tried this?
___________________________
This message was ported from CCS's old forum
Original Post ID: 9753 |
|
|
Laurent chouinard Guest
|
Re: #use rs232 with two TX lines |
Posted: Wed Dec 04, 2002 7:22 am |
|
|
Yes, i've done that because i needed more horsepower for the TX line. Unfortunately, you can't do it easily for two reasons:
1) If you are using the built-in USART, it can only transmit on ONE pin.
2) If you are using the CCS software rs232 functions, they also can only transmit one ONE pin.
BUT, you can code your very own transmit function if you don't mind not using a USART. The consequence is that the byte will never be transmitted by themselves, your PIC will have to wait for each byte to be completely sent before doing anything else.
In this example, "mybits" sets the two bits of the port i want to use, bit 3 and 4, so that's C5 and C6. You can use as many ports as you want (up to the entire C port). You can substitute references to the output_c for output_b.
#define mybits 0b00011000
#define DELAY_BAUDRATE 195 //195 = 9600 bauds when XTAL = 8MHz (104 uS per baud)
// put this line in your powerup sequence:
setup_timer_2(T2_DIV_BY_1,255,15);
void tx(int8 i) // Sends ONE byte
{
int j;
output_c(input_c() | mybits); //high
set_timer2(0); // Start bit
for(j=0; j<8; j++) // We send our byte here
{
if(bit_test(i,j))
{
while(get_timer2() < DELAY_BAUDRATE);
output_c(input_c() & !mybits); // bit low
set_timer2(0);
} else {
while(get_timer2() < DELAY_BAUDRATE);
output_c(input_c() | mybits); // bit high
set_timer2(0);
}
}
set_timer2(0);
while(get_timer2() < DELAY_BAUDRATE);
output_c(input_c() & !mybits); // bit low
set_timer2(0); // Stop bit
while(get_timer2() < DELAY_BAUDRATE);
}
Danger danger will robinson! I haven't tested this code so it *might* not work. I've cut that from my own program, but my real function is twice as long because it deals with much more that this.
___________________________
This message was ported from CCS's old forum
Original Post ID: 9761 |
|
|
|
|
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
|