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 Bitwise

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



Joined: 07 Nov 2007
Posts: 5

View user's profile Send private message

RS232 Bitwise
PostPosted: Wed Nov 07, 2007 8:37 pm     Reply with quote

I am using a PIC16F876, not by choice, I would have preferred the 877. However, here is my problem. I am already using the built in uart, however, I need a second RS232 output. I have done this in assembly, but would like to accomplish this in C. Here is my simple code, which generates the wrong duration pulses when looked at with a scope.

Code:

void Send_One(void)
{
   output_high(PIN_C6);
   delay_us(104);
}

void Send_Zero(void)
{
   output_low(PIN_C6);
   delay_us(104);
}

void Send_Ascii(char Letter)
{
   int i = 0;

   output_low(PIN_C6);
   delay_us(104);              //Send start condition

   while(i <= 7)
      {
         if(bit_test(Letter,i))
         {
            Send_One();
            i++;
         }
         else
         {
            Send_Zero();
            i++;
         }
      }
   
   output_high(PIN_C6);
   delay_us(104);               //Send stop condition
   
}


Would it be better to use a timer instead of delay_us()?
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

PostPosted: Wed Nov 07, 2007 9:51 pm     Reply with quote

Instead of trying to code your own software UART, wouldn't you rather use the CCS feature to handle it? I'm assuming you don't know that you can do that?

Code:
#use rs232(baud=9600,parity=N,xmit=PIN_C6,bits=8)


No?
Guest








PostPosted: Wed Nov 07, 2007 10:10 pm     Reply with quote

I use the PIC uart for another task. I need to send out another rs232 string for a differnt task and have to use another port besides RC6 and 7. The port I can use is RC2.

Thanks for the reply. I use the internal uart when I can. Just this time, I need 2, and the 876 doesn't have 2.
Ttelmah
Guest







PostPosted: Thu Nov 08, 2007 3:13 am     Reply with quote

You are missing the point.
The CCS code, supports use of both the hardware UART, and generation of 'software' UARTs. If you use the two hadware pins in the #use RS232 statement, it generates short code to use the hardware UART. However if you use exactly the same line, but on pins that do not have the hardware UART, it _automatically_ generates software serial code. Hence you can use (for example):
Code:

#use rs232(baud=9600,parity=N,xmit=PIN_C2,bits=8, stream=SW_RS232)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=HW_UART)

and simply talk to whichever stream you require.

It is called "don't bother to re-invent the wheel".....

Best Wishes
Shoebie



Joined: 07 Nov 2007
Posts: 5

View user's profile Send private message

PostPosted: Thu Nov 08, 2007 8:31 am     Reply with quote

I'll give that a try. I didn't realize you could set up 2 uart software modules.

Thanks!
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Thu Nov 08, 2007 9:11 am     Reply with quote

You can have, pretty much, as many software TX pins as you want. RX pins are a different matter since you need, constantly, loop on it to watch for data coming in. I've used multiple TX pins on the same PIC with no problems. You just need to use the STREAM to tell the compiler which TX pin you want to use for that particular print statement.

Ronald
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