This can make using things like buttons simpler because it removes the need for a pull-up on the circuit.
I wondered if it was possible to make a simple program to turn on the pullup resistor for a pin - and came up with this.
Calling Pullup with a port ('B', 'C' etc depending on MCU) and a pin (0..7 - again MCU dependent) - calculates a bit mask and the address of the relevant DDR and PORT register (the ports handily separated by 3, starting with port B) Then applies the bit mask to the registers.
Test with an LED between the pin and ground (no need for a resistor)
This seems to work AOK..
But - is there a better way to do it? I can use a property and get port and pin from a 'single digital pin' using Property.GetValue - but I'm uncertain how I could 'write' the necessary 'C' code in (and at what point in the program?)
ie - generate :
Code: Select all
mask = 1 << pin;
DDRx &= ~mask;
PORTx |= mask;
Martin