I have a digital input to a microcontroller in the +5V Domain.

This digital input is connected to the Microcontroller. The output of the Microcontroller is connected to an LED

Initial LED Logic :

Input - High, Output - High (LED Glow)

Input - Low, Output - Low (LED OFF)

Suppose, with the same Input hardware, i.e. Input - High, can I change my LED logic within software itself so that I can achieve LED = OFF when Input is High and LED = ON when Input = LOW.

Now required LED Logic :

Input - High, Output - Low (LED OFF)

Input - Low, Output - High (LED Glow)

Can I change the Initial LED Logic in software? If so, why not?


  • \$\begingroup\$ It depends on what you can control. If you can reprogram your microcontroller, then of course you will be able to do that. If you can not change the program in the microcontroller, then you have to change the LED logic in hardware. \$\endgroup\$ – Wheatley Oct 10 at 8:32
  • 1
    \$\begingroup\$ " I have the board programmed with the initial LED Logic." - do you have the source code for that program? \$\endgroup\$ – Bruce Abbott Oct 10 at 9:30
  • 1
    \$\begingroup\$ No.. I dont do the coding. And I will not be provided with the code \$\endgroup\$ – Newbie Oct 10 at 9:33
  • 2
    \$\begingroup\$ @Newbie - This situation doesn't seem to make sense. In the question, you said that you want to "change the Initial LED Logic in software". But in your reply to a comment, you just said that you "will not be provided with the code". How are you expecting to change the software, if you won't be given the code?! If you won't be given the source code, then some experienced engineers may be able to modify the final object / executable code, but that is out-of-scope for your level of question here. So the contradiction remains, of you wanting to change the software, without access to it! \$\endgroup\$ – SamGibson Oct 10 at 13:10
  • 1
    \$\begingroup\$ It sounds like the questions boils down to "Can software on a microcontroller effect the state of a GPIO?, which is obviously true. There is nothing left to discuss. OP won't even provide the code. \$\endgroup\$ – Bort Oct 10 at 14:36

Can I change the Initial LED Logic in software?

I don't know why this has attracted so much comment - the answer is almost certainly "yes". It will require finding the part of the software that sets the output and inverting the value.

Exactly how to do that we can't help you without the source code.

  • \$\begingroup\$ I guess it has attracted so many comments since the answer of 'Yes' is so obvious that there must be more to this question than what has been asked. \$\endgroup\$ – HandyHowie Oct 10 at 10:24
  • Sane PCB designs connect one side of the LED to 1 pin and the other side to Vdd or ground. Because MCU pins are valuable resources.
  • If you for some reason don't have a sane PCB design but use 2 pins, then both MCU pins need to be configured as outputs or nothing will happen. A pin set as input cannot source/sink current.
  • The anode of the LED needs to be driven high and the cathode needs to be driven low/grounded, or nothing will happen. Obviously you can't change these the other way around, because a diode is a semiconductor.

Thus "Input - High, Output - High (LED Glow)" doesn't make any sense.

Note that the pins need to be able to source/sink the current needed for the LED, which isn't necessarily the case for all MCUs (this is fine on MPC56 though).

  • \$\begingroup\$ I think an LED connection to an MCU without a resistor is typically insane! \$\endgroup\$ – Bort Oct 10 at 14:41
  • \$\begingroup\$ @Bort I'm obviously assuming that there's a resistor or things will fry quickly. \$\endgroup\$ – Lundin Oct 10 at 14:59
  • \$\begingroup\$ I know, I'm just joking because you said it goes from MCU to VDD/ground. \$\endgroup\$ – Bort Oct 10 at 15:03

You state that you can't change the software even though you ask how to do it. Since this doesn't make sense, here is a suggestion to invert the logic in hardware.

From your question it might be that your circuit is approximately like this:


simulate this circuit – Schematic created using CircuitLab

Then you can change it into:


simulate this circuit

Now the LED it lit when the output level is LOW.

If you can't change the software by yourself you may be able to order the change. A software change by editing the source is mostly trivial.

Another possibility is to patch the software if you get to know where and by what bytes. This is not a trivial task and might need a lot of research and disassembly.

  • 1
    \$\begingroup\$ This isn't what the question states though, only the input state changes the output state, the LED is still off when the pin is low and on when the pin is high. This is purely an inversion in the microcontroller logic, no board changes necessary. \$\endgroup\$ – Ron Beyer Oct 10 at 12:20
  • \$\begingroup\$ @RonBeyer the askers comments make it sound like changing the software isn't an option, which puts changing the hardware on the table. Realistically the question is unclear and should be closed. \$\endgroup\$ – Chris Stratton Oct 10 at 13:27
  • \$\begingroup\$ @DaveTweed Thanks for correcting the Vcc end! I didn't find any symbol for it and forgot to put a label on it. \$\endgroup\$ – the busybee Oct 10 at 13:59
  • \$\begingroup\$ Keep in mind that CircuitLab is a simulator, too. The ground symbol always means ground, no matter how you orient it or label it. \$\endgroup\$ – Dave Tweed Oct 10 at 15:13
  • \$\begingroup\$ @DaveTweed I know, I just wanted to show schematics without having to run another software. ;-) \$\endgroup\$ – the busybee Oct 10 at 18:20

Not the answer you're looking for? Browse other questions tagged or ask your own question.