# Can't get output from GP5 and GP3 in PIC12F629

I can't get output from GP5 and GP3 from a PIC12F629 I have. My code is the following:

#include <xc.h>
#define _XTAL_FREQ 20000000
#pragma config WDTE=OFF , BOREN=OFF , PWRTE=ON , MCLRE=OFF , FOSC=INTRCIO

void main(){
TRISIO = 0;
GPIO = 0;
while(1){
GPIO = 1b11111;
}

}


When I connected the resistor and LED to other pins, every LED lights up, except those connected to pin 2 and 4. I verified both the LED and resistor and they are working ok. The MCU is brand new. I even tested this setup with another, used IC before.

What did I do wrong?

Can some one explain what 1b or 0b in GPIO value mean? I guess b could be binary.

Note: My IDE is MPLAB X, XC8.

• Normally it would be 0b for binary but not all compilers support that (not sure about the one included with MPLAB) but try 0xFF instead and see what happens. – PeterJ Mar 10 '14 at 8:42
• thank's, it lite GP5 but GP3 is off. – Shombol-shagol Mar 10 '14 at 8:46
• GP5 and GP3 are different to pin 5 and pin 3, perhaps edit your question to clarify which one you mean. – David Mar 10 '14 at 8:46
• My mistake, i corrected it. – Shombol-shagol Mar 10 '14 at 8:48

## 1 Answer

See the table on page 6 of the PIC12F629 datasheet, it lists GP3 as:

Input port w/ interrupt-on-change

Then again on page 23:

Figure 3-3 shows the diagram for this pin. The GP3 pin is configurable to function as one of the following:

• a general purpose input

• as Master Clear Reset

GP3 can only be used as an input on this device.

As noted in the comments the 1b prefix is unusual, modern Microchip compilers in the XC range all support the standard 0b as a prefix which indicates a binary radix number.

In your original code you listed 1b11111 as the value for the port. If we read from right to left this would set GP0, GP1, GP2, GP3 and GP4 to the value 1 (but note that GP3 isn't an output, as above). You don't have enough digits to set GP5 to 1.

If you set your output port to 0b111111 you are now setting GP0 to GP5 (again reading right to left).

• I just tested this in a recent XC8, it allows you to specify numbers as 7b101010. Very unusual that this doesn't generate a warning. Don't do this though - 0b101010 is the correct notation. – David Mar 10 '14 at 9:09
• For pin2 or GP5 i used GPIO = 0b100000; and it works. – Shombol-shagol Mar 10 '14 at 9:43