Not sure if this is any help

http://www.trainelectronics.com/miniDCC/index.htm

It has some code and the site is about DCC