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

How to send DEC numbers over RS232?

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



Joined: 12 Dec 2003
Posts: 15

View user's profile Send private message MSN Messenger ICQ Number

How to send DEC numbers over RS232?
PostPosted: Fri Dec 12, 2003 5:22 am     Reply with quote

Dear CCS group,

hello. I am new to this group. I am glad I found such a good group. It is nice to meet you guys Very Happy

Here is my question. What I am trying to do is to send over the RS232 port decimal numbers. Whenever I send a number a get a character insteed of the number in my terminal application.

#include <16f877a.h>
#include <stdlib.h>

#fuses HS, NOWDT, NOPROTECT, PUT, BROWNOUT, LVP, NOWRT
#use delay(clock=20000000)

#use rs232(baud=9600, xmit=PIN_A1, rcv=PIN_A0, invert)


void main()
{

int8 a;
a=0; // should send me a 0

putc(a);
puts(a);
printf(a);

}

I tried with all these 3 commands but without results to get 0 on my side! I know the problem is with my c source and not with the c compiler. I was looking for it in the help and found these three commands and it says"they are for characters" but I don't know how to get it to send me values? Please, can you help me out?

Thank you

Best regards,
Refa
tut
Guest







PostPosted: Fri Dec 12, 2003 6:32 am     Reply with quote

putc(a+'0');
or
printf("%i",a);
tut
Guest







PostPosted: Fri Dec 12, 2003 6:34 am     Reply with quote

note to above:
putc(a+'0'); // Will only work if a>=0 or a<=9
refa



Joined: 12 Dec 2003
Posts: 15

View user's profile Send private message MSN Messenger ICQ Number

PostPosted: Fri Dec 12, 2003 7:31 am     Reply with quote

Dear Tut,

thank you very much for your help.

Best regards,
Refik
wedilo



Joined: 16 Sep 2003
Posts: 71
Location: Moers, Germany

View user's profile Send private message

PostPosted: Mon Dec 15, 2003 2:45 am     Reply with quote

Helo refa,

For those an similar problems have a look at the ccs compiler manual under the 'printf' command abbr. function
http://www.ccsinfo.com/ccscmanual.zip

You need it always...

73 Sven
refa



Joined: 12 Dec 2003
Posts: 15

View user's profile Send private message MSN Messenger ICQ Number

PostPosted: Mon Dec 15, 2003 3:51 am     Reply with quote

Thank you Wedilo. I will download it now Smile
Fredrik
Guest







PostPosted: Tue Dec 16, 2003 12:22 pm     Reply with quote

Take a look at http://www.asciitable.com. You might find that useful.
refa



Joined: 12 Dec 2003
Posts: 15

View user's profile Send private message MSN Messenger ICQ Number

PostPosted: Tue Dec 16, 2003 2:03 pm     Reply with quote

Thx Fredrik it will help of course. Smile
Dargar



Joined: 12 Dec 2003
Posts: 25

View user's profile Send private message

? Why %i ?
PostPosted: Fri Jan 16, 2004 8:40 am     Reply with quote

tut wrote:
putc(a+'0');
or
printf("%i",a);



In my list over format characters, I don't see an "i" anywhere?

In a related question to Refa's question:
If I have a 10bit ADC and read it into a variable of type int16
int16 ADValue;
Then I "shift in" additional information so I have 4 data bits + 10 ADC bits in my ADValue variable.

Now, I want to send it over the RS-232 link that I have, but if I say
printf("%l",ADValue);
then in what order will I recive the data at the other end?
Will the first 8 bits that I receive be "bit15" through "bit8" and then the next "bit7" through "bit0"?

Also, how can I poll/wait to see when the TXREG output buffer is empty? That is, the UART is ready to send a new character? In assembler I would just check the TXSTA and wait until it was cleared but I don't know how to do such low-level things from within CCS?


That was a lot of questions, and I hope someone will help me. I have the Development kit, so you can refer me to pages in the manual if you want to, where appicable.

Thanks.
Kjell-Edmund Ims, Engineering Student
Ttelmah
Guest







Re: ? Why %i ?
PostPosted: Fri Jan 16, 2004 10:18 am     Reply with quote

Dargar wrote:
tut wrote:
putc(a+'0');
or
printf("%i",a);



In my list over format characters, I don't see an "i" anywhere?

In a related question to Refa's question:
If I have a 10bit ADC and read it into a variable of type int16
int16 ADValue;
Then I "shift in" additional information so I have 4 data bits + 10 ADC bits in my ADValue variable.

Now, I want to send it over the RS-232 link that I have, but if I say
printf("%l",ADValue);
then in what order will I recive the data at the other end?
Will the first 8 bits that I receive be "bit15" through "bit8" and then the next "bit7" through "bit0"?

Also, how can I poll/wait to see when the TXREG output buffer is empty? That is, the UART is ready to send a new character? In assembler I would just check the TXSTA and wait until it was cleared but I don't know how to do such low-level things from within CCS?


That was a lot of questions, and I hope someone will help me. I have the Development kit, so you can refer me to pages in the manual if you want to, where appicable.

Thanks.
Kjell-Edmund Ims, Engineering Student

%l, is not a legitimate printf command. the 'l' character, can be used as a 'prefix' to many of the other commands to trigger the handling of a 'long', but does nothing on it's own.
printf, does not output the 'bits', it outputs a _converted form_ of the data, as (say), a decimal number, or a hex number etc..
Generally, it might well be worth sending a hex number, since this is much more 'readable'.
To output the binary bit pattern stored in the 'ADvalue' variable, use something like:

putc(make8(ADvalue,0));
putc(make8(ADvalue,1));

The standard for asynchronous comms, is that the LSB, is sent first.
You can basically do exactly the same 'polling' operation in CCS C.
The actual declarations, will depend on the chip being used, but:

#bit TRMT=0xFAC.1 //on a 18Fxx2

Then in the code, you can wait with:

while (!TRMT) ;

Remember that in C, a '1', is 'true', so to wait till it goes to '1', you have to logically invert the bit being read.

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