This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Logical Operator AND in uVision

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.

Parents
  • 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

Reply
  • 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

Children
  • 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