Simple example program for the PIC12F675 microcontroller

The PIC12F675 is a very inexpensive 8-bit microcontroller from Microchip that’s available in an 8-pin DIP package (i.e. it’s suitable for breadboard use). I’ve had a small tube of these on the shelf for a few years, but I’ve only just got around to trying one out. In this post, I present a simple example circuit and program, which flashes an LED on one of the GPIO pins. The example circuit includes connections to the PICkit2 USB programmer that I’m using to program the device. The PICkit2 also supplies power to the circuit.

First, here’s the video of the example program running on the PIC12F675.

Example Code

This is the full C code for the flashing LED example. I built it using Microchip’s XC8 compiler (the compiler command line is shown in the opening comments).

//
// PIC12F675 example: blink an LED on pin GP5
// Written by Ted Burke - 18-2-2017
//
// To compile:
//
//    xc8 --chip=12F675 main.c
//

#include <xc.h>

#pragma config FOSC=INTRCIO,WDTE=OFF,MCLRE=OFF,BOREN=OFF

void main(void)
{
    TRISIO = 0b11011111; // Make pin GP5 a digital output
    
    while(1)
    {
        GP5 = 1;         // Set pin GP5 high
        _delay(500000);  // 0.5 second delay
        GP5 = 0;         // Set pin GP5 low
        _delay(500000);  // 0.5 second delay
    }
}

Example Circuit

pic12f675_circuit

Here’s my breadboard circuit:

20170217_162941

This entry was posted in Uncategorized and tagged , , , , , , , , , , , . Bookmark the permalink.

3 Responses to Simple example program for the PIC12F675 microcontroller

  1. larry con says:

    que chucha es TRISIO = 0b11011111??? tanta cosa para decir que sea de salida??? ni siquiera explicas

  2. Thomas says:

    Great tutorial… A silly question. If I just add the following code to your program
    while(1)
    {
    GP5 = 1;
    GP1 = 0;
    __delay_ms(500);
    GP5 = 0;
    GP1 = 1;
    __delay_ms(500);
    }
    I can blink two LEDs in alternance…
    but if I use GP0 (as below)
    while(1)
    {
    GP0 = 1;
    GP1 = 0;
    __delay_ms(500);
    GP0 = 0;
    GP1 = 1;
    __delay_ms(500);
    }
    …no leds are blinking anymore. Why would that be??

    many thanks for any comments you may have

    Thomas

    • batchloaf says:

      Hi Thomas,

      Short answer: I don’t know. Seems strange that GP1 is working in the first case but not in the second!

      Possible reason: Do you have anything else connected to GP0 other than the LED? Is the USB programmer still connected to the PIC? If so, pin 6 is used as ICSPCLK. I would assume ICSPCLK is a digital output on the PICkit2 (or whatever programmer you’re using) which would be a problem if you start using pin 6 as a digital output too (i.e. GP0) because if they disagree about the logic level you effectively have a short circuit.

      That’s just off the top of my head. Sorry for the delay getting back to you. I can’t find the time to keep up with all the comments!

      Ted

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s