PIC12F675 GP4 doesn't work

by Ali Abo Shady   Last Updated July 11, 2019 22:25 PM

I'm using a PIC12F675 for a project, and everything works fine except one thing. GP4 does not work as digital IO. I've looked at the configs and the code a lot, but couldn't find anything.

Config:

#pragma config FOSC = INTRCCLK
#pragma config WDTE = OFF
#pragma config PWRTE = OFF
#pragma config MCLRE = OFF
#pragma config BOREN = ON
#pragma config CP = OFF
#pragma config CPD = OFF

Code:

#include <xc.h>
#include <math.h>
#include "config.h"
#define _XTAL_FREQ 4000000

void delay(unsigned int freq){
    for(int i = 0; i < (int)freq; i++){
        __delay_ms(1);
    }
}

void dClock(unsigned int freq){
    GPIO1 = 1;
    delay(freq);
    GPIO1 = 0;
    delay(freq);
}

void InitADC(){
    ANSEL = 0x11;
    ADCON0 = 0b10000001;
    CMCON = 0x7;
    VRCON = 0;
}

unsigned int GetADCValue(){
    ADCON0 = 0b10000011;
    while(GO_nDONE);
    return (ADRESH << 8) + ADRESL;
}

void main(void) {
    TRISIO0 = 1; //analog input
    TRISIO1 = 0; //output
    TRISIO2 = 0; //indication
    TRISIO3 = 1; //mode
    TRISIO4 = 0; //halt
    TRISIO5 = 1; //pulse_button

    char pressed = 0;
    GPIO1 = 0;

    InitADC();

    while(1){
        if(GPIO4 == 0){
            if(GPIO3 == 0){
                GPIO2 = 1;
                unsigned int freq = GetADCValue();
                dClock(freq);
            }
            else{
                GPIO2 = 0;
                if(GPIO5 == 1 && pressed == 0){
                    GPIO1 = 1;
                    __delay_ms(50);
                    GPIO1 = 0;
                    pressed = 1;
                }
                else if(GPIO5 == 0 && pressed == 1){
                    pressed = 0;
                }
            }

        }
    }
    return;
}


Answers 1


You have configured the PIC to output the internal clock signal on GP4 using

#pragma config FOSC = INTRCCLK

Replace INTRCCLK with INTRCIO.

Spehro Pefhany
Spehro Pefhany
July 11, 2019 22:03 PM

Related Questions


Updated April 17, 2015 20:10 PM

Updated October 03, 2017 16:25 PM

Updated June 27, 2018 15:25 PM

Updated June 26, 2019 18:25 PM

Updated June 09, 2019 07:25 AM