yep. As Ralph suggest, the latches will do the job for you. OR if you don't have many i/o, you can do it by software by checking the zero crossing on a specific i/o and once you get it, refresh your i/o states.