I need to know what is wrong with uVision. I had not seen this before.
I wrote this piece of code in uVisio, the program is not working well. When I simulated it, I realized the compiler is not doing the right process:
void Write_LCD(unsigned int A ){ unsigned int E; E=0xf0&A; //here is the problem*** LCD_Data=e; ... }
in ***, E=0xf0&A, the compiler does not execute the ligical operation AND, it passes the value of A to E and when I put parenthesis, this is E=(0xf0&A); it puts 0x00 to the variable E. I wonder what is wrong with this instruction?
Thanks for your help.
Do you ever use E after that statement?
so 'e' and 'E' are two completely different variables...
this may sound silly, but if 'A' is less of equal than 0xF, 'E' will always be assigned 0, of course. 'E = A' will happen if 'A' >= 0xF0.
'E = A' will happen if 'A' >= 0xF0.
oops. a mistake but I think you get the spirit of what I was trying to say...!
.
What I need is to pass the upper nible of the variable, when working with a 4-bit LCD . A very simple way is to make an AND operation, example. A= 0x28 and I want to pass 0x20 first and then 0x08 so the operation LCD_Data=(0xf0&A); //should pass 0x20 only the point is that the compiler is passing 0x28, But the ocmpiler is working wrong.
I made a mistyping, is not 'e' it is 'E'
oespinos
Erik, how can I desable the optimizer? That could solve the problem. it sounds to be the problem because I do not find a problem, actually. The same code works good with SDCC, but I need to enter in Keil because of the company I work for.
thanks oespinos
LCD_Data = 0xF0 & A;
This Could be valid code. It is less likely that you found a compiler bug in a common statement. Post the smallest amount of code that shows the problem. Copy and Paste it. This avoids new bugs, and you correcting any bugs during the retyping.
By the way if you want the upper nibble
LCD_Data = A >> 4;
would be a better choice
LCD_Data = 0xF0 & A; first, although somewhat irrelevant (and should be valid) I have never before seen the above. All I know of writes LCD_Data = A & 0xf0; which is more like what you would say
Post ... code Copy and Paste it. and it should be commented
Erik
I can not recall hoiw many threads have gone astray because the 'bug' discussed was in the retype, not in the code in question
how can I desable the optimizer if you use the IDE i do not have the foggiest, in commandline mode you insert OT(2) in the compile line
If you want to reduce the optimization, use the 'volatile' keyword, or enter the 'options for target' dialogue, compiler tab, code optimization level.
P.s. Is this entire thread a wind up?