Step 51Software: IO initialization
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 Step | Download PDFView All Steps | Next Step » |































































































![Hard Wired LED Cube: [No Programming]](http://img.instructables.com/files/deriv/FTD/SF1T/GO8DC8KW/FTDSF1TGO8DC8KW.SQUARE.jpg)















::: undefined reference to 'delay_ms'----line 173 & 185
::: undefined reference to 'tmp2cube'----line 256
How do I clear these errors?
altered code: int main (void) { ioinit(); current_layer = 1; int i; for (i=0; i<EFFECTS_TOTAL; i++)
launch_effect(i);
Thanks for the replies.
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.