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

Type conversion problem in PIC

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








Type conversion problem in PIC
PostPosted: Sat Dec 13, 2008 9:50 am     Reply with quote

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,
Quote:
ff00ff00b10 5000

Instead of value of "val" , I get a blank.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Dec 13, 2008 12:21 pm     Reply with quote

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:
Code:
val = '2';
Guest








PostPosted: Sat Dec 13, 2008 11:07 pm     Reply with quote

Thanks for the help
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