Topological terms in abelian lattice field theories