The maniacbug mighty1284 core for ATMega1284, which can also be used on ATMega644, was before the introduction of INPUT_PULLUP to the Arduino core.
If you try to use
pinMode(pin, INPUT_PULLUP);
the compiler will throw an error to say that INPUT_PULLUP is not defined.
In order to fix this you need to change a few lines in two files. A copy of each of the amended files is attached to this post
*** No guarantee or warranty is given or implied. Please take a back up of your original files before making any changes ***
In the 1284/644 core file Arduino.h:-
From line 21, replace:-
#define INPUT 0x0
#define OUTPUT 0x1
with
#define INPUT 0x0
#define OUTPUT 0x1
#define INPUT_PULLUP 0x2
In core file wiring_digital.c, in the pinMode function...
at line 35, replace:-
volatile uint8_t *reg;
with
volatile uint8_t *reg;
volatile uint8_t *out;
at line 41, replace:-
reg = portModeRegister(port);
with
reg = portModeRegister(port);
out = portOutputRegister(port);
at line 44, replace:-
if (mode == INPUT) {
uint8_t oldSREG = SREG;
cli();
*reg &= ~bit;
SREG = oldSREG;
} else {
uint8_t oldSREG = SREG;
cli();
*reg |= bit;
SREG = oldSREG;
}
with
if (mode == INPUT) {
uint8_t oldSREG = SREG;
cli();
*reg &= ~bit;
*out &= ~bit;
SREG = oldSREG;
} else if (mode == INPUT_PULLUP) {
uint8_t oldSREG = SREG;
cli();
*reg &= ~bit;
*out |= bit;
SREG = oldSREG;
} else {
uint8_t oldSREG = SREG;
cli();
*reg |= bit;
SREG = oldSREG;
}
On completion of the changes to both files, test that INPUT_PULLUP now works:-
- Wire an LED between any pin and Gnd, with a suitable resistor.
- Set the pinMode as OUTPUT and digitalWrite HIGH to ensure the LED lights normally
- Set the pinMode as INPUT and digitalWrite HIGH to ensure the LED lights dimly (old method of activating pullup)
- Set the pinMode as INPUT and ensure the LED does not light
- Set the pinMode as INPUT_PULLUP to ensure the LED lights dimly (new method of activating pullup)
If you compile OK and see the correct results for step 2 to 4 above then you now have INPUT_PULLUP functionality inserted into your 1284/644 core successfully..
Arduino.h (5.56 KB)
wiring_digital.c (5.18 KB)