For the most part they're interchangeable.
"Don't do IT again."
"Don't do THAT again."
"I know there's a problem, but I haven't got time to worry about THAT now."
"I know there's a problem, but I haven't got time to worry about IT now."
"It was a secret--that's why they never talked about IT."
"It was a secret--that's why they never talked about THAT."
I don't see a difference in meaning between the two in these sentences.
"You can do it!" is used as an idiom of encouragement. As such, it wouldn't work if one said "You can do that!". Used otherwise, they're interchangeable.
There was a popular advertising slogan a couple of decades ago, "Just do it", that wouldn't work as "Just do that".
According to the American Heritage Dictionary "that" refers to something mentioned or understood, "it" refers to something previously mentioned or understood.