Here is an app note http://ww1.microchip.com/downloads/e...tes/01018A.pdf

which contains a wiring diagram.

Name:  Capture.PNG
Views: 1233
Size:  27.6 KB

I hope this gives you some clues as to why the code is not working.