|
|
View previous topic :: View next topic |
Author |
Message |
refa
Joined: 12 Dec 2003 Posts: 15
|
How to send DEC numbers over RS232? |
Posted: Fri Dec 12, 2003 5:22 am |
|
|
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
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
|
|
Posted: Fri Dec 12, 2003 6:32 am |
|
|
putc(a+'0');
or
printf("%i",a); |
|
|
tut Guest
|
|
Posted: Fri Dec 12, 2003 6:34 am |
|
|
note to above:
putc(a+'0'); // Will only work if a>=0 or a<=9 |
|
|
refa
Joined: 12 Dec 2003 Posts: 15
|
|
Posted: Fri Dec 12, 2003 7:31 am |
|
|
Dear Tut,
thank you very much for your help.
Best regards,
Refik |
|
|
wedilo
Joined: 16 Sep 2003 Posts: 71 Location: Moers, Germany
|
|
Posted: Mon Dec 15, 2003 2:45 am |
|
|
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
|
|
Posted: Mon Dec 15, 2003 3:51 am |
|
|
Thank you Wedilo. I will download it now |
|
|
Fredrik Guest
|
|
|
refa
Joined: 12 Dec 2003 Posts: 15
|
|
Posted: Tue Dec 16, 2003 2:03 pm |
|
|
Thx Fredrik it will help of course. |
|
|
Dargar
Joined: 12 Dec 2003 Posts: 25
|
? Why %i ? |
Posted: Fri Jan 16, 2004 8:40 am |
|
|
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 ? |
Posted: Fri Jan 16, 2004 10:18 am |
|
|
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 |
|
|
|
|
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
|