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 CCS Technical Support

how to printf/putc "0x00"

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



Joined: 24 Jul 2014
Posts: 6

View user's profile Send private message

how to printf/putc "0x00"
PostPosted: Sun Jul 27, 2014 6:13 pm     Reply with quote

Dear all,

I am writing a program for wireless transmission where there may be instances where transmission of 0x00 is necessary via TX port.

Does anyone have any idea how that can be achieved?

for example, my array is something like:

char array[3]={0x11,0x00,0x22};
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jul 27, 2014 7:04 pm     Reply with quote

Just do
Code:
putc(0);

If you have an array, then step through it with a for(;;) loop.

----------
If you actually want to send a 'break' (and not a 0x00 character), then
read this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=46459
Also, always tell us your PIC. Some PICs have the ability to send a
break with the hardware UART.

UART break:
http://en.wikipedia.org/wiki/Universal_asynchronous_receiver/transmitter#Break_condition
Ttelmah



Joined: 11 Mar 2010
Posts: 19499

View user's profile Send private message

PostPosted: Mon Jul 28, 2014 2:04 am     Reply with quote

Lets just give a fractional 'explanation'.

0, ('\0' in C), is a perfectly normal character. Can be sent just the same as any other.
The only 'difference' about 0, is that internally, 'C' uses this as an 'end of string' marker. So any _string_ functions, will stop when they reach 0.
So if you use string functions, then there is a problem. However if you ignore string functions, 0 can be sent as a character, no problem at all.

So for the array, simply looping through for the entire size (sizeof?...), of the array, is perfectly legitimate, and 0 can be sent as easily as anything else.

Separately though, async serial, uses a 'continuous 0' (where the output line goes low, and stays low without any 'start' or 'stop' bits, for a defined time longer than a character), as a 'break'. The name comes from the simple thing that this was what was seen, if the wire was broken. The 'break' transmission is commonly used as a trigger for certain operations, so (for instance) things like modems will often institute a 'reset', when they receive a 'break'. The thread PCM_programmer points to, is about 'how to send a break' if this is what is needed.

You need to get the difference 'clear in your head', and know which you actually need (and if the device needs a 'break', how _long_ it needs this to be).
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