changed order of setting port levels and setting direction registers