When working with GPIO (general purpose input/output) pins of microcontroller you must be aware of few things. Some people think it is enough to know how to program but often you MUST know few basic things about hardware so that you can prevent hardware damage as well as to make sure that device will work correctly.
Here are basic you will need about microcontroller pins.
GPIO pins can be configured as input or output
Configured as input pins are used to read logic state on some device. This state of pin is called tri stated. Pin can read if it is logic state “1” or “0”. For exact voltages you must check what is power supply of the microcontroller. Usually it is 5V or 3.3V. If it’s 5V than logic “0” is typically 0 V to 0.8 V and logic “1” is typically 2 V to 5 V. For more details see chosen microcontroller data sheet. It is important not to allow voltage outside allowed voltage level range on any GPIO pin unless states otherwise. In this example allowed signal voltage range on input pin is 0V-5V. There are protective diodes on every GPIO pin that should protect microcontroller in case of over or under voltage, but you shouldn’t be using them :).
If you configure pin as tri state then pin goes into state of high impedance. We can say, it is now simply connected to input of some OpAmp inside the uC and no other circuit is driving it from uC. Thus pin has very high impedance. In this case, if pin is left floating (i.e. kept unconnected) then even small static charge present on surrounding objects can change logic state of pin. If you try to read corresponding bit in pin register, its state cannot be predicted. This may cause your program to go haywire, if it depends on input from that particular pin.
Thus while, taking inputs from pins / using micro-switches to take input, always enable internal pull-up resistors (if microcontroller have this option) or connect external pull-ups on input pins.
NOTE : while using on chip ADC, on many microcontrollers ADC port pins must be configured as tri stated input.
Configured as output pins can be push-pull or open collector.
Push-Pull pin means that it can source and sink relatively big electrical current to connected hardware.
Usually it is enough for turning on LED but when you want to control DC motor for example you will need additional drivers. GPIO pins can give is about 25mA (depending on microcontroller producer and type). Two pins configured as push-pull output CAN NOT be connected together directly or you will make hardware damage to microcontroller if their states (voltage levels) differ!
Open collector (OC) pin means that it only have lower transistor on output so it can sink current (conect output pin to the ground) but cannot source it (providing high voltage and current). These kinds of outputs are used for special purposes such as communication with devises that work on different voltage supplies and usually require pull-up resistor. On picture is given basic idea of open collector output. Not every microcontroller have OC pin but PIC16F series often have RA4 pin OC.
Best resourse for detailed information on specific microcontroller data is allways data sheet
This is some basic usefull information of GPIO pins that should help you in your work. There is much more to it but for begining this is enough.