I am using a TI Tiva arm micro-controller. I want to access a specific bit of a 8-bit register (GPIO_PORTF_DATA_REGISTER) and put its value in an other register. I found examples where people did like
GPIO_PORTF_DATA_REGISTER &= 0x01;
to access the first bit, but doesnt this make the 0th bit of the register 1? i just want to put the 0th bit in say In.
unsigned char In;
In = GPIO_PORTF_DATA_REGISTER|0x01; ( Is this correct?)
Ok GPIO_PORTF_DATA_REGISTER & 0x80= 0x80; sets the 7th bit.
Now have an integer say bitval, and I say to my compiler,
In = GPIO_PORTF_DATA_REGISTER; and when I use the In integer somewhere else, i can't see the current value of the 7th bit of GPIO_PORTF_DATA_REGISTER register when i use In. Alternatively i define the In variable at the 7th bit address and that works.
No, It doesn't set the bit. If that GPIO was already set then you get that value else you get 0. See for example I took GPIO value as 0xFF. So all bits were set. Anding 7th bit resulted in true and the value after anding is 0x80 for 7th bit.
After much thought I still cant seem to run the program correctly. I have a problem with learning ucontrollers, The think i want to do is to call a function if both switches(SW1 and SW2) are pressed simultaneously. Here is my main...
SW1 is at the 4th bit of the register.
SW2 is at the 0th bit of the register.
Both are negative logic(connected to pull-up resistors).
Flash_SOS is the function I want to call. The above program doesn't work and I cant understand why.