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

Printf and how long strings are transmitted

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



Joined: 12 Dec 2003
Posts: 25

View user's profile Send private message

Printf and how long strings are transmitted
PostPosted: Tue Jan 27, 2004 6:21 am     Reply with quote

I am not at all fluent in more advanced assembler (hence CCS, right) but right now I wish I was.

One thing is bugging me:

C is a "serial" language (I think) so that commands are executed after one another.. However, depending on the compiler (I guess) you can do some pseudo parallell programming when you use printf..

My question:

If I run this:

printf("looooooooooooooooooooooooooong string");
output_low(RedLED); //Lights up a red LED.

Will the compiler create a string buffer, start transmitting one character, light the diod, "interrupt" when it is ready for the second character and so on, or will my program have a (relatively) long "pause" while printing out the string?

If it "pauses" (finishes the printf) before moving on, how long time does it take to transmit one char out of the TX register @ 9600 baud? With that in mind, I could code like this:

printf("A");
//do stuff that takes > than transmitting 'A'
printf("B");
//do stuff that takes > than transmitting 'B'
printf("CD");
//do stuff that takes > than transmitting 'CD'

and so on, to make the most use of my cycles?

Or maybe the compiler doesn't do the next command until the TX is empty? Does it just place a character in the TX register and move on?
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Tue Jan 27, 2004 8:53 am     Reply with quote

If you want the transmit to operate "in the background" using an interrupt, with CCS you have to write code for the #INT_TBE RS232 transmit buffer empty interrupt.

Go to the help file and find the entry on #INT_TBE. Read it and then go look at the example programs suggested at the bottom of the file.

That should get you on your way to writing something.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
Ttelmah
Guest







Re: Printf and how long strings are transmitted
PostPosted: Tue Jan 27, 2004 4:18 pm     Reply with quote

Dargar wrote:
I am not at all fluent in more advanced assembler (hence CCS, right) but right now I wish I was.

One thing is bugging me:

C is a "serial" language (I think) so that commands are executed after one another.. However, depending on the compiler (I guess) you can do some pseudo parallell programming when you use printf..

My question:

If I run this:

printf("looooooooooooooooooooooooooong string");
output_low(RedLED); //Lights up a red LED.

Will the compiler create a string buffer, start transmitting one character, light the diod, "interrupt" when it is ready for the second character and so on, or will my program have a (relatively) long "pause" while printing out the string?

If it "pauses" (finishes the printf) before moving on, how long time does it take to transmit one char out of the TX register @ 9600 baud? With that in mind, I could code like this:

printf("A");
//do stuff that takes > than transmitting 'A'
printf("B");
//do stuff that takes > than transmitting 'B'
printf("CD");
//do stuff that takes > than transmitting 'CD'

and so on, to make the most use of my cycles?

Or maybe the compiler doesn't do the next command until the TX is empty? Does it just place a character in the TX register and move on?

The compiler contains no buffer handling. There is example code for this in the supplied samples. However (assuming a hardware serial is used), there are a couple of characters buffered here, so the routine will return with these still 'unsent'.
The transmit time, depends on your data format. 9600bps, says that 1bit is sent every 1/9600th second. The 'word' sent, normally comprises a start bit, the data length requested in the #use RS232 (7 or 8 bits), a parity bit (in enabled in the #use RS232), and a stop bit. Using 8bits, no parity, the whole character, is then ten bits (1/960th second).
Realistically the 'best' way, is to use the serial buffer code, and if you want events to occur at times, the hardware timers to trigger these.
The 'serial' nature of C, is dependant entirely on the implementation. In many larger C's, you can launch seperate 'threads'. In the CCS C, you have the #intxxx handlers, which are triggered by hardware events.

Best Wishes
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