Hier stehen Algorithmnen, wie man sowas macht,
http://www.atmel.com/dyn/resources/p...ts/doc0938.pdf
Gruß