I wrote this some time ago:

http://www.picbasic.co.uk/forum/cont...r-next-project!!

This project have hard-coded Sony's SIRC code, but if you analize the logic I'm pretty sure you can accomplish what you want.
Hope this helps.

Ivan