Converting string to int in 'C'

S

shp

Guest
hello..

I am working with CFAF320240 Display...
In program 0xBCAB is used to represent 16 bits hexadecimal value..

In C program i have a value "0xBCAB" in String..
I want to convert this value in Unsigned integer..but it stop at "x" position while x is not a hexadecimal character or a digit..

How can i convert this..??
please help me...

thanks in advance..
Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.
 
In C program i have a value "0xBCAB" in String..
I don't understand why you have this value is string form. Is it coming as an input from outside the program? If not, it would be easier if you declared the value as:

unsigned int varname = 0xBCAB;

To do a string conversion, you should skip the "0x" part:

char varstring[] = "0xBCAB";
sscanf (varstring+2, "%x", &varname);
 
S

shp

Guest
hello...COSMICVOID

thanks for ur reply..

in my program i alredy defined unsigned int = 0xADCB..

but i want to change the value of CB to other value say 23 & AD to other value say EF..
& then i want this changed value in "0x23EF" in this format..because this value going in one register..
& this register understand value in this format...
so i need this...
 
There is no processor, that I am aware of, which needs register values in string format. I am completely baffled at what you are trying to do, and you aren't giving enough information for me to understand.
 
S

shp

Guest
..Check this file..

..Hello..COSMICVOID

thank u for ur reply..
i send u code which i wrote..
check the files..

Thank u in advance..
 

Attachments

I have looked at your code. :eek: I don't understand why you were trying to use "malloc()" in an embedded system with very limited RAM. You should not need any large blocks of memory to do LCD screen writes.

I found your use of the registers to create drawing areas to be very confusing, and I did not try to analyze it closely.
Code:
	write_command(0x0044); 
	write_data(ve_vs);
	write_command(0x0045);
	write_data(hs);
	write_command(0x0046);
	write_data(he);
I am also baffled by this:
Code:
unsigned char htod_vse(int s,char h)
{
	unsigned char p = s >> (8*h);	
 	return p; 
}
.....
	dec[0] = htod_vse(ve_vs,0); // Verticle Start Value
	dec[1] = htod_vse(ve_vs,1); // Verticle End Value
It seems to me that this would be easier to understand:
Code:
	dec[0] = ve_vs & 0xFF;
	dec[1] = ve_vs >> 8;
It is also very peculiar that you put code and data in an include file. Did you ever figure out that you can have more than one ".c" file (and more than one ".h" file) in your project??

In any case, if you can't get your program to work, you should take another look at mine, since I have ported it to an AVR board and used AVR Studio to compile it. You can see from the screen shot that it works.

Maybe you can modify your fat font to work with my code. In my font tables, each column of the character pattern is one WORD, 16 bits (unsigned int), with D0 the top pixel and D15 the bottom pixel. There is also a table of lengths that contains the number of columns for each character, so they can be different widths (proportional width instead of fixed width).

https://forum.crystalfontz.com/showpost.php?p=27968&postcount=1
 
S

shp

Guest
..

hello...COSMICVOID

Thanks for ur reply..

ur solution is working
but tell me how this two statements r worked..??

dec[0] = ve_vs & 0xFF;
dec[1] = ve_vs >> 8; // This shifting 8 bits..

I try to use ur code in my program..& then tell u it works or not..
Thank u very much for ur reply...
 
S

shp

Guest
..Hello

Hello..COSMICVOID

sorry for the questions..but i am new in Embedded system..i do this first time..

I saw cfaf320 files..i understand ur logic..
but how can i use that in my program..??
because u directly put color onto bus..i have no option for this..
can u please tell me how i can use ur logic related to my program or what i have to change in my program..??

thanks in advance..
 
... I saw cfaf320 files..i understand ur logic.. but how can i use that in my program..??
You can use it any way that you want to. If you understand what is being done in each function, then use the function.
because u directly put color onto bus..i have no option for this..
This is not true. You are also putting color directly onto bus:
Code:
	if(array[i][j] == 1)
		{write_data(text_color);}
	else
		{write_data(area_color);}
.
.
void write_data(unsigned int data)
{
...
	PORTA=data;	// data on the bus
	PORTE=data>>8;	// data on the bus
...
}
If this is not what you mean, you need to explain better.
 
S

shp

Guest
..Hello

Hello..COSMICVOID..

thanks for ur reply & explanation..
i use ur functions in my program...

thank u very much..
 
Top