3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

LED Cube 8x8x8

Step 51Software: IO initialization

Software: IO initialization
The first thing the ATmega does after boot, is to call the ioinit() function.

This function sets up IO ports, timers, interrupts and serial communications.
All IO ports on the ATmega are bi-directional. They can be used either as an input or an output. We configure everything as outputs, except the IO pins where the two buttons are connected. The RX pin for the serial line automatically becomes an input when USART RX is enabled.

1) DDRx sets the data direction of the IO pins. (Data Direction Register). 1 means output, 0 means input.

2) After directionality has been configured, we set all outputs to 0 to avid any blinking LEDs etc before the interrupt has started.

3) For pins configured as inputs, the PORTx bit changes its function. Setting a 1 in the PORTx register bit enables an internal pull up resistor. The port is pulled up to VCC. The buttons are connected between the port and GND. When a button is pressed the corresponding PINx bit reads a logic 0.

4) Timer 2 is configured and a timer interrupt enabled. This is covered in a separate step.

5) Serial communications is configured and enabled. This is also covered in a separate step.
« Previous StepDownload PDFView All StepsNext Step »
4 comments
Feb 25, 2012. 8:14 PMb_ovalle28 says:
I have downloaded the source code and am trying to "make all" in WinAVR and it is saying::: undefined reference to 'launch_effect'-----line56
::: undefined reference to 'delay_ms'----line 173 & 185
::: undefined reference to 'tmp2cube'----line 256
How do I clear these errors?
Feb 26, 2012. 4:12 AMtriumphtotty says:
Do you have all of the .c and .h files in the same folder as Makefile? Those files are the only ones referenced by main.c, so I suspect you only have main.c/.h being compiled. There should be Makefile, cube.h, draw.c/.h, effect.c/.h font.c/.h gameoflife.c/.h, launch_effect.c/.h and main.c and .h in the folder.
Mar 16, 2011. 3:53 PMflunk2003 says:
Hey, I have built a cube following your fantastic instructable. I loaded the test file and everyting works fine (after an afternoon of adjusting). But when I load the main.hex and main.eeprom file you have provided I run into a problem. The cube won't start any animations, pressing the RS232-button doesn't light up the linked led and the upper reset button doesn't work either. But when I change the code you provided in main to not start the bootwait program (so immediately start with the programmed effects) the cube doesn't do anything for 40 seconds, and start suddenly to play the effects, starting with effect box shrink grow (case 6). After some effects (about 2-3 minutes) the cube suddenly stops and I have to reset it to replay the effects. Does anyone have an idea what could be wrong. I guess it's a hardware problem but I've checked and don't find any problems. Where should I look?

altered code: int main (void) { ioinit(); current_layer = 1; int i; for (i=0; i<EFFECTS_TOTAL; i++)
   launch_effect(i);
Mar 22, 2011. 4:57 AMflunk2003 says:
I've checked al the connections and located the problem. I misconnected the buttons, so the system was continuously being restarted. There was a direct connection instead of a button. After switching the buttons (2 out of 3 were wrong) the cube worked!

Thanks for the replies.
Mar 21, 2011. 11:05 PMtroller1 says:
1. Try checking your connections and contacts
2. Probably you should add two pull-up resistors to your buttons. This instructable has a program enabling internal ATMega pull-ups, but they're very weak (about 100K), you should use 10K. Also check you have such a resistor on your ATMega RESET pin, and be sure you connected all VCC and GND pins.
3. Try replacing your ATMega.
4. Pressing the RS232-button will not light up the LED, it will lit only when you send something to UART. And check your ATMega pins 14 and 15, there's a mistake in this instructable and these pins have to be flipped.
Mar 20, 2011. 8:56 AMhybrid_snyper says:
Just guessing, could it be a watchdog timer?

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
651
Followers
7
Author:chr
I like microcontrollers and LEDs :D