A man accused of murder told the court he was acting in self-defence as he thought he was going to be hit with a hammer.