|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
Type conversion problem in PIC |
Posted: Sat Dec 13, 2008 9:50 am |
|
|
Hi
I have a function in my program that I should pass a char value to it. That char value contains in a int8 variable. So I convert the int8 variable to a char value,
Code: |
int8 myvalue;
char val;
myvalue= 2;
val = (char)myvalue;
|
And I pass the "val" to another function and send the data out through UART.
But I am getting a blank where I should get the value of "val" . Other char values are displayed correctly. Is this a problem with the type conversion ??
Following are the functions used to transmit data through UART.
Code: |
void TBE_isr(void) {
if (tx_counter != 0) {
putc(tx_buffer[tx_rd_index]);
if (++tx_rd_index > TX_BUFFER_SIZE) {
tx_rd_index = 0;
}
tx_counter--;
if (tx_counter == 0) {
disable_interrupts(INT_TBE);
}
}
}
void bputc(int c) {
int restart = 0;
if (tx_counter == 0) {
restart = 1;
}
tx_buffer[tx_wr_index++] = c;
if (tx_wr_index > TX_BUFFER_SIZE) {
tx_wr_index = 0;
}
tx_counter++;
if (restart == 1) {
enable_interrupts(INT_TBE);
}
}
|
And in main,
Code: |
createPacket(ptr,'f','f','0','0','f','f','0','0','b','1','0',val,
'5','0','0','0');
for (a=0;a<16;a++)
{
bputc(*(ptr + a)); //send the prepared packet
}
|
My output is,
Instead of value of "val" , I get a blank. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Dec 13, 2008 12:21 pm |
|
|
Quote: | int8 myvalue;
char val;
myvalue= 2;
val = (char)myvalue; |
You don't have to do this. In CCS, char and int8 are the same thing.
Quote: | myvalue= 2;
val = (char)myvalue;
createPacket(ptr,'f','f','0','0','f','f','0','0','b','1','0',val, '5','0','0','0'); |
All the other values in the packet are ASCII bytes. You can see them
on a terminal window. But val does not have an ASCII number in it.
That's why you can't see it. Change it to this:
|
|
|
Guest
|
|
Posted: Sat Dec 13, 2008 11:07 pm |
|
|
Thanks for the help |
|
|
|
|
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
|