Note that if you have the first qubit as the control qubit, and the second qubit as the target, then you can write $CU$ gate as follow:
$$ CU_{12} = |0\rangle \langle 0| \otimes I + |1 \rangle \langle 1| \otimes U $$
If you work this out then this is equivalent to the matrix representation of
$$ CU_{12} = \begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0 \\ 0 & 0 & u_{11} & u_{12} \\ 0 & 0 & u_{21} & u_{22} \end{pmatrix} \hspace{1 cm} \textrm{where} \ \ U = \begin{pmatrix} u_{11} & u_{12} \\ u_{21} & u_{22} \end{pmatrix} $$
So for instance, if $U = X$ then you have the familarity $CNOT_{12}$ gate (with the first qubit being controlled and the second being the target)
$$ CNOT_{12} = \begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{pmatrix} $$
As for the case where the first qubit is the target and the second qubit as the controlled, then you can write it as
$$ CU_{21} = I \otimes |0\rangle \langle 0| + U\otimes |1\rangle \langle1|$$
I will let you work out the matrix representation here.
A final note that might help while you working out all the details yourself:
$$ |0\rangle \langle 0 | = \begin{pmatrix}1 \\ 0 \end{pmatrix} \begin{pmatrix} 1 & 0 \end{pmatrix} = \begin{pmatrix}1 & 0 \\ 0 & 0 \end{pmatrix} \hspace{1 cm} |1\rangle \langle 1 | = \begin{pmatrix}0 \\ 1\end{pmatrix} \begin{pmatrix} 0 & 1 \end{pmatrix} = \begin{pmatrix}0 & 0 \\ 0 & 1 \end{pmatrix} $$