Are you taking meds for your depression and your pain?
As far as motivation, I assume you want to be successful to acccomplish some future goals, so each test successfully taken and each task done is helping you to reach those goals.
You might try reading out loud as you study--asking yourself questions along the way, thinking of ways to remember any info you need to memorize, etc. Those more conscious techniques might help you keep your mind off the pain.

That would be a start. You might also talk to a school counselor about your situation.