PIC12F675 clock


 /*
 * File:   main.c
 * Author: root
 *
 * Created on March 10, 2025, 7:22 AM
 */
#pragma config FOSC = INTRCIO   // Oscillator Selection bits (INTOSC oscillator: I/O function on GP4/OSC2/CLKOUT pin, I/O function on GP5/OSC1/CLKIN)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF       // Power-Up Timer Enable bit 
#pragma config MCLRE = ON       // GP3/MCLR pin function select (GP3/MCLR pin function is digital I/O, MCLR internally tied to VDD)
#pragma config BOREN = OFF      // Brown-out Detect Enable bit (BOD disabled)
#pragma config CP = OFF         // Code Protection bit (Program Memory code protection is disabled)
#pragma config CPD = OFF        // Data Code Protection bit (Data memory code protection is disabled)

#include <xc.h>
#define _XTAL_FREQ 4000000

unsigned char nHLT =  1;
unsigned char count = 0;

void clkpulse(void) {
    GP0 = 1;        // clock
    __delay_ms(50);
    if (GP2 == 1) {
    	nHLT = 0;
    	GP0 = 0;
    } else {
      GP0 = 0;
      __delay_ms(50);
    }
   
}

/*
    nGPPU = 0;
    INTEDG = 1;
    GIE = 1;
    PEIE = 1;
    INTE = 1;
    GPIE = 0;

void __interrupt() ISR(void) {
   if (INTCONbits.INTF == 1) {
       INTCONbits.INTF = 0;
   }
}
*/

void main(void) {
    ANSEL  = 0x00;  
    TRISIO = 0b00111100;  // input GP5,GP4,GP3,GP2 except GGP1 GP0
    CMCON  = 0b00000111;  //comparators CM2:CM0 off
    VRCON  = 0x00;         // Shut off the Voltage Reference
    GPIO   = 0x00;          // Make all pins 0
    
    char once = 1;
        
    while(nHLT) {
        if (GP5 == 0) { // auto/manual switch
            clkpulse();
        } else {  // manual
            if ((GP4 == 1) && (once)) {
              clkpulse();
              once = 0;
            } else if (GP4 == 0) {
                once = 1;
            }
        }
     }
   
    while(1) {
    }
     
    return;
}