0

I recently started learning about the IAR embedded workbench 8051. Well, I am currently playing with the LED only. I am using CC2540 BLE chip to do this. Let's say I have 8 pins of LED but I only want to control only 2 pins by not affect other 6 pins, how to code it using bitwise operators? I set all the pin for GPIO using this code P1SEL = 0;, my friend told me if I type the code like this will affect others pins. What if I declare it P1SEL = 0xFC;? Will others pin be affected?

Ah Îoon
  • 49
  • 1
  • 8
  • of course if you assign the whole register then all other pins are affected. Most common registers in 8051 are bit accessible so if you just want to change 1 pin then assign to that bit. If it's not available you need to read the whole register and change only the necessary bits – phuclv Nov 03 '16 at 04:43
  • [How do you set, clear and toggle a single bit in C/C++?](http://stackoverflow.com/q/47981/995714). Multiple bits just do the same. [Set output pins on the CC2540 USB dongle](https://e2e.ti.com/support/wireless_connectivity/bluetooth_low_energy/f/538/t/436679) – phuclv Nov 03 '16 at 04:46
  • Thanks for your answer =), I will read it. – Ah Îoon Nov 03 '16 at 05:33

1 Answers1

0

Actually, you can use & and | to set a specific bit.

P1SEL = P1SEL & (~(1 << i)) // set bit i to 0
P1SEL = P1SEL | (1 << i)    // set bit i to 1
Mak
  • 154
  • 4