This may help you. Always interesting to see what others have done. Not in picbasic, (but it is compatible with PICs) but might give you some ideas. http://cq.cx/ladder.pl

I used to be able to find a PLC made out of a PIC that was a commercial product, with screw terminals and a din-rail case, but I can't seem to find it anymore. If I remember right, this company also produced a ladder logic compiler. The PLC was about $200.