I am able to use the pins P0 to p7 as a current sink and light LEDs ( i.e. the LEDs are connected to voltage source and then to the pins)
But I am unable to ( or rather do not know how to) do the opposite. i.e. use P0 to P7 as a voltage source to power the LEDs
The datasheet says the the pins are quasi-bidirectional.
Also Page 7 shows the different configuration.
My questions:
1. Does the default configuration (current sink) mean 'Output LOW' ?
2. To convert the PIN to a source I will need it to be in 'Input HIGH' config ?
3. Is my assumption that I have to attach a pull-up resistor at the pins to +5V to convert the pin to a source correct ?
4.If the above 3. is correct, then how do I calculate how much resistance to add? in the pull-up?
You can't source current with that type of I/O - it's known as open collector and can only pull the pin low. Actually, it can pull it high but with a very tiny current capability (100μA).
1. Yes.
2. Yes but it can only supply 100μA.
3. This is built into the chip. Edit, this is what supplies the 100μA.
It is not that there is something particular I have accomplish with this circuit but just demonstrate conceptually that it can be done even if the current is 100μA.
The thing is not being a electrical or electronic engineer sometimes what can be considered common sense in this domain is not exactly present for me. ( Example: the setup is called an open collector.)
I had a followup question:
2. Shouldn't it be OUTPUT HIGH (rather than INPUT HIGH) for me to obtain the 100μA.
Also, is the voltage at the pin with 100μA is 5v ? that is the supply voltage ?
Think of it as there only being a switch from the output to ground and a very high resistance(10k) from the output to 5V. When the switch is turned off the pin acts as an input AND a very high impedance output. If you connected an LED from the pin to ground then the pin will be pulled down by the LED - probably to 2V and so your current will drop to 50μA - the power illuminating the LED will be 100μW. I doubt you will be able to see any light from the LED. I can't find any data on LEDs at such microscopic power levels.
Note, input high turns the switch off and so the output will go high via the resistor.