Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 10th October 2007, 06:27 AM   (permalink)
Default convert int to char dspic30f

Hi
The mplab c30 compiler does not support itoa() function.
how do I change a hex number ie 0x55 to become a char '55' without using the printf().
Thanks
kenobe is offline  
Old 10th October 2007, 07:59 AM   (permalink)
Default

There is probably some easier way but this gets the job done,

Code:
	intVal=0x34;
	charout[0]=(intVal>>4)+0x30;
	charout[1]=intVal&0x0f+0x30;
Mike.
Pommie is offline  
Old 10th October 2007, 08:23 AM   (permalink)
Default


Hi Pommie
Thanks for your help.
but what I need is charout[0] = 55 , not charout[0]=5, charout[1]=5
kenobe is offline  
Old 10th October 2007, 08:46 AM   (permalink)
Default

Isnt't that just

charout=(char)intVal;

or even,

charout=intVal&0xff;

Mike.
Pommie is offline  
Old 10th October 2007, 09:28 AM   (permalink)
Default

I tried that too, but mplab c30 compiler does not work with casting and masking ,so it still does not solve the problem.
kenobe is offline  
Old 10th October 2007, 03:21 PM   (permalink)
Default

Quote:
Originally Posted by kenobe
I tried that too, but mplab c30 compiler does not work with casting and masking ,so it still does not solve the problem.
I found this hard to believe and so, I just tried the following,
Code:
#include <p30f2010.h>

unsigned int x;
unsigned char outchar;

int main(void){
	x = 0x45;
	outchar=(char)x;
	x = 0x45;
	outchar=x&0xff;
	x = 0x45;
	outchar=x;
	while(1);
}
It did exactly what I expected it to do.

Maybe you should post an example of what doesn't work.

Mike.
Pommie is offline  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
Title Starter Forum Replies Latest
c++ convert argv[1] to a char array danielsmusic Chit-Chat 5 18th March 2006 02:09 PM
revew code please Seb Micro Controllers 1 22nd February 2005 02:15 PM
I2C Master write problem using SSP (here's code) Oznog Micro Controllers 1 16th October 2004 06:48 AM
HOW TO CONVERT HEXA TO DECIMAL FOR LCD, PLS HELP!!!!!!!! AUNG THANT Micro Controllers 3 10th April 2004 01:38 PM
PIC 16f84A and PowerTip Alphanumeric display 27 Micro Controllers 1 9th March 2004 03:19 PM



All times are GMT. The time now is 06:58 PM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker