Ok, since many of us use PICs for our robots, I figure that here would be an appropriate place to ask for help, additionally, this should be an easy one as I am clearly doing something wrong...
I've made a small program on my pic18f452 that basically watches for a port to go high or low (a button) and then sends the state of this port through a serial port. This application was working fine when the pic was on my development board (that has buttons), but it's acting weird now that I'm mounting it on a protoboard (those fiberboards full of holes). I've looked at the schematics of my dev board and all the switches do is to connect the pin to VCC, no resistors (do I need one?)
Let's say it is port RD1. I've set the TRISD.RD1 bit as input. This pin connected to one leg of a momentary on switch that connects directly to VCC (5V). When the pic was on the development board, pressing the button (I've taken care of debouncing) would drive RD1 high and releasing would let it go low. Now when I press the button it goes high allright, but then it stays high. If I try to probe it to see it on my oscope (even using a x10 probe), it goes low. Sometimes even if I touch the pin with my finger it will go low. Something related to capacitance right? My program, besides sending serial messages, it also drives PORTC.0 (TRISC.0=0) high or low accordingly to PORTD.1 state so I can double check it with a led. When it goes high after pressing the button, port RC0 goes high, but it oscillates close to 4V about 800mV.
I had similar problems in the past because I 1) had not connected VSS to my PIC 2) had not grounded (pulled down) unused pins
This time, VSS is connected to ground, any port that is not being used is connected to ground. I'm using an external crystal at 4MHz (HS mode) with two 15pF on each leg of the xtal (should I be using more? I doubt, serial communication, which is timing dependant is working fine). I was using a .1uF decoupling cap close to my VDD pin, I thought it was insufficient, then I've increased it to 1uF, same problem....
I have the impression that I'm forgetting something really simple....
Do you see what?
Thanks
Padu