With a bit of luck it should not be rocket science and just moving a few wires around and recompiling a slightly modified sketch…
PORTB on your UNO are digital pins 8 to 13 (the doc states using only 8-10 ?) → So I assume that in your current set-up you have wires going from pin 8 to 10 to form the Address bus. PORTB on your mega are digital pins 19 to 26 → so if you don’t change the code you need to move the wires from pins 8-10 (or 13 if more) to 19-21 (or 26 if more)
PORTD on your UNO are digital pins 0 to 7 and the doc seems to hint they are all used → So I assume that in your current set-up you have wires going from pin 0 to 7 to form the Data bus. PORTD on your mega are digital pins 43 to 50 → so if you don’t change the code you need to move the wires from pins 0-7 to 43-50
The hex file has been pre-compiled for a UNO. You can’t use that for a mega. So you need to recompile with a MEGA as target board but there are a few things to change in the code first:
At the start of the code in the setup() you have
for(i=0; i<14; i++)
for loops sets pins 0 to 13 of the UNO as OUTPUT. that’s because PORTB and PORTD were used.
You would need to change that to place 19-21 and 43-50 as OUTPUT and that can be done by setting the Data Direction Register correctly
DDRD = B11111111; // D43 to D50 as OUTPUT
DDRB = B11111111; // D19 to D26 as OUTPUT
then you have
DDRC = 0xff;
PORTC = 0x00;
If you keep this as is, then you talk to PORTC directly. On a UNO this would be A0-A5 and on a MEGA that would be A8 to A15. So you need to move your wires from A0-A5 to A8-A13
Then you have Timer2 setup.
TCCR2A = 0x00;
TCCR2B = 0x00;
TCCR2A |= (0x01 << WGM21); // CTC mode. clear counter on TCNT2 == OCR2A
OCR2A = 10; // Interrupt every 25600th cpu cycle (256*100)
TCNT2 = 0x00; // start counting at 0
TCCR2B |= (0x01 << CS22) | (0x01 << CS21); // Start the clock with a 256 prescaler
TIMSK2 |= (0x01 << OCIE2A);
A timer is just a clock counter built in the Arduino controller can be programmed by some special registers.
The Arduino UNO board is based on the ATmega328 and has 3 timers, called Timer0, Timer1 and Timer2. Timer0 and Timer2 are 8bit timer, where Timer1 is a 16bit timer.
The Arduino Mega is based on the ATmega2560. It is not too far from the ATmega328 but has 6 timers. First 3 timers (Timer 0, Timer1 and Timer2) are identical to the ATmega328 (and Timer3, Timer4 and Timer5 are all 16bit timers, similar to Timer1.)
All timers depends on the system clock of your Arduino system - here on a UNO or MEGA you would be likely at 16MHz in both cases so interruption would behave the same way
Here they use Timer2 with a prescaler of 256 and an Output Compare value of 10. This means that the counter is incremented by 1 for every 256th cpu cycle. When Timer2 reaches 10, it is reset to 0 and the interrupt routine is called - this is what drives the refresh of your cube.
→ long story short as timer2 is used to drive an ISR and as the registers and configurations are the same for this setup, it should work without changes.
doing so you will end up with the following code (after removing a couple warning)
you need to move the wires from pins 8-10 (or 13 if more) to 19-21 (or 26 if more)
you need to move the wires from pins 0-7 to 43-50
you need to move your wires from A0-A5 to A8-A13
you need to recompile the attached code with a MEGA as target board
and it possibly could work … give it a try…
LedCube.ino (13.6 KB)