Microchip 12F683

This is a sample code showing a minimal configuration of a PIC12F683 to get on GPIO2 a high level (logical 1) of a duration of one cycle of 500ns (8MHz = 2MIPS on 8bits architecture). The aim is to validate a simple design by verifying :

  • The MPU is well powered,
  • Its main oscillator is working.

To do that, one file have to be added to a blank project in MPLABX using Hi-Tech PICC compilers :

#include <htc.h>

/////////// Bits de configuration : Voir datasheet page 84, 12.1 Configuration bits //////////////
__CONFIG(FCMEN_OFF \
    & IESO_OFF \
    & BOREN_OFF \
    & CPD_OFF \
    & CP_OFF \
    & MCLRE_ON \
    & PWRTE_ON \
    & WDTE_OFF \
    & FOSC_INTOSCIO);

void main(void) {
//// Configuration de l'oscillateur interne (datasheet page 20, 3.2 Oscillator control) //////////
    OSCCONbits.IRCF = 0b111;    // 8Mhz
    OSCCONbits.SCS = 0;     // Configuration de l'horloge systeme
                    // définie par les bits de configuration

///// Configuration de entrees/sorties numeriques ////////////////////////////////////////////////
    ANSELbits.ANS2 = 0;     // GPIO2 est numerique
    TRISIObits.TRISIO2 = 0;     // GPIO2 est une sortie

    while(1) {
        GPIObits.GP2 = 1;
        GPIObits.GP2 = 0;
    }
}