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>

/////////// Configuration Bits : Read 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) {
    //// Internal oscillator configuration (datasheet page 20, 3.2 Oscillator control) //////////
    OSCCONbits.IRCF = 0b111;   // 8Mhz
    OSCCONbits.SCS = 0;        // System clock configuration is defined by configuration bits

    ///// Configuration of digital IO ///////////////////////////////////////////////////////////
    ANSELbits.ANS2 = 0;        // GPIO2 is digital
    TRISIObits.TRISIO2 = 0;    // GPIO2 is an output

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

MCU Microchip

Radio

Electronic

Library

Software

Privacy Policy

Politique de cookies (UE)

Conditions générales