Troubleshooting ATmega

Since your loopback test worked, my first guess would be that the 16 MHz crystal or load capacitors are not working correctly. Double check those connections and the capacitor values.