  Let $\mathbb{F}_{p^m}$ be a finite field with $p^m$ elements, where $p$ is an
odd prime and $m$ is a positive integer. Recently, \cite{Hengar} and
\cite{Wang2020} determined the weight distributions of subfield codes with the
form
  $$\mathcal{C}_f=\left\{\left(\left( {\rm Tr}_1^m(a f(x)+bx)+c\right)_{x \in
\mathbb{F}_{p^m}}, {\rm Tr}_1^m(a)\right)\, : \, a,b \in \mathbb{F}_{p^m}, c
\in \mathbb{F}_p\right\}$$ for $f(x)=x^2$ and $f(x)=x^{p^k+1}$, respectively,
where $k$ is a nonnegative integer. In this paper, we further investigate the
subfield code $\mathcal{C}_f$ for $f(x)$ being a known perfect nonlinear
function over $\mathbb{F}_{p^m}$ and generalize some results in
\cite{Hengar,Wang2020}.
  The weight distributions of the constructed codes are determined by applying
the theory of quadratic forms and the properties of perfect nonlinear functions
over finite fields. In addition, the parameters of the duals of these codes are
also determined. Several examples show that some of our codes and their duals
have the best known parameters with respect to the code tables in
\cite{MGrassl}. The duals of some proposed codes are optimal with respect to
the Sphere Packing bound if $p\geq 5$.
