The first thing that leaps at me in your code is the line:
P_term=(Kp*err_val)/T^2;
You've initialised T with a very large value (227) that when squared yields 51529 - which is outside the range of values representable in the (I presume) 16-bit signed integers used in your program. You'll need to make T smaller...
The integer division performed on the same line is also computationally expensive - and unnecessary - since you're simply scaling (Kp*err_val) by a design-time constant. You can replace it with a single multiplication, or absorb the constant into the value of Kp.
Kp and Ki represent the proportional and integral (respectively) gain values of the PI voltage control system. Their values will need to be adjusted depending upon your sampling rate and system dynamics/parameters such as switching frequency, output filter capacitor size etc. Once you've got your control loop functional, you'll probably want to optimise the values for best load regulation and step response. While this certainly isn't impossible in the fixed point architecture you've adopted [indeed, a fixed point implementation is a good final goal] - it can be markedly more difficult to prototype in fixed point arithmetic due to precision/overflow considerations. If your CPU has sufficient speed/idle time, it might be worthwhile getting it all to run initially with a floating point implementation, and converting the design back to fixed point at the end.
Good luck!